Skip to content

Instantly share code, notes, and snippets.

@erikhansen
Created March 15, 2019 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikhansen/6b900aec63bcf1b1ca84d9172188a68a to your computer and use it in GitHub Desktop.
Save erikhansen/6b900aec63bcf1b1ca84d9172188a68a to your computer and use it in GitHub Desktop.
Capistrano Deployment From Start to Finish

Prerequisites

  • Have SSH access to the target server(s) using PKA (public key authentication)
  • Either your public key or a deploy key on the target server(s) has been added to the source repository as a deploy key
  • The system you are running deployments from has Ruby 2.2 or later installed (RHEL/CentOS users may reference this gist as a means of meeting this requirement)

Setting Up the Deployment Toolchain

  1. Install bundler (http://bundler.io/):

     gem install bundler
    
  2. Clone the git repository:

     git clone git@github.com:classyllama/exampledomain-com.git
    
  3. Install project deployment dependencies:

     cd exampledomain-com/tools/cap
     bundle install
    

Execute a Deployment

  1. Find out what deployment stages (may be better thought of as target configurations) are configured on your system:

     ls -1 config/deploy | sed 's/\.rb//'
    

    In a typical setup, you'll likely see stage and prod listed. The former being the stage site where code is tested and the latter being the production system where real customers browse the site.

  2. Move into the tools/cap directory of your project repository:

     cd exampledomain-com/tools/cap
    
  3. Run the following deployment command, replacing <stage> with one of the stages listed in step #1:

     bundle exec cap <stage> deploy
    

    The output of this command should look something like the following:

     00:00 git:wrapper
           01 mkdir -p /home/www-data/tmp
         ✔ 01 www-data@target-server 0.876s
         
     /// a lot of additional output here... 
         
     00:10 deploy:cleanup
           Keeping 10 of 11 deployed releases on target-server
           01 rm -rf /var/www/data/releases/20161103160141
         ✔ 01 www-data@target-server 0.727s
     00:10 deploy:log_revision
           01 echo "Branch master (at 4a6b0d4b1cd42a91f4cfed13aecf395629ebdfbd) deployed as release...
         ✔ 01 www-data@target-server 0.085s
    
  4. Load up the site and verify the deployment ran successfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment