$30 off During Our Annual Pro Sale. View Details »

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

    View Slide

  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

    View Slide

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

    View Slide

  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?

    View Slide

  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.

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  9. INTRO TO GIT

    View Slide

  10. © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
    WHAT IS GIT?

    View Slide

  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.

    View Slide

  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.

    View Slide

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

    View Slide

  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.

    View Slide

  15. git-scm.com
    CREDITS

    View Slide

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

    View Slide

  17. © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
    ‎ Make changes
    ‎ Stage
    ‎ Commit
    ‎ Pull
    ‎ Push
    BASIC WORKFLOW

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

  28. git-scm.com
    CREDITS

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  32. EE + GIT

    View Slide

  33. © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
    REMEMBER THIS?

    View Slide

  34. {if  member_group  ==  "1"}
      Some  new  feature
    {/if}
    © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.

    View Slide

  35. arrestedstills.tumblr.com
    CREDITS
    THAT WAS
    THE WORST.

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

  40. >  git  clone  [email protected]:vigetlabs/
    EEMaster.git  peersdemo
    © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.

    View Slide

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

    View Slide

  42. © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
    DON’T BE SCARED
    OF RUBY

    View Slide

  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)

    View Slide

  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.

    View Slide

  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.

    View Slide

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

    View Slide

  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

    View Slide

  48. ENVIRONMENTS

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  59. DEPLOYING

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

  64. View Slide

  65. HOLY CRAP.

    View Slide

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

    View Slide

  67. © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.
    SO WHAT IS
    CAPISTRANO?

    View Slide

  68. .
    Capistrano is a utility and framework for executing
    commands in parallel on multiple remote machines,
    via SSH.

    View Slide

  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.

    View Slide

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

    View Slide

  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

    View Slide

  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:  [email protected]:vigetlabs/peersdemo.git
     branch:  master
     user:  www-­‐data
     remote_db_settings:
         adapter:  mysql
         database:  eemaster_staging
         username:  eemaster
         password:  password
         host:  localhost

    View Slide

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

    View Slide

  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.

    View Slide

  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

    View Slide

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

    View Slide

  77. >  cap  staging  deploy
    Want to deploy a change?

    View Slide

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

    View Slide

  79. >  cap  staging  deploy  -­‐s  branch=carousel
    © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.

    View Slide

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

    View Slide

  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

    View Slide

  82. >  cap  staging  sync:db_down
    © Viget Labs, LLC • This presentation is CONFIDENTIAL and should not be shared without permission.

    View Slide

  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.

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  89. DEMO TIME

    View Slide

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

    View Slide

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

    View Slide

  92. View Slide

  93. © 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

    View Slide