London Magento Meetup - 5 March 2014

London Magento Meetup - 5 March 2014

069e0a9fdfc97995bfc60a6d733b4ec6?s=128

Steve Desmet

March 05, 2014
Tweet

Transcript

  1. <3

  2. whoami • Happy chappy @redboxdigital • Magento Certified Developer •

    @stevede5met • Linux biased • Git biased
  3. What is composer? PHP dependency manager

  4. What is composer? NOT a package manager!

  5. What is composer? Define and download dependencies • per project

    vendor
  6. What's composer? • Dependencies are composer packages which can depend

    on other composer packages
  7. What is composer? Dependency version constraints

  8. What is composer? • require 'vendor/autoload.php'

  9. What is composer? Cross-platform

  10. Why should you care? No need to add (Magento) extension

    code (connect, private, commercial) to project code (magento base dir) in VCS
  11. Why should you care? Easy project setup

  12. Why should you care? Better dependency management / maintenance across

    projects
  13. What's wrong with Magento Connect? • For merchants it's a

    nice feature • Extensions need to either be in tarball format or on Connect • What about private/commercial extensions?
  14. What's wrong with Magento Connect? $ ./mage install community Ext_Xyz

    $ ./mage install-file ext-xyz.tgz
  15. Modman • Importing extensions from Git/Svn • Not “industry” standard

    • Magento-composer supports modman!
  16. Where can we get (Magento) extensions with composer ?

  17. Where can we get Magento extensions with composer?

  18. What do we need to get started? composer.json composer.json composer.phar

    composer.phar Magento install Magento install
  19. composer.json { “require”: { “magneto/debug”:”*” }, “require-dev”: { “ivanchepurnyi/ecomdev_phpunit”:”*” },

    “repositories”: [ { “type”:”composer”, “url”:”packages.firegento.com” } ], “extra”: { “magento-root-dir”:”./” } }
  20. DEMO

  21. Project start $ cd /var/www/magento $ vim composer.json $ composer

    validate $ composer install $ n98-magerun.phar dev:module:rewrite:conflicts $ echo 'vendor/' >> .gitignore $ find . -type l | cut -c 3- >> .gitignore $ git add composer.json composer.lock .gitignore $ git commit -v
  22. Version constraints Composer evaluates versions based on tags and branches

    in Git, Hg or Svn
  23. Versioning constraints “require”: { “vendor/package”:”VERSION CONSTRAINT” } • EXACT “1.0.0”

    “dev-master” • RANGE “>=1.0” • WILD CARD “1.0.*” (equals >=1.0, <1.1) “*” • NEXT SIGNIFICANT RELEASE ~1.7 (equals >=1.7, <2.0)
  24. Version constraints - Tags 1.1.1 – v1.1.1 1.1.1-alpha1 1.1.1-beta1 1.1.1-RC1

    1.1.1-patch1 (v)X.Y.X-[alpha|beta|RC|patch][0-9]* Tags are stable and generate dist packages
  25. Version constraints - Branches 1.0 => 1.0.x-dev master => dev-master

    Branches always have DEV stability and generate source packages VCS composer
  26. Version constraints - Stability “minimum-stability” dev beta alpha RC stable

    “vendor/package”:”@dev” Global Per package
  27. Version constraints “vendor/package”:”*”

  28. DEMO

  29. Workflow: add new dependency $ cd /var/www/magento $ vim composer.json

    $ composer validate $ composer.phar update $ n98-magerun.phar dev:module:rewrite:conflicts $ echo 'vendor/' >> .gitignore $ find . -type l | cut -c 3- >> .gitignore $ git add composer.json composer.lock $ git commit -v
  30. Workflow: delete a dependency There is no `composer remove` command

    Remove dependency from composer.json “require” key and run `composer update` $ rm -rf `find -L . -type l`
  31. Make your Magento extension composerable! Is your module published on

    Magento Connect? “YES”
  32. Make your Magento extension composerable! { “name”:”vendor/package”, “description”:”My awesome extension”,

    “license”:[”MIT”], “type”:”magento-module”, “require”: { “magento-hackathon/composer-installer”:”*” } } Your extension already has modman or package.xml file?
  33. Create your own and publish { “name”:”vendor/package”, “description”:”My awesome extension”,

    “license”:[”MIT”], “type”:”magento-module”, “require”: { “magento-hackathon/composer-installer”:”*” }, “extra”: { “map”: [ [“source/path”,”destination path”], [“source/path”,”destination path”] ] } } No modman, package.xml?
  34. Mappings • Create mappings based on the module configuration •

    Outputs a modman file php -f modman_files.php -- --module_name=Mage_Catalog --prefix="mycustom_dir"
  35. Create your own and publish

  36. Create your own and publish “type”: “composer” “url”: “http://packages.firegento.com”

  37. Create your own and publish “type”: “vcs” “url”: “https://github.com/” “url”:

    “git@github.com:..”
  38. Create your own and publish SATIS “type”:“composer” “url”:“p.mycompany.com”

  39. Updating package $ cd /tmp $ git clone <package> $

    cd package $ rm -rf * $ unzip / tar <new package> $ git add --update $ git add <any new files or folders> $ git checkout composer.json // Make sure you add mappings for any new files $ vim composer.json $ git commit -v
  40. Publish changes $ composer.phar install --prefer-source $ composer.phar status --verbose

    If “minimum-stability”:”stable”, composer download, not clone packages
  41. Deployment $ git clone git@bitbucket.com:... $ composer.phar install --prefer-dist $

    composer.phar create-project vendor/package \ --repository-url=”http://p.yourcomp.com” \ --stability=”stable” \ --prefer-dist \ --no-dev \ --no-interaction \ 1.0.0 Production $ composer.phar create-project vendor/package \ --repository-url=”http://p.yourcomp.com” \ --stability=”dev” dev-master Dev
  42. Install Magento Core as dependency { "require": { "connect20/mage_all_latest":"*" },

    "repositories": [ { "type":"composer", "url":"http://packages.firegento.com" } ], "extra": { "magento-deploystrategy":"copy", "magento-root-dir":"./", "magento-force":"1" } }
  43. Autoloader Accessing vendor folder from within Magento project https://gist.github.com/anonymous/8488849 {

    "minimum-stability":"dev", "require": { "pear-pear/Net_IPv4":"v1.3.4", "firegento/psr0autoloader":"*" }, "repositories": [ { "type": "composer", "url": "http://packages.firegento.com" }, { "type":"pear", "url":"pear.php.net" } ], “extra”: { “magento-root-dir”:”./” }
  44. Lessons learned • Allow symlinks Magento config • Adding untracked

    composer extension files to repository • Difference between composer install/update.. Do NOT run composer update on a production server • After composer update, also update .gitignore file • Make sure composer.lock is added after update • When un-installing, sometimes dangling symlinks left behind • Windows users.. symlink support (use Cygwin).. Older version use copy-deploy • Developers not familiar with command line • Updating private packages • Creating mappings for linking into base install
  45. Documentation • getcomposer.json • github.com/magento-hackathon/magento- composer-installer • http://magebase.com/magento- tutorials/composer-with-magento/