Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Tips and Best Practices for Developing on Magento 2

715 views

Published on

Based on years of Magento development with a gold partner and consulting with the Magento Expert Consulting Group (ECG) Gordon shares his thoughts on some of the most common areas of improvement he sees in development teams.

Published in: Technology
  • Be the first to comment

Tips and Best Practices for Developing on Magento 2

  1. 1. © 2016 Magento, Inc. Page | 1 Tips and Best Practices for Developing on Magento 2 Magento Meetup Dublin - October 26, 2016
  2. 2. © 2016 Magento, Inc. Page | 2 Solutions Architect Magento Expert Consulting Group Twitter: @gordonknoppe Gordon Knoppe
  3. 3. © 2016 Magento, Inc. Page | 3 Based on what I am seeing today
  4. 4. © 2016 Magento, Inc. Page | 4 You may already be doing some of this
  5. 5. © 2016 Magento, Inc. Page | 5 Not many teams are doing all…
  6. 6. © 2016 Magento, Inc. Page | 6 Each slide could be it’s own talk...
  7. 7. © 2016 Magento, Inc. Page | 7 But not as important as that three hours you spent looking at dark themes for your IDE…
  8. 8. © 2016 Magento, Inc. Page | 8 Quick show of hands
  9. 9. © 2016 Magento, Inc. Page | 9 Magento source, project structure composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition . http://devdocs.magento.com/guides/v2.0/install-gde/prereq/integrator_install.html
  10. 10. © 2016 Magento, Inc. Page | 10 Magento source, gitignore /app/code/Magento /app/design/*/Magento /app/etc/*.* /app/etc/enterprise /app/i18n/magento /app/*.* /bin /dev /lib /node_modules /phpserver /pub /setup /update /var /vendor /*.* !/app/etc/config.php !/.gitignore !/composer.json !/composer.lock https://github.com/gordonknoppe/m2-sample-project
  11. 11. © 2016 Magento, Inc. Page | 11 Magento source, composer for dependencies https://getcomposer.org M1 composer: http://fbrnc.net/blog/2014/12/magento-update
  12. 12. © 2016 Magento, Inc. Page | 12 Magento source, composer for dependencies Paid extension or no composer.json? Make your own repo and add composer.json
  13. 13. © 2016 Magento, Inc. Page | 13 Magento source, composer for dependencies require-dev for developer dependencies (debug toolkit maybe?) http://store.pulsestorm.net/products/commerce-bug-3
  14. 14. © 2016 Magento, Inc. Page | 14 Magento source, patches are still a reality • Create a patches/ directory to drop patch files into • Write a simple bash script which loops and applies on build • See patches and re-order patches is trivial • 01, 02, 03, etc.
  15. 15. © 2016 Magento, Inc. Page | 15 Magento source, simple reset/build script • Cleanup (destructive!) – git clean -ffxd src/ • Compose – composer install • Patch – find patches -type f -name '*.sh' | while read file do # copy patch into src and apply... done • Seems scriptable right? (reset.sh, stash-reset.sh?)
  16. 16. © 2016 Magento, Inc. Page | 16 Features and bug fixes • Developing in branches • Different styles during lifecycle of project – Sprint on master during project build phase – Switch to branches for bug fixes and maintenance – Bugfix branch based on latest stable (master) • Means you can stage, test, and deploy combination of features/fixes • Don’t let a single bug block an entire maintenance release • git-release to pick branches and build RCs https://github.com/gdoug-guidance/git-release
  17. 17. © 2016 Magento, Inc. Page | 17 PHPStorm - IDE • Inspections and validation • Code navigation • Automatic formatting • Autocomplete and parameter hinting • XSD based XML validation • Quick survey?
  18. 18. © 2016 Magento, Inc. Page | 18 PHPStorm - IDE https://github.com/magento-ecg/coding-standard
  19. 19. © 2016 Magento, Inc. Page | 19 PHPStorm - New > File templates https://gist.github.com/Vinai/eb4713bda65fb8b467b1
  20. 20. © 2016 Magento, Inc. Page | 20 PHPStorm - Local File History
  21. 21. © 2016 Magento, Inc. Page | 21 PHPStorm - Magento 2 plugin • Configuration smart completion and references – di.xml – layouts – events.xml – webapi.xml • Inspections – @api usage – ObjectManager usage • Code helpers – "Navigate to configuration" reference in scope of class/interface – "Go to plugin" reference in scope of class/interface and method – "Navigate to Web API configuration" reference in scope of class/interface and method https://plugins.jetbrains.com/plugin/8024
  22. 22. © 2016 Magento, Inc. Page | 22 PHPStorm - “Mark directory as..” – /bin – /dev – /pub – /setup – /var/cache – /var/log – /var/page_cache – var/view_processed – vendor/magento/magento2- base https://plugins.jetbrains.com/plugin/8024 Recommended directories to exclude
  23. 23. © 2016 Magento, Inc. Page | 23 PHPStorm - Test Driven Development
  24. 24. © 2016 Magento, Inc. Page | 24 PHPStorm - Test Driven Development http://vinaikopp.com/2016/02/05/01_the_skeleton_module_kata/
  25. 25. © 2016 Magento, Inc. Page | 25 PHPStorm - Test Driven Development • Testing during active development – Configure a custom test suite for just your code base • Speed up integration test configuration (but understand why) – <const name="TESTS_CLEANUP" value="disabled"/> – Database is not reinstalled on each test run
  26. 26. © 2016 Magento, Inc. Page | 26 Development - Data issues • Sample data • Database snapshots, script a refresh – Filesystem snapshots (VirtualBox, etc.) – Fake a MySQL snapshot by importing switching databases in config • Continual testing of setup:install, not just setup:upgrade
  27. 27. © 2016 Magento, Inc. Page | 27 Development - Error logs and messages • Tail error logs during dev in the PHPStorm terminal – tail -f var/log/*.log • A clean log is easier to tail when debugging your future self will thank you – Fix trivial NOTICE and WARNING messages • Production logging – Application clusters need a centralized logging solution • Logstash • Loggly • And many more...
  28. 28. © 2016 Magento, Inc. Page | 28 Deployment • Yes, you need an actual process • One-click or no-click deploys should be the first step of your project • Dev, stage, and prod should all use it identically (parameterize) • Zero downtime deployments (assuming no schema updates)
  29. 29. © 2016 Magento, Inc. Page | 29 Deployment • With Magento 2 that means a build process – Ship artifacts, don’t build on application servers – Can ship using tar/zip files but also another git repo • Visibility into exact file changes between deploys (including upgrades and dependencies) • Atomic deployments – A/B vs. Timestamped deployments and the thundering herd • Two directories with a symlink switch (careful with document root setting) • Two git clones (if shipping built code via repo) • Preserve your opcode cache https://youtu.be/MT4rRWKygq0?t=46m18s - Rasmus Lerdorf on PHP 7 (Skip to 46 minute for deployment topic)
  30. 30. © 2016 Magento, Inc. Page | 30 Performance and optimization • Performance optimization shouldn’t be left for week before launch • Tools like New Relic and Blackfire give real world insights • During development – Block cache and page cache off to test your improvements • Remove unused or dead code • Disable core functionality which you don’t use – Observers or even whole extensions (sometimes)
  31. 31. © 2016 Magento, Inc. Page | 31 Performance and optimization • Develop and test using sample data (all product types, etc.) • Fixtures from Magento performance tests provide more product data • Add on with your own sample data package http://devdocs.magento.com/guides/v2.1/config-guide/cli/config-cli-subcommands-perf-data.html
  32. 32. © 2016 Magento, Inc. Page | 32 Performance and optimization siege -c 1 -r 10 http://www.mysite.docker/ parse = false # in ~/.siege/siege.conf (for isolating app performance)
  33. 33. © 2016 Magento, Inc. Page | 33 Local Development with Docker • https://github.com/gordonknoppe/docker-magento2-example • Composed docker images not monolith – Easy swap for testing PHP/MySQL versions • 5.6 to 7.0 • MySQL / Percona / MariaDB • Docker images – https://hub.docker.com/u/gknoppe/
  34. 34. © 2016 Magento, Inc. Page | 34 OS X Development with Docker - Brew • Install brew (http://brew.sh) • Install dependencies – brew tap homebrew/dupes – brew tap homebrew/versions – brew tap homebrew/homebrew-php – brew install php70 php70-intl php70-mcrypt – brew install docker docker-compose
  35. 35. © 2016 Magento, Inc. Page | 35 OS X Development with Docker - Dinghy • Virtualbox (with extensions) • Install Dinghy – brew tap codekitchen/dinghy – brew install dinghy • Initialise dinghy for boot2docker (bump up performance) – bumped memory and cpus • dinghy create --memory=4096 --cpus=2 --disk=40000 --provider=virtualbox
  36. 36. © 2016 Magento, Inc. Page | 36 Engage with the Magento community • Twitter • Sherrie Rohde community digest – https://community.magento.com/t5/News-Announcements/bd-p/newsannouncements • Meet Magento events and hackathons • Official Magento events (Live UK, Paris, Imagine Vegas)
  37. 37. © 2016 Magento, Inc. Page | 37 Thank you

×