From af6fefc399ff8cf399c9f06e629af9947c873cbf Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Fri, 11 Jul 2014 11:34:58 +0200 Subject: [PATCH] Upgrade and add deploy options --- .gitignore | 1 + Capfile | 27 ++++++++++--- Gemfile | 1 + Gemfile.lock | 31 ++++++++++----- config/deploy.rb | 78 ++++++++++++++++++++++--------------- config/deploy/production.rb | 45 +++++++++++++++++++++ config/deploy/staging.rb | 45 +++++++++++++++++++++ 7 files changed, 183 insertions(+), 45 deletions(-) create mode 100644 config/deploy/production.rb create mode 100644 config/deploy/staging.rb diff --git a/.gitignore b/.gitignore index a17a25b8..4b936008 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ custom_plan.rb public/capybara.html chromedriver.log /coverage +/old_cap diff --git a/Capfile b/Capfile index f9df16e0..080238a9 100644 --- a/Capfile +++ b/Capfile @@ -1,8 +1,25 @@ -load 'deploy' if respond_to?(:namespace) # cap2 differentiator +# Load DSL and Setup Up Stages +require 'capistrano/setup' -# Uncomment if you are using Rails' asset pipeline -load 'deploy/assets' +# Includes default deployment tasks +require 'capistrano/deploy' -Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } +# Includes tasks from other gems included in your Gemfile +# +# For documentation on these, see for example: +# +# https://github.com/capistrano/rvm +# https://github.com/capistrano/rbenv +# https://github.com/capistrano/chruby +# https://github.com/capistrano/bundler +# https://github.com/capistrano/rails +# +# require 'capistrano/rvm' +# require 'capistrano/rbenv' +# require 'capistrano/chruby' +# require 'capistrano/bundler' +# require 'capistrano/rails/assets' +# require 'capistrano/rails/migrations' -load 'config/deploy' # remove this line to skip loading any of the default tasks +# Loads custom tasks from `lib/capistrano/tasks' if you have any defined. +Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } diff --git a/Gemfile b/Gemfile index 6c8f4c1c..c916a1ef 100644 --- a/Gemfile +++ b/Gemfile @@ -80,6 +80,7 @@ group :development do gem 'thin' gem 'faye' gem 'pry-rails' + gem 'capistrano', '~> 3.0', require: false #gem 'spring' #gem 'spring-commands-rspec' end diff --git a/Gemfile.lock b/Gemfile.lock index 1263fa72..f851c08d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -92,6 +92,10 @@ GEM sass (~> 3.2) thor builder (3.2.2) + capistrano (3.2.1) + i18n + rake (>= 10.0.0) + sshkit (~> 1.3) capybara (2.4.1) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -109,10 +113,11 @@ GEM coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) - coffee-script (2.2.0) + coffee-script (2.3.0) coffee-script-source execjs - coffee-script-source (1.7.0) + coffee-script-source (1.7.1) + colorize (0.7.3) connection_pool (2.0.0) cookiejar (0.3.2) couchbase (1.3.8) @@ -203,10 +208,10 @@ GEM haml (>= 3.1, < 5.0) railties (>= 4.0.1) handlebars-source (1.3.0) - hashie (2.1.2) + hashie (3.2.0) hike (1.2.3) http_parser.rb (0.6.0) - i18n (0.6.9) + i18n (0.6.11) jquery-rails (3.1.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) @@ -237,23 +242,26 @@ GEM multi_json (1.10.1) multi_xml (0.5.5) multipart-post (2.0.0) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (2.9.1) nokogiri (1.6.2.1) mini_portile (= 0.6.0) - oauth2 (0.9.4) + oauth2 (1.0.0) faraday (>= 0.8, < 0.10) jwt (~> 1.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (~> 1.2) - omniauth (1.2.1) - hashie (>= 1.2, < 3) + omniauth (1.2.2) + hashie (>= 1.2, < 4) rack (~> 1.0) omniauth-facebook (1.6.0) omniauth-oauth2 (~> 1.1) - omniauth-oauth2 (1.1.2) + omniauth-oauth2 (1.2.0) faraday (>= 0.8, < 0.10) multi_json (~> 1.3) - oauth2 (~> 0.9.3) + oauth2 (~> 1.0) omniauth (~> 1.2) orm_adapter (0.5.0) paperclip (4.2.0) @@ -349,6 +357,10 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (~> 2.8) + sshkit (1.5.1) + colorize + net-scp (>= 1.1.2) + net-ssh (>= 2.8.0) subexec (0.2.3) temple (0.6.8) thin (1.6.2) @@ -385,6 +397,7 @@ DEPENDENCIES active_decorator bootstrap-sass (~> 2.3) bourbon + capistrano (~> 3.0) capybara capybara-webkit cmtool! diff --git a/config/deploy.rb b/config/deploy.rb index f8890b3b..1ad9b014 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,42 +1,58 @@ -#$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) -require "bundler/capistrano" -#load 'deploy/assets' -# -load 'config/recipes/monit' +# config valid only for Capistrano 3.1 +lock '3.2.1' -# Load RVM's capistrano plugin. -#require "rvm/capistrano" +set :application, 'qwaiter' +set :repo_url, 'root@uflows.com:/var/git/qwaiter.git' -set :application, "qwaiter" -set :repository, "root@uflows.com:/var/git/qwaiter.git" +# Default branch is :master +# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call -set :scm, :git -#set :revision, '89700f36e9' -# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none` +# Default deploy_to directory is /var/www/my_app +# set :deploy_to, '/var/www/my_app' -# Do not touch public/images,stylesheets,javascripts -set :normalize_asset_timestamps, false +# Default value for :scm is :git +# set :scm, :git -role :web, "qwaiter.com" # Your HTTP server, Apache/etc -role :app, "qwaiter.com" # This may be the same as your `Web` server -#role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run -#role :db, "your slave db-server here" +# Default value for :format is :pretty +# set :format, :pretty -# if you're still using the script/reaper helper you will need -# these http://github.com/rails/irs_process_scripts +# Default value for :log_level is :debug +# set :log_level, :debug -set :deploy_via, :remote_cache -set :branch, :master -set :user, 'root' -set :deploy_to, '/var/www/qwaiter' -#set :bundle_cmd, 'bundle install --deployment' +# Default value for :pty is false +# set :pty, true + +# Default value for :linked_files is [] +# set :linked_files, %w{config/database.yml} + +# Default value for linked_dirs is [] +# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} + +# Default value for default_env is {} +# set :default_env, { path: "/opt/ruby/bin:$PATH" } + +# Default value for keep_releases is 5 +# set :keep_releases, 5 -# If you are using Passenger mod_rails uncomment this: namespace :deploy do - task :start do ; end - task :stop do ; end - task :restart, :roles => :app, :except => { :no_release => true } do - run "#{try_sudo} chown -R www-data:www-data #{release_path}" - run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" + + desc 'Restart application' + task :restart do + on roles(:app), in: :sequence, wait: 5 do + # Your restart mechanism here, for example: + # execute :touch, release_path.join('tmp/restart.txt') + end end + + after :publishing, :restart + + after :restart, :clear_cache do + on roles(:web), in: :groups, limit: 3, wait: 10 do + # Here we can do anything such as: + # within release_path do + # execute :rake, 'cache:clear' + # end + end + end + end diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 00000000..00c479cb --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,45 @@ +# Simple Role Syntax +# ================== +# Supports bulk-adding hosts to roles, the primary server in each group +# is considered to be the first unless any hosts have the primary +# property set. Don't declare `role :all`, it's a meta role. + +role :app, %w{deploy@qwaiter.com} +role :web, %w{deploy@qwaiter.com} +role :db, %w{deploy@qwaiter.com} + + +# Extended Server Syntax +# ====================== +# This can be used to drop a more detailed server definition into the +# server list. The second argument is a, or duck-types, Hash and is +# used to set extended properties on the server. + +server 'qwaiter.com', user: 'root', roles: %w{web app}, my_property: :my_value + + +# Custom SSH Options +# ================== +# You may pass any option but keep in mind that net/ssh understands a +# limited set of options, consult[net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start). +# +# Global options +# -------------- +# set :ssh_options, { +# keys: %w(/home/rlisowski/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(password) +# } +# +# And/or per server (overrides global) +# ------------------------------------ +# server 'qwaiter.com', +# user: 'user_name', +# roles: %w{web app}, +# ssh_options: { +# user: 'user_name', # overrides user setting above +# keys: %w(/home/user_name/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(publickey password) +# # password: 'please use keys' +# } diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb new file mode 100644 index 00000000..e664a6cd --- /dev/null +++ b/config/deploy/staging.rb @@ -0,0 +1,45 @@ +# Simple Role Syntax +# ================== +# Supports bulk-adding hosts to roles, the primary server in each group +# is considered to be the first unless any hosts have the primary +# property set. Don't declare `role :all`, it's a meta role. + +role :app, %w{deploy@example.com} +role :web, %w{deploy@example.com} +role :db, %w{deploy@example.com} + + +# Extended Server Syntax +# ====================== +# This can be used to drop a more detailed server definition into the +# server list. The second argument is a, or duck-types, Hash and is +# used to set extended properties on the server. + +server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value + + +# Custom SSH Options +# ================== +# You may pass any option but keep in mind that net/ssh understands a +# limited set of options, consult[net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start). +# +# Global options +# -------------- +# set :ssh_options, { +# keys: %w(/home/rlisowski/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(password) +# } +# +# And/or per server (overrides global) +# ------------------------------------ +# server 'example.com', +# user: 'user_name', +# roles: %w{web app}, +# ssh_options: { +# user: 'user_name', # overrides user setting above +# keys: %w(/home/user_name/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(publickey password) +# # password: 'please use keys' +# }