EE + CAP + Git = Happiness

EE + CAP + Git = Happiness

Using Cap and Git to make EE deployments smoother.

98e7524451cd8ec1bf8f644d2c2f01c9?s=128

Trevor Davis

June 28, 2013
Tweet

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. INTRO TO GIT

  10. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. WHAT IS GIT?
  11. -. 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.
  12.  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.
  13. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. DISTRIBUTED
  14. -. 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.
  15. git-scm.com CREDITS

  16. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

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

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

    is CONFIDENTIAL and should not be shared without permission.
  19. >  git  remote  add  origin   git@github.com:user/repo_name.git © Viget Labs,

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

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

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

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

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

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

    should not be shared without permission. IGNORING FILES
  26. © 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
  27. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. BRANCHING
  28. git-scm.com CREDITS

  29. >  git  branch  some-­‐feature © Viget Labs, LLC • This

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

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

    This presentation is CONFIDENTIAL and should not be shared without permission.
  32. EE + GIT

  33. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

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

    Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
  35. arrestedstills.tumblr.com CREDITS THAT WAS THE WORST.

  36. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. DEVELOP LOCALLY
  37. © 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
  38. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. BASE INSTALL
  39. © 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
  40. >  git  clone  git@github.com:vigetlabs/ EEMaster.git  peersdemo © Viget Labs, LLC

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

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

    should not be shared without permission. DON’T BE SCARED OF RUBY
  43. 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)
  44. $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.
  45. $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.
  46. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. THE DB
  47. © 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
  48. ENVIRONMENTS

  49. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

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

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

    should not be shared without permission. STAGING
  52. © 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
  53. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

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

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

    should not be shared without permission. FLOW
  56. © 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
  57. © 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
  58. © 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
  59. DEPLOYING

  60. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. HOW IT USED TO BE
  61. © 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
  62. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

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

    should not be shared without permission. IT ALL STARTED WITH DAN BENJAMIN
  64. None
  65. HOLY CRAP.

  66. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

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

    should not be shared without permission. SO WHAT IS CAPISTRANO?
  68. . Capistrano is a utility and framework for executing commands

    in parallel on multiple remote machines, via SSH.
  69. #  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.
  70. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. THE WHOLE PROCESS
  71. © 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
  72. 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:  git@github.com:vigetlabs/peersdemo.git  branch:  master  user:  www-­‐data  remote_db_settings:      adapter:  mysql      database:  eemaster_staging      username:  eemaster      password:  password      host:  localhost
  73. >  cap  staging  deploy:setup © Viget Labs, LLC • This

    presentation is CONFIDENTIAL and should not be shared without permission.
  74. 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.
  75. © 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
  76. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

    should not be shared without permission. WANT TO DEPLOY A CHANGE?
  77. >  cap  staging  deploy Want to deploy a change?

  78. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

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

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

    should not be shared without permission. BACK TO THE DB
  81. © 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
  82. >  cap  staging  sync:db_down © Viget Labs, LLC • This

    presentation is CONFIDENTIAL and should not be shared without permission.
  83. >  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.
  84. >  cap  staging  sync:content_down © Viget Labs, LLC • This

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

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

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

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

    should not be shared without permission. NOT EE SPECIFIC
  89. DEMO TIME

  90. © Viget Labs, LLC • This presentation is CONFIDENTIAL and

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

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

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