Last active
August 29, 2015 13:57
-
-
Save alChaCC/9798590 to your computer and use it in GitHub Desktop.
Transfer from Capistrano 2 to Capistrano 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load DSL and Setup Up Stages | |
require 'capistrano/setup' | |
# Includes default deployment tasks | |
require 'capistrano/deploy' | |
require 'capistrano/rvm' | |
require 'capistrano/bundler' | |
require 'capistrano/rails/assets' | |
require 'capistrano/rails/migrations' | |
require "whenever/capistrano" | |
require 'capistrano/sidekiq' | |
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined. | |
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config valid only for Capistrano 3.1 | |
lock '3.1.0' | |
set :application, "CoolApplication" | |
set :repository, "your@git.location" | |
set :sidekiq_role, :sidekiqer | |
set :rvm_ruby_version, '2.0.0-p247@global' | |
set :linked_files, %w{config/database.yml config/application.yml} | |
set :linked_dirs, %w{public/uploads public/blog} | |
set :ssh_options, { :forward_agent => true } | |
namespace :deploy do | |
after :publishing, :restart | |
after 'deploy:assets:precompile', 'deploy:assets:sync' | |
after :finishing, 'deploy:cleanup' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem "capistrano-rails" | |
gem "capistrano-sidekiq" | |
gem 'capistrano-rvm' | |
gem 'capistrano-bundler' | |
gem 'whenever','~> 0.9.0' , require: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :branch, 'develop' | |
set :user, 'stage_deployer' | |
set :domain, 'staging.your.domain' | |
set :rails_env, "staging" | |
set :deploy_to, "/home/#{fetch(:user)}/urbox" | |
set :sidekiq_pid, File.join("#{shared_path}", 'pids', 'sidekiq.pid') | |
set :stage, :staging | |
server "#{fetch(:domain)}", user: "#{fetch(:user)}", roles: %w{web app db asset_syncer sidekiqer} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load 'deploy' | |
# Uncomment if you are using Rails' asset pipeline | |
load 'deploy/assets' | |
load 'config/deploy' # remove this line to skip loading any of the default tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :whenever_command, "bundle exec whenever" | |
set :assets_role, [:web, :shadow, :asset_syncer, :sidekiqer] | |
begin | |
require 'capistrano_colors' | |
rescue LoadError | |
puts "`gem install capistrano_colors` to get output more userfriendly." | |
end | |
set :rvm_type, :system | |
require "rvm/capistrano" | |
require 'capistrano/ext/multistage' | |
set :stages, %w(production staging) | |
set :default_stage, "staging" | |
require 'bundler/capistrano' | |
require "whenever/capistrano" | |
set :application, "cool application name" | |
set :repository, "your@git.location" | |
set :ssh_options, { :forward_agent => true } | |
set :scm, :git | |
set :deploy_via, :copy | |
set :git_shallow_clone, 1 | |
set :scm_verbose, true | |
set :use_sudo, false | |
set :symlink_paths, ['config/database.yml', 'config/application.yml'] | |
# from https://github.com/AF83/capistrano-af83/blob/master/lib/capistrano/af83/deploy/assets.rb | |
set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb) | |
namespace :deploy do | |
desc "Restart passenger process" | |
task :restart, :roles => [:web], :except => { :no_release => true } do | |
run "touch #{current_path}/tmp/restart.txt" | |
end | |
task :symlink_files do | |
symlink_paths.each do |path| | |
run "ln -sf #{shared_path}/#{path} #{release_path}/#{path}" | |
end | |
end | |
namespace :assets do | |
task :sync, :roles => [:asset_syncer] do # you must set "shadow" server role | |
run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:sync" | |
end | |
end | |
end | |
namespace :remote_rake do | |
desc "Run a task on remote servers, ex: cap staging remote_rake:invoke task=cache:clear" | |
task :invoke do | |
run "cd #{deploy_to}/current; RAILS_ENV=#{rails_env} bundle exec rake #{ENV['task']}" | |
end | |
end | |
# cap staging tail_log | |
task :tail_log, :roles => :app do | |
run "tail -f -n 100 #{shared_path}/log/#{rails_env}.log" | |
end | |
after "deploy:finalize_update", "deploy:symlink_files" | |
after "deploy", "deploy:cleanup" | |
after "deploy:assets:precompile", "deploy:assets:sync" | |
set :sidekiq_cmd, "bundle exec sidekiq" | |
set :sidekiqctl_cmd, "bundle exec sidekiqctl" | |
set :sidekiq_role, :sidekiqer | |
require 'sidekiq/capistrano' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'capistrano' | |
gem 'capistrano-ext' | |
gem 'capistrano_colors' | |
gem 'rvm-capistrano' | |
gem 'whenever', require: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :branch, 'develop' | |
set :user, 'stage_deployer' | |
set :domain, 'staging.your.domain' | |
set :rails_env, "staging" | |
set :deploy_to, "/home/#{user}/#{application}" | |
server "#{domain}", :web, :app, :db, :asset_syncer, :sidekiqer, :primary => true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
desc "Restart passenger process" | |
task :restart do | |
on roles(:web), in: :sequence, wait: 5 do | |
execute "touch", "#{release_path}/tmp/restart.txt" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
namespace :assets do | |
desc "Synchronize assets to S3" | |
task :sync do | |
on roles(:asset_syncer) do |role| | |
within "#{release_path}"do | |
with rails_env: "#{fetch(:rails_env)}" do | |
execute :rake, "assets:sync" | |
end | |
end | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment