deploy made easy (even on friday)

23
DEPLOY MADE EASY (even on Friday) Riccardo Bini @odracci

Upload: riccardo-bini

Post on 07-May-2015

1.828 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Deploy made easy (even on Friday)

DEPLOY MADE EASY(even on Friday)

Riccardo Bini@odracci

Page 2: Deploy made easy (even on Friday)

In the beginning

Page 3: Deploy made easy (even on Friday)
Page 4: Deploy made easy (even on Friday)

FAIL

Page 5: Deploy made easy (even on Friday)

DEPLOY TOOLS

• Idephix

• puppet

• fabric

Page 6: Deploy made easy (even on Friday)

CAPISTRANO

Capistrano is an open source tool for running scripts on multiple servers; its main use is deploying web applications. It automates the process of making a new version of an application available on one or more web servers, including supporting tasks such as changing databases.

http://en.wikipedia.org/wiki/Capistrano

Page 7: Deploy made easy (even on Friday)

WHY?

One-click deploy

Deploy in transaction

Rollback

Automated tasks (minifing CSS/JS, DB migrations)

Page 8: Deploy made easy (even on Friday)

RECIPES

Capifony http://capifony.org

Railsless-deploy https://github.com/leehambley/railsless-deploy

Multistage https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension

Page 9: Deploy made easy (even on Friday)

`-- /var/www/my-app.com|-- current ! /var/www/my-app.com/releases/20131004131539|-- releases| `-- 20131004131539| `-- 20131004150741| `-- 20131004145325`-- shared |-- web | `-- uploads `-- config `-- config.php

HOW IT WORKS

Page 10: Deploy made easy (even on Friday)

HOW IT WORKS

ssh to the server (my-app.com)• create a new release path (/var/www/my-app.com/releases/...)• pull the latest project version from the remote git repo• copy the source code, pulled from git, into the release path

http://capifony.org

Page 11: Deploy made easy (even on Friday)

HOW IT WORKS

Page 12: Deploy made easy (even on Friday)

$ capify .[add] writing './Capfile'[add] making directory './config'[add] writing './config/deploy.rb'[done] capified!

SETUP

$ cap deploy:setup

Page 13: Deploy made easy (even on Friday)

# to deploy: cap -S branch=<branchname> deployset :application, "set your application name here"set :repository, "[email protected]:odracci/#{application}.git"set :scm, :git

server "my-app.com", :app, :web, :db, :primary => trueset :deploy_to, "/var/www/my-app.com"set :branch, fetch(:branch, "master")

set :shared_children, ["web/uploads", "config"]set :user, "vagrant"set :group_writable, trueset :use_sudo, falseset :copy_exclude, [".git"]set :deploy_via, :remote_cacheset :keep_releases, 5ssh_options[:forward_agent] = truedefault_run_options[:pty] = true

logger.level = Logger::MAX_LEVEL

# if you want to clean up old releases on each deploy uncomment this:after "deploy:restart", "deploy:cleanup"

config/deploy.rb

Page 14: Deploy made easy (even on Friday)

$ cap <env> deploy

server "www.my-app.com", :app, :web, :db, :primary => trueset :deploy_to, "/var/www/my-app.com"set :branch, fetch(:branch, "master")

MULTISTAGE

server "s.my-app.com", :app, :web, :db, :primary => trueset :deploy_to, "/var/www/my-app.com"set :branch, fetch(:branch, "develop")

config/deploy/production.rb

config/deploy/staging.rb

command line

Page 15: Deploy made easy (even on Friday)

cap deploy # Deploys your project.cap deploy:check # Test deployment dependencies.cap deploy:cleanup # Clean up old releases.cap deploy:cold # Deploys and starts a `cold' application.cap deploy:create_symlink # Updates the symlink to the most recently deployed...cap deploy:migrate # Run the migrate rake task.cap deploy:migrations # Deploy and run pending migrations.cap deploy:pending # Displays the commits since your last deploy.cap deploy:pending:diff # Displays the `diff' since your last deploy.cap deploy:restart # Blank task exists as a hook into which to install...cap deploy:rollback # Rolls back to a previous version and restarts.cap deploy:rollback:code # Rolls back to the previously deployed version.cap deploy:setup # Prepares one or more servers for deployment.cap deploy:start # Blank task exists as a hook into which to install...cap deploy:stop # Blank task exists as a hook into which to install...cap deploy:symlink # Deprecated API.cap deploy:update # Copies your project and updates the symlink.cap deploy:update_code # Copies your project to the remote servers.cap deploy:upload # Copy files to the currently deployed version.cap invoke # Invoke a single command on the remote servers.cap shell # Begin an interactive Capistrano session.

cap -T

Page 16: Deploy made easy (even on Friday)

namespace :deploy do task :start do end task :stop do

end task :restart, :roles => :app, :except => { :no_release => true } do run "sudo /etc/init.d/httpd restart" endend

Override Tasks

Page 17: Deploy made easy (even on Friday)

namespace :config do desc "Upload config/config.php to remote server" task :to_remote do upload("config/config.php", "#{shared_path}/config/config.php", :via => :scp) endend

$ cap config:to_remote

Custom Tasks

Page 18: Deploy made easy (even on Friday)

WTF

Page 19: Deploy made easy (even on Friday)

[my-app.com] executing command ** [my-app.com :: out] Permission denied (publickey). ** [my-app.com :: out] ** [my-app.com :: out] fatal: The remote end hung up unexpectedly ** [my-app.com :: out] command finished in 2769ms*** [deploy:update_code] rolling back

WTF

$ ssh-add

Page 20: Deploy made easy (even on Friday)

namespace :deploy do desc 'Show deployed revision' task :revision, :roles => :app do run "#{try_sudo} cat #{current_path}/REVISION" endend

WTF

$ cap deploy:revision

Page 21: Deploy made easy (even on Friday)

#server "server1, :app, :web, :db, :primary => truerole :app, "server1", "server2"role :web, "server1", "server2"role :db, "dbserver", :primary => true

SCALING WEB APPS

$ cap deploy:setup

Page 22: Deploy made easy (even on Friday)

THANKS

Riccardo Bini

@odracci

github.com/odracci

Page 23: Deploy made easy (even on Friday)

QUESTIONS?