Created
February 18, 2014 19:20
-
-
Save PelagicDev/9077946 to your computer and use it in GitHub Desktop.
Rails Deployment using Capistrano
This file contains hidden or 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
# Application Settings | |
set :application, "your_application_name" | |
set :user, "deploy" | |
set :deploy_to, "/home/#{user}/apps/#{application}" | |
set :rails_env, "test" | |
set :keep_releases, 5 | |
# Git Settings | |
set :scm, :git | |
set :branch, 'development' | |
set :repo_url, '[email protected]...' | |
# Deploy Tasks | |
namespace :deploy do | |
desc 'Restart application' | |
task :restart do | |
on roles(:app), in: :sequence, wait: 5 do | |
# Your restart mechanism here, for example: | |
execute :touch, release_path.join('tmp/restart.txt') | |
end | |
end | |
after :publishing, :restart | |
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 | |
end | |
before "deploy:setup", "db:configure" | |
after "deploy:update_code", "db:symlink" | |
namespace :db do | |
desc "Create database yaml in shared path" | |
task :configure do | |
set :database_username do | |
'deploy' | |
end | |
set :database_password do | |
Capistrano::CLI.password_prompt "Database Password: " | |
end | |
db_config = <<-EOF | |
base: &base | |
adapter: postgresql | |
encoding: utf8 | |
reconnect: false | |
pool: 5 | |
username: #{database_username} | |
password: #{database_password} | |
development: | |
database: #{application}_development | |
<<: *base | |
test: | |
database: #{application}_test | |
<<: *base | |
production: | |
database: #{application}_production | |
<<: *base | |
EOF | |
run "mkdir -p #{shared_path}/config" | |
put db_config, "#{shared_path}/config/database.yml" | |
end | |
desc "Make symlink for database yaml" | |
task :symlink do | |
run "ln -nfs #{shared_path}/config/database.yml #{latest_release}/config/database.yml" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment