View
190
Download
5
Category
Tags:
Preview:
DESCRIPTION
A remote server automation and deployment tool written in Ruby.
Citation preview
Revealing Hour CreationsSagar P Junnarkarsj@revealinghour.in@sagarjunnarkar
Deployment with capistrano
How do we deploy?
FTP,SFTP,SCP?SSH+GIT?Debian packages?Don’t know? Other team does it for you.
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
What do we need?
What do we need?
●Give limited power to developers●Automate entire deployment process
System admins don’t want you to touching their stuff
System admins don’t want you to touching their stuff
Standard server env:●Convention●Consistency●Security●Monitoring
working together to get the job done
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
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.
Simplest explanation
●Lets you write scripts that say “ssh ontoremote machine and do things.”●Program your deployment actions
Setup and configuration
gem install capistranocap -T # List all commandscapify . #capistrano v2cap install #capistrano v3
Local Directory Structure
├── Capfile├── config│ ├── deploy│ │ ├── production.rb│ │ └── staging.rb│ └── deploy.rb└── lib └── capistrano
└── tasks
├── Capfile├── config
│ ├── deploy.rb
Server Directory Structure
myapp/releasesmyapp/current -> releases/20141001001122myapp/shared
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
How does it works
●No software installed on server, just locally●Capistrano builds commands to be executed
remotely●executed on the server over ssh
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
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
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.
Deploy configurationIn deploy.rbset :application, ‘site.com’’set :scm, :gitset :repository, “git@github.com/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
Made mistake
Oops.
We’re sorry but something went wrong
Rollback deployment
cap deploy:rollbackSet current symlink to previous release directory
Questions
Thank you
Recommended