Pro Yearly is on sale from $80 to $50! »

Environments and Version Control in EE - The Why and How

594642c6d8a7fa66c622e740496a0a32?s=47 Erik Reagan
October 22, 2011

Environments and Version Control in EE - The Why and How

These slides are from my presentation at EECI2011. I exploring reasons for using a version control system while building and maintaining ExpressionEngine websites.

We also look at why (and some of the "how") you should use multiple environments in your workflow.

594642c6d8a7fa66c622e740496a0a32?s=128

Erik Reagan

October 22, 2011
Tweet

Transcript

  1. ERIKREAGAN • EECI ENVIRONMENTS & VERSION CONTROL The Why &

    How
  2. ERIKREAGAN • EECI WHO IS THIS GUY? 2 EE Reactor

    team member
  3. ERIKREAGAN • EECI WHO IS THIS GUY? 3 Partner &

    Lead Developer
  4. Survey Submissions ERIKREAGAN • EECI 78 4

  5. ERIKREAGAN • EECI 5 35 24 19 6-10 years 3-5

    years Over 10 years SURVEY SUBMISSIONS Web Development Experience
  6. ERIKREAGAN • EECI 6 40 19 12 4 3 3-4

    years SURVEY SUBMISSIONS ExpressionEngine Experience 0-2 years 5-7 years pMachine None
  7. ERIKREAGAN • EECI 7 66 64 38 21 20 19

    HTML/CSS/JS markup SURVEY SUBMISSIONS Weekly Responsibilities EE site planning PHP/MySQL development Add-on development Content management Team leader
  8. Caught my Monty Python reference ERIKREAGAN • EECI 73% 8

  9. ERIKREAGAN • EECI VERSION CONTROL 9

  10. ERIKREAGAN • EECI SYNONYMS • Version Control • Revision Control

    • Source Control 10
  11. ERIKREAGAN • EECI COMMON SYSTEMS • Git • Subversion •

    Mercurial 11
  12. ERIKREAGAN • EECI SURVEY STATS 12

  13. Devs not currently using a VCS regularly ERIKREAGAN • EECI

    34% 13
  14. Devs only using a desktop GUI for VCS ERIKREAGAN •

    EECI 21% 14
  15. Devs only using command line for VCS ERIKREAGAN • EECI

    21% 15
  16. Devs using both CLI and a GUI for VCS ERIKREAGAN

    • EECI 24% 16
  17. Have used CVS ERIKREAGAN • EECI 6% 17

  18. Have used Mercurial ERIKREAGAN • EECI 13% 18

  19. Have used Subversion ERIKREAGAN • EECI 54% 19

  20. Have used Git ERIKREAGAN • EECI 77% 20

  21. ERIKREAGAN • EECI 21 WE USE GIT Linux jQuery Rails

    Android
  22. ERIKREAGAN • EECI 21 WE USE GIT And so do

    the cool kids Linux jQuery Rails Android
  23. ERIKREAGAN • EECI 21 WE USE GIT And so do

    the cool kids Linux jQuery Rails Android
  24. ERIKREAGAN • EECI OLD WAY 1. Duplicate index.html 2. Test

    changes 3. (Maybe save a backup of the previous version) 4. Save over old version losing previous state 22 Single Developer
  25. ERIKREAGAN • EECI NEW WAY 1. Change and save the

    file contents (Retain history of file for future use) 23 Single Developer
  26. ERIKREAGAN • EECI OLD WAY 1. Bob changes part of

    index.html 2. Suzie changes a different part of index.html 3. Bob and Suzie carefully merge changes together 4. Overwrite old version of index.html 24 Development Team
  27. ERIKREAGAN • EECI NEW WAY 1. Change and save the

    file contents (Retain history of file for future use) 25 Development Team
  28. ERIKREAGAN • EECI 26

  29. ERIKREAGAN • EECI 26

  30. ERIKREAGAN • EECI 26

  31. ERIKREAGAN • EECI KEY CONCEPTS • Track certain files •

    Ignore certain files • Commits (History) • Branches • Remote branches 27
  32. ERIKREAGAN • EECI “WHAT DO I TRACK?” VS “WHAT DO

    I IGNORE?” 28
  33. ERIKREAGAN • EECI IGNORED FILES • Operating System files •

    Caches • .htaccess (possibly) • Custom uploads from EE • Dynamic images (captchas etc) 29
  34. ERIKREAGAN • EECI # Lame OS files Thumbs.db .DS_Store #

    EE System cache /system/expressionengine/cache/* # Local dev database file /config/config.local.php # Custom Upload Directories /public_html/uploads/* # Captchas /public_html/images/captchas # Asset minification /public_html/min 30 .gitignore
  35. ERIKREAGAN • EECI 31 TRACKED FILES • EE System directory

    • Add-ons • Template flat files • Images, CSS, Javascript & other assets
  36. ERIKREAGAN • EECI COMMITS Create your history 32

  37. ERIKREAGAN • EECI COMMIT TIPS • Commit o en (common

    Git practice) • Write detailed commit messages • Review commit log when returning to a project a er a break of any sort • Review commits of development team members 33
  38. ERIKREAGAN • EECI BAD COMMIT MESSAGE Updated config file. 34

  39. ERIKREAGAN • EECI GOOD COMMIT MESSAGE Updated config file with

    new Minimee cache path directory This allows our cache path to be dynamicly absolute based on the environment out code is in. $config[‘minimee_cache_path’] = $base_path . ‘/min’; 35
  40. ERIKREAGAN • EECI BRANCHING Keeping things organized 36

  41. ERIKREAGAN • EECI BRANCHING WORKFLOW Do what works best for

    you 37 Just make sure you do it for a reason
  42. ERIKREAGAN • EECI REMOTE BRANCHES • Destination for your repository

    / branch • “Origin” of your repository / branch • Server environment for your site • Other team member’s repository / branch 38
  43. ERIKREAGAN • EECI TOPICAL BRANCHING • master • dev •

    feature/x • upgrade/y • bugfix/z 39
  44. ERIKREAGAN • EECI 40 “It's like not wearing a seatbelt

    in your car because you haven't had an accident yet. Don't be silly, version your work.” Iain Urquhart / @iain
  45. ERIKREAGAN • EECI GIT RESOURCES • Book: Pragmatic Version Control

    Using Git • peepcode.com/products/git • whygitisbetterthanx.com • github.com • More available with the presentation download 41
  46. ERIKREAGAN • EECI ENVIRONMENTS 42

  47. ERIKREAGAN • EECI AN ENVIRONMENT IS any server running an

    instance of your site 43
  48. ERIKREAGAN • EECI COMMON ENVIRONMENTS • Production - the public-facing

    “live” site • Staging - typically used for a final test • Development - shared team development • Local - each developer’s local instance 44
  49. ERIKREAGAN • EECI SURVEY STATS 45

  50. Devs currently using a Production Environment ERIKREAGAN • EECI 100%

    46
  51. Devs currently using a Staging Environment ERIKREAGAN • EECI 59%

    47
  52. Devs currently using a Shared Dev Environment ERIKREAGAN • EECI

    32% 48
  53. Devs currently using a Local Dev Environment ERIKREAGAN • EECI

    77% 49
  54. Devs who keep using environments post-launch ERIKREAGAN • EECI 29%

    50
  55. ERIKREAGAN • EECI 51 WHY DO YOU USE ENVIRONMENTS?

  56. ERIKREAGAN • EECI 52 “Local development is incredibly fast and

    you don't have to worry about setting up crazy conditionals and memeber preferences to hide what you are working on on the live site.”
  57. ERIKREAGAN • EECI 53 “Multiple environments allow us to build

    locally without affecting others and preview new features to clients - without losing the ability to quickly apply updates to the current live site.”
  58. ERIKREAGAN • EECI 54 “Automated deployments and multiple environments are

    essential to any agile-oriented developer. They save time, reduce errors and streamline site maintenance.”
  59. ERIKREAGAN • EECI 55 GETTING SET UP What is potentially

    unique to each environment?
  60. ERIKREAGAN • EECI GETTING SET UP • Server paths •

    URL root • EE upload paths • Debug mode intentions • URI support (PATH_INFO) • Cache settings 56 What’s Unique?
  61. ERIKREAGAN • EECI ROBUST CONFIG FILE Saves time and adds

    flexibility 57
  62. ERIKREAGAN • EECI GETTING SET UP ✓ Server paths ✓

    URL root - EE upload paths ✓ Debug mode intentions ✓ URI support (PATH_INFO) ✓Cache settings 58 What can be changed?
  63. ERIKREAGAN • EECI GETTING SET UP /config/ config.env.php config.master.php config.{ENV}.php

    /public_html/ /system/ /tpl/ 59 Directory and file structure
  64. ERIKREAGAN • EECI GETTING SET UP if ( ! defined('ENV'))

    { switch ($_SERVER['HTTP_HOST']) { case 'focuslabllc.com' : define('ENV', 'prod'); define('ENV_FULL', 'Production'); define('ENV_DEBUG', FALSE); break; case 'ohsnap.focuslabllc.com' : define('ENV', 'stage'); define('ENV_FULL', 'Staging'); define('ENV_DEBUG', FALSE); break; default : define('ENV', 'local'); define('ENV_FULL', 'Local'); define('ENV_DEBUG', TRUE); break; } } 60 config.env.php sample
  65. ERIKREAGAN • EECI GETTING SET UP <?php if ( !

    defined('BASEPATH')) exit('No direct script access allowed'); /** * Development config overrides & db credentials * * Our database credentials and any environment-specific overrides * * @package Focus Lab Master Config * @version 1.1 * @author Erik Reagan <erik@focuslabllc.com> */ $env_db['hostname'] = 'localhost'; $env_db['username'] = ''; $env_db['password'] = ''; $env_db['database'] = ''; $config['webmaster_email'] = 'dev@focuslabllc.com'; /* End of file config.dev.php */ /* Location: ./config/config.dev.php */ 61 config.dev.php sample
  66. ERIKREAGAN • EECI GETTING SET UP /** * Template settings

    * * Working locally we want to reference our template files. * In staging and production we do not use flat files * (for ever-so-slightly better performance) * This approach requires that we synchronize templates after * each deployment of template changes */ $env_config['save_tmpl_files'] = (ENV == 'prod') ? 'n' : 'y'; $env_config['tmpl_file_basepath'] = $base_path . '/../tpl/'; $env_config['hidden_template_indicator'] = '_'; 62 config.master.php sample
  67. ERIKREAGAN • EECI GETTING SET UP /** * Debugging settings

    * * These settings are helpful to have in one place * for debugging purposes */ $env_config['is_system_on'] = 'y'; $env_config['allow_extensions'] = 'y'; $env_config['email_debug'] = (ENV_DEBUG) ? 'y' : 'n' ; // Show template debugging if we're not in production $env_config['template_debugging'] = (ENV_DEBUG) ? 'y' : 'n' ; /** * Set debug to '2' if we're in dev mode, otherwise just '1' * * 0: no PHP/SQL errors shown * 1: Errors shown to Super Admins * 2: Errors shown to everyone */ $env_config['debug'] = (ENV_DEBUG) ? '2' : '1' ; 63 config.master.php sample
  68. ERIKREAGAN • EECI GETTING SET UP /** * 3rd Party

    Add-on config items as needed */ $env_config['minimee_cache_path'] = $base_path . '/min'; $env_config['minimee_cache_url'] = $base_url . '/min'; $env_config['minimee_remote_mode'] = 'auto'; $env_config['minimee_debug'] = 'n'; // Disable minimee in dev but not in staging and production $env_config['minimee_disable'] = (ENV == 'local') ? 'y' : 'n' ; // Greeny (auto-updating of upload directory paths) $env_config['greeny_enabled'] = (ENV == 'prod') ? 'false' : 64 config.master.php sample
  69. ERIKREAGAN • EECI FOCUS LAB CONFIG SETUP github.com/focuslabllc/ee-master-config 65

  70. ERIKREAGAN • EECI MULTI-ENVIRONMENT CHALLENGES You didn’t think it was

    that easy, did you? 66
  71. ERIKREAGAN • EECI BACK TO THE SURVEY 67

  72. 100% ERIKREAGAN • EECI 68

  73. 100% ERIKREAGAN • EECI 68 Keeping database changes synced across

    environments
  74. 72% ERIKREAGAN • EECI 69

  75. 72% ERIKREAGAN • EECI 69 Maintaining custom upload directory paths

  76. Devs who say the headaches are worth the trouble 100%

    ERIKREAGAN • EECI 70
  77. ERIKREAGAN • EECI 71 DATABASE ISSUES • New custom fields

    alter the DB schema • Installing or updating add-ons can alter the DB schema • Updating EE can alter the DB schema
  78. ERIKREAGAN • EECI DATABASE ISSUES • Custom upload directory paths

    are stored in the DB and cannot be dynamically altered • Relative upload directory paths work sometimes, but not with all add-ons • “Content” is very likely changing in the Production environment while you build and test in your other environments 72
  79. ERIKREAGAN • EECI 73 http://expressionengine.com/forums/viewthread/196480/

  80. ERIKREAGAN • EECI QUICK TIPS • You need to understand

    EE’s database • Learn about 3rd party add-on’s DB tables • Establish a ruleset for your workflow • Understand that there will be exceptions 74
  81. ERIKREAGAN • EECI 75 Schema / Structure flows up stream

  82. ERIKREAGAN • EECI 76 Content flows down stream

  83. ERIKREAGAN • EECI FINAL NOTES • These practices make you

    a better developer • They help prepare you to work with a team • They help your team work more efficiently • You can provide a better service to your clients 77
  84. ERIKREAGAN • EECI ERIKREAGAN Partner Focus Lab LLC FocusLabLLC 78