25
Revealing Hour Creations Sagar P Junnarkar [email protected] @sagarjunnarkar

Deployment with capistrano

Embed Size (px)

DESCRIPTION

A remote server automation and deployment tool written in Ruby.

Citation preview

Page 1: Deployment with capistrano

Revealing Hour CreationsSagar P [email protected]@sagarjunnarkar

Page 2: Deployment with capistrano

Deployment with capistrano

Page 3: Deployment with capistrano

How do we deploy?

FTP,SFTP,SCP?SSH+GIT?Debian packages?Don’t know? Other team does it for you.

Page 4: Deployment with capistrano

What are the issues●Lot of manual processes-backup db, update code, update db etc.●Room for error. steps could be missed.●Small organisation : loose server access and

permissions●Large organisation : too restrictive

permissions. locked down server env

Page 5: Deployment with capistrano

What do we need?

Page 6: Deployment with capistrano

What do we need?

●Give limited power to developers●Automate entire deployment process

Page 7: Deployment with capistrano

System admins don’t want you to touching their stuff

Page 8: Deployment with capistrano

System admins don’t want you to touching their stuff

Standard server env:●Convention●Consistency●Security●Monitoring

Page 9: Deployment with capistrano

working together to get the job done

Page 10: Deployment with capistrano

working together to get the job done

●Developers are able to deploy rapidly●Sys admins have tight control of environments●All manual process are automated

Page 11: Deployment with capistrano

Capistrano www.capistranorb.com

●Introduced around 2006 by Jamis Buck of 37 signals●Written in ruby, initially for rails project●It is a developer tool for deploying web

applications. It is typically installed on your workstation and used to deploy your SCM to one or more servers.

Page 12: Deployment with capistrano

Simplest explanation

●Lets you write scripts that say “ssh ontoremote machine and do things.”●Program your deployment actions

Page 13: Deployment with capistrano

Setup and configuration

gem install capistranocap -T # List all commandscapify . #capistrano v2cap install #capistrano v3

Page 14: Deployment with capistrano

Local Directory Structure

├── Capfile├── config│ ├── deploy│ │ ├── production.rb│ │ └── staging.rb│ └── deploy.rb└── lib └── capistrano

└── tasks

├── Capfile├── config

│ ├── deploy.rb

Page 15: Deployment with capistrano

Server Directory Structure

myapp/releasesmyapp/current -> releases/20141001001122myapp/shared

Page 16: Deployment with capistrano

Symlink for shared files

Symlinks are made back to the shared folder,so they are not lost between deployments.

e.g. myapp/current/uploads -> myapp/shared/uploads

Page 17: Deployment with capistrano

How does it works

●No software installed on server, just locally●Capistrano builds commands to be executed

remotely●executed on the server over ssh

Page 18: Deployment with capistrano

Local Server

Lookup current revision in source control

ssh into server using ssh public key

checkout specified revision from source control

copy a new timestamped site directory

Add symlinks to shared directories

update current symlink to new site directory

Simple Deployment Workflow

Page 19: Deployment with capistrano

Hooks

Before and after hooks at each stage of the deployment lifecycleExtend or customise default capistrano behaviorExamples: deploy, deploy:setup,deploy:symlink, deploy:update_code, deploy:rollback

Page 20: Deployment with capistrano

Some common recipes

cap deploy # Deploys your project.cap deploy:check # Check required files and directories existcap deploy:cleanup # Clean up old releases.cap deploy:migrate # Run the migrate rake task.

Page 21: Deployment with capistrano

Deploy configurationIn deploy.rbset :application, ‘site.com’’set :scm, :gitset :repository, “[email protected]/sagarjunnarkar/site.git”set :branch, “master”set :port, 22set :user, 'ubuntu'set :deploy_to, “/home/#{user}/#{application}” #/home/ubuntu/site.comrole :app, ‘www.example.com’#server "54.169.95.188", :web

Page 22: Deployment with capistrano

Made mistake

Oops.

We’re sorry but something went wrong

Page 23: Deployment with capistrano

Rollback deployment

cap deploy:rollbackSet current symlink to previous release directory

Page 24: Deployment with capistrano

Questions

Page 25: Deployment with capistrano

Thank you