Created
November 25, 2013 17:04
-
-
Save Olefine/7644695 to your computer and use it in GitHub Desktop.
some deploy from legacy project
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
# Automatically precompile assets | |
load "deploy/assets" | |
# Execute "bundle install" after deploy, but only when really needed | |
require "bundler/capistrano" | |
# RVM integration | |
require "rvm/capistrano" | |
set :application, "app name" | |
set :rails_env, :production | |
set :domain, "your domain" | |
set :use_sudo, false | |
set :rvm_ruby_string, 'rvmrc' | |
set :rvm_type, :user | |
set :hostingserver, "server" | |
set :user, "user on server" | |
set :port, 22 | |
set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names | |
set :repository, "your git repository" | |
set :branch, "branch from deploy" | |
set :bundle_without, [:darwin, :development, :test] | |
# Deploy via github | |
set :deploy_via, :remote_cache | |
set :deploy_to, "deploy folder" | |
set :shared_files, %w(config/database.yml config/config.yml public/uploads) | |
role :web, hostingserver # Your HTTP server, Apache/etc | |
role :app, hostingserver # This may be the same as your `Web` server | |
role :db, hostingserver, :primary => true # This is where Rails migrations will run | |
#role :db, "your slave db-server here" # No slave at this moment | |
# Install RVM and Ruby before deploy | |
before "deploy:setup", "rvm:install_rvm" | |
before "deploy:setup", "rvm:install_ruby" | |
after "deploy:setup", "deploy:set_rvm_version" | |
after "deploy:finalize_update", "deploy:update_shared_symlinks" | |
after "deploy", "deploy:migrate" | |
# Unicorn config | |
set :unicorn_config, "#{current_path}/config/unicorn.rb" | |
set :unicorn_binary, "bash -c 'bundle exec unicorn_rails -c #{unicorn_config} -E #{rails_env} -D'" | |
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid" | |
namespace :deploy do | |
task :start, :roles => :app, :except => { :no_release => true } do | |
# Start unicorn server using sudo (rails) | |
run "cd #{current_path} && #{unicorn_binary}" | |
end | |
task :stop, :roles => :app, :except => { :no_release => true } do | |
run "if [ -f #{unicorn_pid} ]; then kill `cat #{unicorn_pid}`; fi" | |
end | |
task :graceful_stop, :roles => :app, :except => { :no_release => true } do | |
run "if [ -f #{unicorn_pid} ]; then kill -s QUIT `cat #{unicorn_pid}`; fi" | |
end | |
task :reload, :roles => :app, :except => { :no_release => true } do | |
run "if [ -f #{unicorn_pid} ]; then kill -s USR2 `cat #{unicorn_pid}`; fi" | |
end | |
task :restart, :roles => :app, :except => { :no_release => true } do | |
stop | |
start | |
end | |
task :set_rvm_version, :roles => :app, :except => { :no_release => true } do | |
run "rvm use #{rvm_ruby_string}" | |
end | |
task :update_shared_symlinks do | |
shared_files.each do |path| | |
run "ln -nfs #{File.join(deploy_to, "shared", path)} #{File.join(release_path, path)}" | |
end | |
end | |
desc "reload the database with seed data" | |
task :seed do | |
run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}" | |
end | |
# Precompile assets only when needed | |
namespace :assets do | |
task :precompile, :roles => :web, :except => { :no_release => true } do | |
# If this is our first deploy - don't check for the previous version | |
if remote_file_exists?(current_path) | |
from = source.next_revision(current_revision) | |
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0 | |
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile} | |
else | |
logger.info "Skipping asset pre-compilation because there were no asset changes" | |
end | |
else | |
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile} | |
end | |
end | |
end | |
end | |
# Helper function | |
def remote_file_exists?(full_path) | |
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip | |
end | |
desc "tail production log files" | |
task :tail_logs, :roles => :app do | |
run "tail -f #{shared_path}/log/production.log" do |channel, stream, data| | |
trap("INT") { puts 'Interupted'; exit 0; } | |
puts # for an extra line break before the host name | |
puts "#{channel[:host]}: #{data}" | |
break if stream == :err | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment