Last active
October 5, 2016 02:02
-
-
Save taka-oyama/a78a3a1221731bc2ce6c to your computer and use it in GitHub Desktop.
Capistrano 3 Sample for Deploying to Development
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
require 'capistrano/setup' | |
require 'capistrano/deploy' | |
require 'capistrano/rvm' | |
require 'capistrano/bundler' | |
#require 'capistrano/rails/assets' | |
require 'capistrano/rails/migrations' | |
require 'capistrano3/unicorn' | |
require 'whenever/capistrano' | |
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined. | |
Dir.glob('lib/capistrano/tasks/*.rake').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
lock '3.4.0' | |
set :application, "jellyserver" | |
set :repo_url, "ssh://git@gitlab.dev.playnext.co.jp:10022/jelly/jellyserver.git" | |
set :branch, fetch(:stage) | |
set :deploy_to, "/u/apps/jellyserver" | |
set :keep_releases, 1 | |
set :linked_files, [".env", "config/database.yml", "config/shards.yml", "config/sockets.yml"] | |
set :linked_dirs, ["log", "public", "tmp/pids", "tmp/sockets", "tmp/persistent"] | |
# SSH Config | |
set :default_env, { | |
:LANG => 'en_US.UTF-8', | |
} | |
# Rails config | |
set :rails_env, fetch(:stage) | |
set :migration_role, :ctr | |
set :conditionally_migrate, true | |
# Bundler config | |
set :bundle_path, -> { shared_path.join("vendor", "bundle") } | |
set :bundle_binstubs, -> { shared_path.join("bin") } | |
set :bundle_without, (["development", "test", "production"] - [fetch(:stage).to_s]).join(" ") | |
set :bundle_flags, "--deployment" | |
# Unicorn config | |
set :unicorn_roles, [:ctr, :ap] | |
set :unicorn_pid, -> { shared_path.join("tmp", "pids", "unicorn.pid") } | |
set :unicorn_config_path, -> { current_path.join("config", "unicorn", "#{fetch(:stage).to_s}.rb") } | |
# Whenever config | |
set :whenever_roles, :ctr | |
set :whenever_environment, fetch(:stage).to_s | |
set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" } | |
namespace :deploy do | |
task :restart do | |
invoke "unicorn:restart" | |
on roles(fetch(:unicorn_roles)) do | |
upload! StringIO.new(`git log -n10 --pretty=format:'%ci|%h|%an|%s|%d'`), "#{release_path}/log/recent_commits.log" | |
end | |
end | |
after :publishing, :restart | |
desc "remove active-admin" | |
task :remove_active_admin do | |
on roles(:ap) do | |
within release_path do | |
execute "rm -r #{release_path}/app/admin" | |
end | |
end | |
end | |
after :publishing, :remove_active_admin | |
desc "Automatically create git tag #{fetch(:stage).to_s} and push to remote." | |
task :add_tag do | |
on roles(:ctr) do | |
system [ | |
"git checkout --quiet #{fetch(:branch).to_s}", | |
"git pull --quiet", | |
"git tag --force deployed_#{fetch(:stage).to_s} #{fetch(:branch).to_s}", | |
"git push --force origin deployed_#{fetch(:stage).to_s}" | |
].join(" && ") | |
end | |
end | |
after :finished, :add_tag | |
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 :maintenance do | |
desc "Maintenance start (edit config/maintenance.yml to provide parameters)" | |
task :start do | |
on roles(:all) do | |
upload! "config/maintenance.yml", "#{current_path}/tmp/maintenance.yml" | |
end | |
end | |
desc "Maintenance stop" | |
task :stop do | |
on roles(:all) do | |
execute "rm #{current_path}/tmp/maintenance.yml" | |
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
before_exec do |server| | |
ENV['BUNDLE_GEMFILE'] = "/u/apps/<applicaton_name>/current/Gemfile" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment