Tag Archives: capistrano

Using Capistrano for EC2 Deployment

9 Sep

SSH SETUP on your Development environment

Setup ssh private key

  • Download the Amazon EC2 Private Key (xyz.pem) to your development box.
  • Copy the xyz.pem to the .ssh directory under the /root directory. If you don’t have .ssh directory create one.
    • mkdir -p /root/.ssh
    • cp xyz.pem /root/.ssh
    • chmod 0600 /root/.ssh/xyz.pem
      • Required: Have to make the private key pair NOT world readable.

Test SSH access

  • In a terminal window, login into the the EC2 instance
    • ssh -i ~/.ssh/xyz.pem ec2-user@yourhost.compute-1.amazonaws.com
      • This will log you in as the as ec2-user
      • To switch to user root use “sudo -i”

Prerequisites for running remote deployment scritps

  • This is probably already configured on the existing EC2 instances. But if you are setting up new EC2 instances
    that you want to test, ensure the following configuration settings

Enable remote sudo access

  • Run the following on each EC2 instance that you want to remotely deploy to
  • sudo -i
  • visudo
  • Comment out the following line.
    Defaults    requiretty

     

pgpass file setup on DB instance

Install Capistrano on your development box

    • yum install ruby rubygems
    • gem install capistrano capistrano-ext railsless-deploy
  • Create the build file
    • mkdir -p /opt/capistrano
    • Generate the Capistrano Capfile under this directory

Run Deployment Scripts

Run deploy:setup

  • cd /opt/capistrano
  • cap deploy:setup
    • This command will create the deployment directory structure. The directories under releases will not be created just yet.
      Each time you deploy, a new directory will be created under the “releases” directory, and the new version placed there.
      Then, the “current” symbolic link will be updated to point to that directory.

      /opt/apps/appname
      /opt/apps/appname/releases
      /opt/apps/appname/releases/20080819001122
      /opt/apps/appname/releases/...
      /opt/apps/appname/current -> /opt/app/appname/releases/20100819001122

       

Perform a code push/update

  • cd /opt/capistrano
  • cap –set scm_username=<YOUR SVN USERID> –set scm_password=<YOUR_SVN_PASSWORD> deploy
    • ALTERNATIVELY, enter your svn userid and password in the Capfile and ensure you uncomment those lines then you can run just “cap deploy”
    • The deploy task does the following:
      • get’s the latest code from subversion and copies it to /opt/apps/appname/releases on all ec2 instances
      • other custom capistrano tasks are also executed

References