Upgrade to Pro — share decks privately, control downloads, hide ads and more …

EE + CAP + Git = Happiness

EE + CAP + Git = Happiness

Using Cap and Git to make EE deployments smoother.

Trevor Davis

June 28, 2013
Tweet

More Decks by Trevor Davis

Other Decks in Technology

Transcript

  1. by Trevor Davis at Peers on June ,  ©

    Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission. EE + CAP + GIT = HAPPINESS
  2. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. @trevor_davis HI! I’M I work as a Senior Front-End Developer at Viget. TREVOR DAVIS
  3. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. YES, THAT’S HOW YOU PRONOUNCE IT. SAYVIGET.COM
  4. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. I. Intro to Git II. EE + Git III. Environments IV. Deploying V. Demo Time WHAT WILL WE COVER?
  5. WHO CURRENTLY USES GIT OR ANOTHER FORM OF VERSION CONTROL?

    © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  6. WHO USES EXPRESSIONENGINE? © Viget Labs, LLC • This presentation

    is CONFIDENTIAL and should not be shared without permission.
  7. WHO USES GIT & EXPRESSIONENGINE TOGETHER? © Viget Labs, LLC

    • This presentation is CONFIDENTIAL and should not be shared without permission.
  8. WHO USES A DEPLOYMENT TOOL TO DEPLOY THEIR SITES? ©

    Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  9. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. WHAT IS GIT?
  10. -. Git is a free and open source DISTRIBUTED version

    control system. Git has a tiny footprint with lightning FAST performance and features like cheap local branching, convenient staging areas, and multiple workflows.
  11.  Every Git working directory is a full-fledged repository with

    complete history and full revision tracking capabilities, not dependent on network access or a central server.
  12. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. DISTRIBUTED
  13. -. Instead of doing a “checkout” of the current tip

    of the source code, you do a “clone” of the entire repository. This means that even if you're using a centralized workflow, every user essentially has a full backup of the main server.
  14. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. BASIC WORKFLOW
  15. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Make changes ‎ Stage ‎ Commit ‎ Pull ‎ Push BASIC WORKFLOW
  16. >  git  init © Viget Labs, LLC • This presentation

    is CONFIDENTIAL and should not be shared without permission.
  17. >  git  remote  add  origin   [email protected]:user/repo_name.git © Viget Labs,

    LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  18. >  git  status © Viget Labs, LLC • This presentation

    is CONFIDENTIAL and should not be shared without permission.
  19. >  git  add  . © Viget Labs, LLC • This

    presentation is CONFIDENTIAL and should not be shared without permission.
  20. >  git  commit  -­‐m  "here  is  the  message" © Viget

    Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  21. >  git  pull © Viget Labs, LLC • This presentation

    is CONFIDENTIAL and should not be shared without permission.
  22. >  git  push © Viget Labs, LLC • This presentation

    is CONFIDENTIAL and should not be shared without permission.
  23. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. IGNORING FILES
  24. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ A .gitignore files tells Git which files to ignore ‎ These files don’t get pushed into the repository ‎ Sample: .DS_Store uploads .sass-­‐cache IGNORING FILES
  25. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. BRANCHING
  26. >  git  branch  some-­‐feature © Viget Labs, LLC • This

    presentation is CONFIDENTIAL and should not be shared without permission.
  27. >  git  checkout  some-­‐feature © Viget Labs, LLC • This

    presentation is CONFIDENTIAL and should not be shared without permission.
  28. >  git  checkout  -­‐b  some-­‐feature © Viget Labs, LLC •

    This presentation is CONFIDENTIAL and should not be shared without permission.
  29. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. REMEMBER THIS?
  30. {if  member_group  ==  "1"}   Some  new  feature {/if} ©

    Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  31. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. DEVELOP LOCALLY
  32. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Make changes on your machine ‎ Push to staging server for the client to verify ‎ Easily rollback if necessary ‎ Multiple developers ‎ Work in branches ‎ Never open FTP again DEVELOP LOCALLY
  33. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. BASE INSTALL
  34. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Private GitHub repo ‎ DB dump in repo ‎ Single config.php ‎ database.php for each environment (auto generated) BASE INSTALL
  35. >  git  clone  [email protected]:vigetlabs/ EEMaster.git  peersdemo © Viget Labs, LLC

    • This presentation is CONFIDENTIAL and should not be shared without permission.
  36. >  rake  setup © Viget Labs, LLC • This presentation

    is CONFIDENTIAL and should not be shared without permission.
  37. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. DON’T BE SCARED OF RUBY
  38. desc  "Setup  a  new  environment" task  :setup  do    unless

     File.exist?  "#{config_loc}"                #  ask  for  pertinent  details  about  local  environment                puts  "This  process  will  walk  through  setting  up  a  local  install  of  this   ExpressionEngine  project."        puts  "Please  answer  a  few  questions  about  you  local  mysql  installation  to   get  started"        puts  "\nLocation  of  mysql  binary?  [mysql]"        mysql_adapter  =  STDIN.gets.chomp!        mysql_adapter  =  mysql_adapter  ==  ""  ?  "mysql"  :  mysql_adapter                puts  "\nMySQL  server  address?  [localhost]"        mysql_server  =  STDIN.gets.chomp!        mysql_server  =  mysql_server  ==  ""  ?  "localhost"  :  mysql_server        puts  "\nMySQL  user?  [root]"        mysql_user  =  STDIN.gets.chomp!        mysql_user  =  mysql_user    ==  ""  ?  "root"  :  mysql_user        puts  "\nMySQL  password?"        mysql_pass  =  STDIN.gets.chomp!        puts  "\nMySQL  database  name?  [eemaster]"        mysql_db_name  =  STDIN.gets.chomp!        mysql_db_name  =  mysql_db_name  ==  ""  ?  "eemaster"  :  mysql_db_name        config_yml  =  ERB.new(File.read('./config/templates/ config.yml.erb')).result(binding)
  39. $config['site_url']  =  "http://{$_SERVER['HTTP_HOST']}/"; $config['base_path']  =  $_SERVER['DOCUMENT_ROOT']  .  '/'; $config['third_party_path']  =

     $config['base_path']  .   'third_party/'; $config['save_tmpl_files']  =  'y'; $config['tmpl_file_basepath']  =  $config['base_path']  .   'assets/templates/'; © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  40. $config['upload_preferences']  =  array  (   1  =>   array  (

        'name'  =>  'Images:  Team',     'server_path'  =>  $config['base_path']  .  'uploads/ images/team/',     'url'  =>  $config['site_url']    .  'uploads/images/ team/',   ) ); © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  41. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. THE DB
  42. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ The most complicated piece (with any app) ‎ You want your development environment to match as close as possible to production ‎ Once the site is live, all structural DB changes happen on production and “sync” down THE DB
  43. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. LOCAL
  44. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Easy, your computer ‎ System Apache, MAMP, XAMPP ‎ Virtual host LOCAL
  45. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. STAGING
  46. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ A “development” server that the client can access ‎ Server provisioning from a “recipe” ‎ LAMP stack ‎ Git, rake, etc. ‎ Uses the chef gem to create a server using the Rackspace Cloud API ‎ It’s for real some black magic STAGING
  47. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. PRODUCTION
  48. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ The live website ‎ Same server specs as staging PRODUCTION
  49. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. FLOW
  50. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Develop site locally ‎ Provision staging server ‎ Push to staging ‎ Client enters all content on staging PRE-LAUNCH FLOW
  51. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Provision production server ‎ Copy DB from staging to production ‎ All further content/DB changes happen on production LAUNCH
  52. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Staging becomes an area to preview new features ‎ All changes get pushed from development to staging, then to production ‎ All DB changes flow “down” POST LAUNCH
  53. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. HOW IT USED TO BE
  54. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Make changes locally ‎ Push to repo ‎ SSH into server, and pull in changes HOW IT USED TO BE
  55. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. MEH.
  56. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. IT ALL STARTED WITH DAN BENJAMIN
  57. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ENTER BLAKE WALTERS
  58. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. SO WHAT IS CAPISTRANO?
  59. #  Gemfile source  "https://rubygems.org" gem  "sass" gem  "compass" gem  "capistrano"

    gem  "rake" © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  60. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. THE WHOLE PROCESS
  61. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Clone EE base repo (local) ‎ bundle install (local) ‎ rake setup (local) ‎ Provision staging server ‎ Add environment to config.yml ‎ Provision production server ‎ Add environment to config.yml THE WHOLE PROCESS
  62. development:    local_db_settings:        adapter:  mysql    

       database:  peersdemo        username:  peersdemo        password:  password        host:  127.0.0.1 staging:  application:  eemaster.staging.vigetx.com  deploy_to:  /var/www/eemaster  repository:  [email protected]:vigetlabs/peersdemo.git  branch:  master  user:  www-­‐data  remote_db_settings:      adapter:  mysql      database:  eemaster_staging      username:  eemaster      password:  password      host:  localhost
  63. >  cap  staging  deploy:setup © Viget Labs, LLC • This

    presentation is CONFIDENTIAL and should not be shared without permission.
  64. after  "deploy:setup",  "deploy:after_setup" namespace  :deploy  do    desc  "Setup  a

     GitHub-­‐style  deployment."    task  :setup,  :except  =>  {  :no_release  =>  true  }  do        run  "git  clone  #{repository}  #{current_path}"    end    desc  "Create  additional  EE  directories  and  set   permissions  after  initial  setup"    task  :after_setup,  :roles  =>  :app  do        create_shared_directories        create_config        create_symlinks        set_permissions        import_db    end end © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  65. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Clones repo ‎ Creates shared directories and sets permissions ‎ Avatars, captchas, etc. ‎ Upload destinations ‎ Creates database.php ‎ Imports DB CAP SETUP
  66. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. WANT TO DEPLOY A CHANGE?
  67. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. WANT TO DEPLOY A DIFFERENT BRANCH?
  68. >  cap  staging  deploy  -­‐s  branch=carousel © Viget Labs, LLC

    • This presentation is CONFIDENTIAL and should not be shared without permission.
  69. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. BACK TO THE DB
  70. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. ‎ Needs tasks to: ‎ Copy DB from remote to local ‎ Copy DB from local to remote (rare) ‎ Copy content from remote to local ‎ Clear CE Cache ‎ Clear Stash Cache BACK TO THE DB
  71. >  cap  staging  sync:db_down © Viget Labs, LLC • This

    presentation is CONFIDENTIAL and should not be shared without permission.
  72. >  rake  export_db >  cap  staging  deploy >  cap  staging

     deploy:import_db © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  73. >  cap  staging  sync:content_down © Viget Labs, LLC • This

    presentation is CONFIDENTIAL and should not be shared without permission.
  74. >  cap  staging  deploy:clear_cache © Viget Labs, LLC • This

    presentation is CONFIDENTIAL and should not be shared without permission.
  75. >  cap  staging  deploy:clear_stash_cache © Viget Labs, LLC • This

    presentation is CONFIDENTIAL and should not be shared without permission.
  76. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. MAKE TASKS FOR ALL THE THINGS!
  77. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. NOT EE SPECIFIC
  78. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. QUESTIONS?
  79. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. WANT TO WORK WITH US?
  80. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. : viget.com : trevordavis.net : [email protected] : @trevor_davis Thanks! Let’s Connect