From 080593c76585bd1f45418e654842a6784728b246 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Sun, 1 Dec 2013 21:28:42 -0200 Subject: [PATCH] Capistrano 3 installed --- Capfile | 29 ++++++++++++++++++++++++++--- Gemfile | 6 ++++-- Gemfile.lock | 36 +++++++++++++++++++++--------------- config/deploy.rb | 71 ++++++++++++++++++++++++++++++++++++++++------------------------------- config/deploy/production.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+), 51 deletions(-) create mode 100644 config/deploy/production.rb diff --git a/Capfile b/Capfile index d30f46a..3a9dac7 100644 --- a/Capfile +++ b/Capfile @@ -1,3 +1,26 @@ -load 'deploy' -load 'deploy/assets' -load 'config/deploy' # remove this line to skip loading any of the default tasks \ No newline at end of file +# Load DSL and Setup Up Stages +require 'capistrano/setup' + +# Includes default deployment tasks +require 'capistrano/deploy' + +# 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/tree/master/assets +# https://github.com/capistrano/rails/tree/master/migrations +# +require 'capistrano/rvm' +# require 'capistrano/rbenv' +# require 'capistrano/chruby' +require 'capistrano/bundler' +require 'capistrano/rails/assets' +require 'capistrano/rails/migrations' + +# Loads custom tasks from `lib/capistrano/tasks' if you have any defined. +Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } diff --git a/Gemfile b/Gemfile index d4fca1b..ccda0b1 100644 --- a/Gemfile +++ b/Gemfile @@ -75,8 +75,10 @@ group :development, :test do gem 'factory_girl_rails', '~> 4.3.0' # Deployment - gem 'capistrano', "~>2.15.5" - gem 'rvm-capistrano' + gem 'capistrano', "~>3.0.1", require: false + gem 'capistrano-rails' + gem 'capistrano-bundler' + gem 'capistrano-rvm' # JavaScript unit tests gem "konacha", "~> 3.0.0" diff --git a/Gemfile.lock b/Gemfile.lock index abc16fa..c359a1b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,12 +32,19 @@ GEM atomic (1.1.14) bcrypt-ruby (3.1.2) builder (3.1.4) - capistrano (2.15.5) - highline - net-scp (>= 1.0.0) - net-sftp (>= 2.0.0) - net-ssh (>= 2.0.14) - net-ssh-gateway (>= 1.1.0) + capistrano (3.0.1) + i18n + rake (>= 10.0.0) + sshkit (>= 0.0.23) + capistrano-bundler (1.1.1) + capistrano (~> 3.0) + sshkit (>= 1.2.0) + capistrano-rails (1.1.0) + capistrano (>= 3.0.0) + capistrano-bundler (>= 1.0.0) + capistrano-rvm (0.1.0) + capistrano (~> 3.0) + sshkit (~> 1.2.0) capybara (2.1.0) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -92,7 +99,6 @@ GEM rmagick gyoku (1.1.0) builder (>= 2.1.2) - highline (1.6.20) hike (1.2.3) httpi (2.1.0) rack @@ -131,11 +137,7 @@ GEM multi_test (0.0.2) net-scp (1.1.2) net-ssh (>= 2.6.5) - net-sftp (2.1.2) - net-ssh (>= 2.6.5) net-ssh (2.7.0) - net-ssh-gateway (1.2.0) - net-ssh (>= 2.6.5) nokogiri (1.6.0) mini_portile (~> 0.5.0) nori-ng-1.6 (2.3.0) @@ -182,8 +184,6 @@ GEM rspec-expectations (~> 2.14.0) rspec-mocks (~> 2.14.0) rubyntlm (0.3.4) - rvm-capistrano (1.5.1) - capistrano (~> 2.15.4) sass (3.2.12) sass-rails (4.0.1) railties (>= 4.0.0, < 5.0) @@ -217,6 +217,10 @@ GEM activesupport (>= 3.0) sprockets (~> 2.8) sqlite3 (1.3.8) + sshkit (1.2.0) + net-scp (>= 1.1.2) + net-ssh + term-ansicolor term-ansicolor (1.2.2) tins (~> 0.8) therubyracer (0.12.0) @@ -254,7 +258,10 @@ PLATFORMS ruby DEPENDENCIES - capistrano (~> 2.15.5) + capistrano (~> 3.0.1) + capistrano-bundler + capistrano-rails + capistrano-rvm coffee-rails (~> 4.0.0) coveralls cucumber (~> 1.3.10) @@ -274,7 +281,6 @@ DEPENDENCIES poltergeist (~> 1.4.0) rails (= 4.0.1) rspec-rails - rvm-capistrano sass-rails (~> 4.0.0.rc2) sdoc shoulda-matchers diff --git a/config/deploy.rb b/config/deploy.rb index 88cbee1..4e7ef34 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,45 +1,54 @@ -require "rvm/capistrano" -require 'bundler/capistrano' +set :application, 'mezuro' +set :repo_url, 'https://github.com/mezuro/mezuro.git' -set :default_shell, "/bin/bash -l" -set :rails_env, "production" +# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp } -set :rvm_ruby_string, :local # use the same ruby as used locally for deployment -set :rvm_autolibs_flag, "read-only" # more info: rvm help autolibs -set :rvm_type, :user - -set :application, "mezuro" set :deploy_to, "/home/mezuro/app" -set :repository, "https://github.com/mezuro/mezuro.git" +# set :scm, :git -set :user, 'mezuro' -set :use_sudo, false -set :rvm_install_with_sudo, true -default_run_options[:pty] = true +# set :format, :pretty +# set :log_level, :debug +# set :pty, true -# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names -# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none` +# set :linked_files, %w{config/database.yml} +# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} -role :web, "mezuro.org" # Your HTTP server, Apache/etc -role :app, "mezuro.org" # This may be the same as your `Web` server -role :db, "mezuro.org", :primary => true # This is where Rails migrations will run +# set :default_env, { path: "/opt/ruby/bin:$PATH" } +# set :keep_releases, 5 -# before 'deploy:setup', 'rvm:install_rvm' # install RVM -before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, OR: -before 'deploy:setup', 'rvm:create_gemset' # only create gemset -after 'deploy:assets:symlink', 'deploy:config_symlinks' -after 'deploy:restart', "deploy:cleanup" +# User info +set :user, 'mezuro' + +# RVM +set :rvm_ruby_string, :local # use the same ruby as used locally for deployment +set :rvm_autolibs_flag, "read-only" # more info: rvm help autolibs +set :rvm_type, :user +set :rvm_install_with_sudo, true namespace :deploy do - task :start do ; end - task :stop do ; end + desc 'Restart application' + task :restart do + on roles(:app), in: :sequence, wait: 5 do + execute "touch #{File.join(current_path,'tmp','restart.txt')}" + end + end - task :restart, :roles => :app, :except => { :no_release => true } do - run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" + 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 - task :config_symlinks do - run "ln -s #{File.join(deploy_to, 'shared', 'config/database.yml')} #{File.join(release_path, 'config/database.yml')}" + before :compile_assets, :config_symlinks do + on roles(:web) do + execute "ln -s #{File.join(deploy_to, 'shared', 'config/database.yml')} #{File.join(release_path, 'config/database.yml')}" + end end -end \ No newline at end of file + + after :finishing, 'deploy:cleanup' + +end diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 0000000..75bcfb6 --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,42 @@ +set :stage, :production + +# 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. +#role :app, %w{mezuro.org} +#role :web, %w{mezuro.org} +#role :db, %w{mezuro.org} + +# Extended Server Syntax +# ====================== +# This can be used to drop a more detailed server +# definition into the server list. The second argument +# something that quacks like a hash can be used to set +# extended properties on the server. +server 'mezuro.org', user: 'mezuro', roles: %w{web app db} + +# you can set custom ssh options +# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options +# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start) +# set it globally +# set :ssh_options, { +# keys: %w(/home/rlisowski/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(password) +# } +# and/or per server +# 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' +# } +# setting per server overrides global ssh_options + +# fetch(:default_env).merge!(rails_env: :production) -- libgit2 0.21.2