Top Banner
ВЫКЛАДКА БЕЗ БОЛИ С CAPISTRANO PAINLESS DEPLOYMENT WITH CAPISTRANO / Николай Кугаевский @kugaevsky
19

Painless Deployment with Capistrano

Jul 16, 2015

Download

Software

Nick Kugaevsky
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Painless Deployment with Capistrano

ВЫКЛАДКАБЕЗ БОЛИ С

CAPISTRANOPAINLESS DEPLOYMENT WITH CAPISTRANO

/ Николай Кугаевский @kugaevsky

Page 2: Painless Deployment with Capistrano

TRUE OLD SCHOOLRsyncSCPFTP

Page 3: Painless Deployment with Capistrano

NOT SO OLDssh → git pullFabric

Page 5: Painless Deployment with Capistrano

CAPISTRANO TO THE RESCUE

Page 6: Painless Deployment with Capistrano

CAPISTRANOCapistrano is a remote server automation and deployment tool

written in Ruby.

It supports the scripting and execution of arbitrary tasks, andincludes a set of sane-default deployment workflows.

Page 7: Painless Deployment with Capistrano

CAPISTRANORubyOpen sourceExpressive DSLSimity0-time deploy/rollbackMultistagingRoles

Page 8: Painless Deployment with Capistrano

INSTALL AND INIT

$ cd my_perfect_app $ gem install capistrano $ cap install

Page 9: Painless Deployment with Capistrano

CONFIG

# config/deploy.rbset :application, 'slides'set :repo_url, '[email protected]:kugaevsky/slides.git'

# config/deploy/staging.rbrole :app, %w{[email protected]}set :deploy_to, '/home/kugaevsky/www/slides.kugaevsky.ru'set :user, 'nick'

Page 10: Painless Deployment with Capistrano

ANATOMY LOCAL

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

Page 11: Painless Deployment with Capistrano

ANATOMY HOST

my_perfect_app├── current → ../releases/20141209222103├── releases│ ├── 20141209220703│ ├── 20141209222103│ └── ...├── repo│ ├── branches│ ├── config│ ├── description│ └── ...└── shared ├── node_modules ├── uploads ├── vendor └── ...

Page 12: Painless Deployment with Capistrano

DEPLOY FLOW

deploy:starting # start a deployment, make sure everything is readydeploy:started # started hook (for custom tasks)deploy:updating # update server(s) with a new releasedeploy:updated # updated hookdeploy:publishing # publish the new releasedeploy:published # published hookdeploy:finishing # finish the deployment, clean up everythingdeploy:finished # finished hook

Page 13: Painless Deployment with Capistrano

ROLLBACK FLOW

deploy:startingdeploy:starteddeploy:reverting # revert server(s) to previous releasedeploy:reverted # reverted hookdeploy:publishingdeploy:publisheddeploy:finishing_rollback # finish the rollback, clean up everythingdeploy:finished

Page 14: Painless Deployment with Capistrano

PLUGINS!

# Capfilerequire 'capistrano/rvm'require 'capistrano/rbenv'require 'capistrano/chruby'require 'capistrano/bundler'require 'capistrano/rails/assets'require 'capistrano/rails/migrations'

Page 15: Painless Deployment with Capistrano

REAL WORLD EXAMPLE

# config/deploy.rbdesc 'Create symlinks for npm modules'task :npm do on roles(:app) do execute "ln -nfs #{shared_path}/node_modules #{release_path}/node_modules" endend

desc 'Install npm modules'task :npm do on roles(:app) do execute "cd #{release_path} && npm install" endend

desc 'Compile assets'task :compile_assets do on roles(:app) do execute "cd #{release_path} && #{shared_path}/node_modules/.bin/gulp compile:production" endend

Page 16: Painless Deployment with Capistrano
Page 19: Painless Deployment with Capistrano

СПАСИБОВЫКЛАДКА БЕЗ БОЛИ С CAPISTRANO

PAINLESS DEPLOYMENT WITH CAPISTRANO

для

http://slides.kugaevsky.ru/Николай Кугаевский rannts#3