15
2014 1 FOR COMPOSER + MAGENTO Alec Bedzir Head of development Vaimo Ukraine [email protected] Kiev, Jul 16, 2014 2

DevHub 3 - Composer plus Magento

Embed Size (px)

Citation preview

Page 1: DevHub 3 - Composer plus Magento

2014

1

FOR

COMPOSER + MAGENTO

Alec Bedzir Head of development Vaimo Ukraine [email protected]

Kiev, Jul 16, 2014

2

Page 2: DevHub 3 - Composer plus Magento

HOW DO WE USUALLY START THE PROJECT

• Getting core • Installing few already existing modules • Developing few customizations

3

4

Page 3: DevHub 3 - Composer plus Magento

HOW DO WE MAINTAIN THE PROJECT

• Lots of useful/useless modules installed and their list is smth difficult to get right away

• Development has introduced multiple dependencies

• Development has over-customised a bunch of general purpose modules

• Thanks god core is untouched

5

6

Page 4: DevHub 3 - Composer plus Magento

THOUGH IN SOME TIME…

7

• It is faster and easier to implement a feature issuing dependencies on other modules

WHY PROJECT LOSE FIT

• Or vice versa - some module in the project becomes kind of “customization” module storing everything

• Original purpose and integrity of each separate module is not tracked by anyone

• The same module in the other project is being developed in parallel instead of getting benefit from already created code

8

Page 5: DevHub 3 - Composer plus Magento

SOLUTION: LETS WATCH THE MODULES

9

CONCEPTS

• Project and modules relation should not be hardcoded

• This relation should be many to many and remain flexible

• Module “purity” and maintenance (at least of main line) should be delegated to “module maintainer”

• Module development by different teams should be done together even though being conducted in different projects

• Module versions should be clear and all ready-to-use

10

Page 6: DevHub 3 - Composer plus Magento

TOOLS• Composer

(https://getcomposer.org/) • Magento-composer-installer

(https://github.com/magento-hackathon/magento-composer-installer) • Whatever VCS

and

11

STEPS1) Install Composer

Check the link to Github for code of all the steps (in final slides)

2) Ensure Magento-composer-installer is required3) Create your project’s initial composer.json file4) Install Magento files via Composer5) Create Magento DB, user and grant permissions6) Ensure corresponding Magento folders are writable7) Finalise magento installation: install.php from CLI or web

12

Page 7: DevHub 3 - Composer plus Magento

1. COMPOSER

$ mkdir bin $ curl -s https://getcomposer.org/installer | php -- --install-dir=bin

In the project root issue:

Create empty project root folder.

13

2. MAGENTO-COMPOSER-INSTALLER

… "require": { … "magento-hackathon/magento-composer-installer": "*" }, "repositories": [ { "type": "composer", "url": "http://packages.firegento.com" } ], …

Add to composer.json if your project already uses composer

14

Page 8: DevHub 3 - Composer plus Magento

2. MAGENTO-COMPOSER-INSTALLER (2)

… "require": { "magento/core": "1.9.0.1" }, "repositories": [ { "type": "composer", "url": "http://packages.firegento.com" } ], …

Or simply require Magento core installation in composer.json if you’re starting from scratch (Note, full version on composer.json file is shown in next step)

15

3. COMPOSER.JSON{ "authors": [ { "name": "Alec Bedzir", "email": "[email protected]" } ], "require": { "magento/core": "1.9.0.1" }, "repositories": [ { "type": "composer", "url": "http://packages.firegento.com" } ], "extra":{ "magento-root-dir": "htdocs/", "magento-deploystrategy": "copy" }, "minimum-stability": "dev" }

The very basic version of the file which installs magento only with no other modules. !

File should be named composer.json and put into the root directory of the project

16

Page 9: DevHub 3 - Composer plus Magento

4. INSTALLING MAGENTO VIA COMPOSER

$ php ./bin/composer.phar -n install

In the project root issue:

17

5. DB, USER AND PERMISSIONS

$ mysql -u root -p -e " \ CREATE DATABASE magento_composer \ CHARACTER SET utf8 COLLATE utf8_general_ci; \ CREATE USER [email protected] IDENTIFIED BY '123456'; \ GRANT ALL ON magento_composer.* TO [email protected]; \ "

Run sql for preparing Mysql infrastructure for Magento:

18

Page 10: DevHub 3 - Composer plus Magento

6. MAGENTO WRITABLE FOLDERS

$ chmod -R 777 ./htdocs/app/etc $ chmod -R 777 ./htdocs/var $ chmod -R 777 ./htdocs/media

In the project root issue:

19

6. EXECUTE MAGENTO’S INSTALL.PHP

$ php -f ./htdocs/install.php -- --license_agreement_accepted yes \ --locale en_US --timezone "America/Los_Angeles" --default_currency USD \ --db_host 127.0.0.1 --db_name magento_composer --db_user magento_user \ --db_pass 123456 --db_prefix magento_ \ --url "http://magento-composer.lo" --use_rewrites yes \ --use_secure yes --secure_base_url "http://magento-composer.lo" \ --use_secure_admin yes \ --admin_lastname Owner --admin_firstname Store \ --admin_email "[email protected]" \ --admin_username admin --admin_password qwerty_123 \ --encryption_key "Encryption Key"

In the project root issue:

20

Page 11: DevHub 3 - Composer plus Magento

EXPECTED RESULT . <project root> |-- bin | `-- composer.phar |-- composer.json |-- composer.lock |-- htdocs | |-- … | |-- app | |-- cron.php | |-- index.php | |-- … | `-- var `-- vendor |-- autoload.php |-- bin |-- … |-- magento `-- magento-hackathon

1) Magento was deployed to ./htdocs under the project root

2) Composer.lock file has been generated

3) Magento installation is entirely comlete

21

TROUBLESHOOTING

If magento/core is not put into your htdocs directory:!!• Check whether this is not the issue with installing outdated version: (e.g. 1.4). Be sure version is 2.0.0 and higher.

(this can be checked in composer install operation log:…Installing dependencies (including require-dev) - Installing magento-hackathon/magento-composer-installer (1.4)…!!

• check whether you have the up-to-date version of composer!!

• check whether cache of composer is cleaned!!

• check whether you don't have any custom configuration in ~/.composer/config.json (e.g. which overlaps with your per-project configuration)!

!If Magento after installation with composer throws at you Fatal error: Call to a member function getModelInstance() on a non-object in /var/www/magento-composer/htdocs/app/Mage.php on line 463!!• simply check the user magento files belong to and ensure app/etc/ media/ and var/ are writable.

22

Page 12: DevHub 3 - Composer plus Magento

SHOW TIME!

23

SPECIFICS OF VERSIONING

• Trickiest part: project has versions but modules too

• Thus, upgrade in project doesn’t mean that modules were upgraded too. Probably they were downgraded

• Each project environment (dev, staging, live etc.) should be backed up by separate branch of the project repo

• Forking module for customizing it to very specific needs is a good option

24

Page 13: DevHub 3 - Composer plus Magento

USAGE AND BENEFITS• Modules repos are separate and module tracking is easy

• One can’t break the module’s overall purpose with his code as this will fail other projects using this module

• Module get’s a “maintainer” or few of them which are responsible for main line of its development

• Multiple teams working on the same module contribute to it simultaneously

25

USAGE AND BENEFITS (2)

• Flexible module versions locking in the project

• Modules used in the project and their versions are easy to check

26

Page 14: DevHub 3 - Composer plus Magento

DEVELOPING IDEA IN

• Push to module repo on BitBucket via hook informs Jenkins about new changes

• Jenkins having successfully done the build of the module (with all the checks, tests etc) updates “Vaimo packages” - our own Magento module composer repository

• Composer (custom of Vaimo edition) upon next “composer update” fetches the updated packages feed and uses it for updating the project

• In our internal web tool “Server portal” we track each module’s state, it’s all available versions, projects were it is installed and in which revisions

27

LINKS AND DEMO FILES

Files executed during demo (for Magento entire installation and for cleanup): https://github.com/alecbedzir/composer_plus_magento_devhub_2014_Jul !

Magento-composer-installer https://github.com/magento-hackathon/magento-composer-installer !

Firegento - Magento Module Composer Repository http://packages.firegento.com/ !

Composerhttps://getcomposer.org/

28

Page 15: DevHub 3 - Composer plus Magento

29

WATCH THE MODULES!

Alec Bedzir Head of development Vaimo Ukraine [email protected]

30