Skip to content

Instantly share code, notes, and snippets.

@ngw

ngw/deploy.rb Secret

Created April 28, 2016 15:39
Show Gist options
  • Save ngw/3472dc3a2fac385da3f9c616a8f5a7a8 to your computer and use it in GitHub Desktop.
Save ngw/3472dc3a2fac385da3f9c616a8f5a7a8 to your computer and use it in GitHub Desktop.
# config valid only for current version of Capistrano
set :deploy_to, '/home/deployer/apps/braint'
set :user, 'deployer'
set :scm, :git
set :format, :pretty
set :log_level, :debug
set :keep_releases, 3
set :rvm_ruby_version, '2.2.3@braint'
set :nvm_type, :user
set :nvm_node, 'v6.0.0'
set :nvm_map_bins, %w{node npm bower}
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
namespace :braint do
task :doc do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, 'doc:v1'
end
end
end
end
end
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc "Upload config file"
task :upload_config_file do
on release_roles :all do
within shared_path do
fetch(:linked_files).each do |config_file|
if File.exists?(config_file)
unless test "[ -f #{File.join(shared_path, config_file)} ]"
info "Uploading config #{config_file}"
upload! StringIO.new(IO.read(config_file)), File.join(shared_path, config_file)
else
info "Config #{config_file} already exists"
end
else
info "#{config_file} doesn't exist"
end
end
end
end
end
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
after :finishing, 'braint:doc'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment