• Save
Composer in the wilderness by Josef Bielawski
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Composer in the wilderness by Josef Bielawski

on

  • 1,041 views

Оригинальная презентации Йозефа с SymfonyCon Киев (декабрь 2012)

Оригинальная презентации Йозефа с SymfonyCon Киев (декабрь 2012)

Statistics

Views

Total Views
1,041
Views on SlideShare
1,041
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Composer in the wilderness by Josef Bielawski Presentation Transcript

  • 1. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 1/62 IN THE WILDERNESS
  • 2. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 2/62 WHO AM I? Józef Bielawski, better known as stloyd Sarcastic Pole with a flair for being real troll Symfony2 and other OSS contributions Author of many features at Working at with Happy Awesome Developers! https://github.com/stloyd KnpBundles KnpLabs
  • 3. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 3/62 LITTLE NOTE WHAT IS COMPOSER? In real simply words Composer is dependency manager written in PHP. It allows you to define and manage your project dependencies in really easy way. Inspiration for it was taken from such projects like npm for NodeJS & Bundler for Ruby lang, yet internal solver code is inspired by OpenSuse Libzypp satsolver.
  • 4. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 4/62 YEAH SURE... BUT WHY USE COMPOSER?
  • 5. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 5/62 ADOPTION BY PHP ECOSYSTEM 5 100+ packages with over 14 000 defined versions on Packagist Already 6 250 000+ installs only from Packagist Supported by: Symfony2, Zend Framework, eZ Publish, and many others... with support for 17 different projects! Multi-Framework Library Installer
  • 6. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 6/62 HOW TO GET COMPOSER READY TO GO?
  • 7. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 7/62 CHECK YOUR ENVIRONMENT: $ curl -s http://getcomposer.org/installer | php -- --check
  • 8. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 8/62 IF IT'S OK, DOWNLOAD: $ curl -s http://getcomposer.org/installer | php
  • 9. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 9/62 AND RUN LOCALLY: $ php composer.phar --version Composer version cd4d569
  • 10. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 10/62 OR SETUP FOR GLOBAL USE: ADD A CRON JOB FOR AUTO-UPDATE: $ sudo mv composer.phar /usr/local/bin/composer $ composer --version Composer version cd4d569 $ crontab -e * 12 * * * /usr/local/bin/composer self-update >/dev/null 2>&1
  • 11. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 11/62 BUT WHAT WITH WINDOWS USERS?
  • 12. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 12/62 USE EXECUTABLE INSTALLER Download: Run it and enjoy this simple process! All required steps were done automatically, go to your console and test! http://getcomposer.org/Composer-Setup.exe
  • 13. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 13/62 WE USED COMPOSER LONG TIME AGO IN PROJECT Will update be boring and painful?
  • 14. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 14/62 UPDATING COMPOSER.LOCK TO NEW FORMAT
  • 15. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 15/62 ADVANTAGES WITH NEW FORMAT OF COMPOSER.LOCK FILE: Composer is slower when using old format New format is much more human-friendly And probably more boring ones =)
  • 16. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 16/62 UPDATE... NOTHING! Update of composer.lockfile is really easy, just run: Yep! None of your packages was updated! $ composer update nothing
  • 17. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 17/62 UPDATE ONLY WHAT YOU WANT! $ composer update mypackage1 mypackage5
  • 18. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 18/62 I DON'T WANNA UPDATE YET! Check what updates are waiting for you: $ composer update --dry-run
  • 19. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 19/62 ADDITIONS TO UPDATE/INSTALL
  • 20. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 20/62 DO YOU PREFER TO USE GIT CLONE? $ composer update --prefer-source
  • 21. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 21/62 OR MAYBE ZIP ARCHIVES? $ composer update --prefer-dist
  • 22. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 22/62 WHAT IS IN THIS? $ composer update --verbose # or simply -v
  • 23. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 23/62 YOU CAN COMBINE THOSE OPTIONS: $ composer update --dry-run --dev -v
  • 24. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 24/62 SO I GUESS YOU ARE BORED WITH DEFINING OPTIONS IN EVERY PROJECT...
  • 25. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 25/62 YET DEFINING SAME REPOSITORIES AGAIN & AGAIN IN YOUR PROJECTS?
  • 26. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 26/62 EDIT GLOBAL COMPOSER CONFIG! Look into: $COMPOSER_HOME/config.json, this file holds default settings.
  • 27. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 27/62 PLACES WHERE CONFIG FILE CAN BE: *nix: /home/YourUser/.composer/config.json OSX: /Users/YourUser/.composer/config.json Windows: C:UsersYourUserAppDataRoamingComposerconfig.json
  • 28. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 28/62 AVAILABLE SETTINGS vendor-dir bin-dir process-timeout github-protocols notify-on-install cache-files-ttl Change them once and use in all your projects. No more boring defining option in all your projects!
  • 29. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 29/62 ADD EXTERNAL REPOSITORIES! Similar way to global configuration, you can define repositories that will be always checked in your projects i.e. Zend Framework packages! Simply open again your configuration*: $COMPOSER_HOME/config.json, and simply add: { "repositories": [ { "type": "composer", "url": "http://packages.zendframework.com/" } ] }
  • 30. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 30/62 BUT WHAT WITH OUR PRIVATE REPOSITORY?
  • 31. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 31/62 ADD IT TO YOUR GLOBAL CONFIG! Composer have additional tool for generation and management of private repositories: Statis - package repository generator.
  • 32. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 32/62 ADD IT TO YOUR GLOBAL CONFIG! Same way as before, open configuration and add: { "repositories": [ { "type": "composer", "url": "http://packages.zendframework.com/" }, { "type": "composer", "url": "http://statis.yourdomain.com/" } ] }
  • 33. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 33/62 BUT OUR REPOSITORY IS NOW NOT SECURED!
  • 34. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 34/62 BLOCK ACCESS WITH SSH! Statis allows to secure your private repository using over SSH (which requires SSH2 PECL extension installed). { "repositories": [ { "type": "composer", "url": "ssh2.sftp://yourdomain.com", "options": { "ssh2": { "username": "secret_user", "pubkey_file": "/home/composer/.ssh/id_rsa.pub ", "privkey_file": "/home/composer/.ssh/id_rsa" } } } ] }
  • 35. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 35/62 OR USE SSL WITH CLIENT CERTIFICATE: { "repositories": [ { "type": "composer", "url": "https://yourdomain.com", "options": { "ssl": { "cert_file": "/home/composer/.ssl/composer.pem " } } } ] }
  • 36. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 36/62 YOU USE ONLY CUSTOM REPOSITORIES AND ZEND FRAMEWORK REPOSITORY?
  • 37. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 37/62 YET YOU DON'T WANT TO CALL PACKAGIST ON EVERY UPDATE?!
  • 38. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 38/62 TURN OFF PACKAGIST! Composer allows you to simply disable package lookup at official repository. { "repositories": [ { "type": "composer", "url": "http://packages.zendframework.com/" }, { "type": "composer", "url": "http://statis.yourdomain.com/" }, { "packagist": false } ] } Packagist.org
  • 39. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 39/62 WHAT TO DO IF WE HAVE OUR BUGFIX/FEATURE FOR PACKAGE BUT IT WAS NOT MERGED YET?
  • 40. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 40/62 OVERRIDING "DEFAULT" PACKAGES Dependency solver implemented in Composer allows to easily override any package defined in repositories: default (from Packagist), yet those really custom.
  • 41. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 41/62 OVERRIDING "DEFAULT" PACKAGES To do that add your fork as repository, and require patched version: { "repositories": [ { "type": "vcs", "url": "https://github.com/stloyd/Buzz" } ], "require": { "kriswallsmith/buzz": "dev-feature/awesome-thing" } }
  • 42. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 42/62 OVERRIDING "DEFAULT" PACKAGES To prevent conflicts in dependency solver, you would need to use very useful aliasing feature (it's possible because custom repositories have higher priority when resolving dependencies). { "repositories": [ { "type": "vcs", "url": "https://github.com/stloyd/Buzz" } ], "require": { "kriswallsmith/buzz": "dev-feature/awesome-thing as 0.7", "hwi/oauth-bundle": "*" } }
  • 43. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 43/62 BUT SEEMS THAT OUR FORK WILL NOT BE MERGE SOON... WE REALLY NEED THIS FEATURE!
  • 44. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 44/62 REPLACING "DEFAULT" PACKAGES In your composer.json for forked package, you need to define replacetag. { "name": "stloyd/buzz", "replace": { "kriswallsmith/buzz": "0.7" } }
  • 45. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 45/62 REPLACING "DEFAULT" PACKAGES Now add your forked package to custom repository or to the Packagist and define that package in composer.jsonfor your project! { "require": { "stloyd/buzz": "1.0", "hwi/oauth-bundle": "*" } }
  • 46. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 46/62 HOUSTON, WE HAVE A PROBLEM!
  • 47. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 47/62 COMMON PROBLEMS
  • 48. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 48/62 THAT PACKAGE CANNOT BE FOUND? Yet you can we can see it at Packagist or in any other repository. Be sure to check that in your composer.jsonyou have pointed all required repositories. $ composer show pagerfanta/pagerfanta
  • 49. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 49/62 THAT PACKAGE CANNOT BE FOUND? If you have all required repositories defined in your composer.json, you should check that for package you are looking for is defined stable version. By default Composer always tries to install/update to latest stable version in defined range. Sorry to say, but many packages don't have yet any "stable" version defined.
  • 50. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 50/62 FORCE PACKAGE STABILITY You can force Composer to always install packages with different stability, yet I would not recommend this approach. { "require": { "pagerfanta/pagerfanta": "*" }, "minimum-stability": "dev" }
  • 51. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 51/62 FORCE PACKAGE STABILITY Better approach is to define stability for specific packages: { "require": { "pagerfanta/pagerfanta": "dev-master" "symfony/symfony": "2.2.*@dev", "doctrine/orm": "2.3.*" } }
  • 52. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 52/62 MORE COMMON PROBLEMS
  • 53. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 53/62 HOW DO DISABLE SCRIPTS CALLS? $ composer install --no-scripts
  • 54. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 54/62 PACKAGE IS NOT AUTO-UPDATING? Be sure that composer.jsonis valid: $ composer validate ./composer.json is valid
  • 55. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 55/62 GITHUB FAILS? Every attempt to update, fails because of GitHub error when downloading archives? $ composer install --prefer-source
  • 56. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 56/62 DOWNLOADS ARE REALLY SLOW? $ composer install --prefer-dist
  • 57. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 57/62 ALWAYS USE LATEST COMPOSER! $ composer self-update
  • 58. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 58/62 NOTHING HELPS? In edge cases you can try to force re-installation of dependencies: $ rm -rf vendor/ $ composer update -v
  • 59. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 59/62 LEARN MORE: & getcomposer.org packagist.org github.com/composer composer-dev google group #composer #composer-dev
  • 60. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 60/62 THANK YOU
  • 61. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 61/62 QUESTIONS? FOLLOW ME AT TWITTER: OR AT GITHUB: @STLOYD STLOYD
  • 62. 6/19/13 Composer in the wilderness 2012.symfonycamp.org.ua/uploads/slides/composer/index.html?print-pdf#/ 62/62 BECOME A NINJA! YEAH PEOPLE, WE'RE HIRING! GO CHECK OUT OUR WEBSITE: OR SIMPLY CONTACT WITH US: HTTP://KNPLABS.COM/JOBS JOB@KNPLABS.COM