Skip to content

Instantly share code, notes, and snippets.

@zires
Forked from reu/deploy.rb
Created October 23, 2013 02:46
Show Gist options
  • Save zires/7111806 to your computer and use it in GitHub Desktop.
Save zires/7111806 to your computer and use it in GitHub Desktop.
# Bundler Integration
require "bundler/capistrano"
# Application Settings
set :application, "yourapplicationname"
set :user, "serveruser"
set :deploy_to, "/home/#{user}/rails-applications/#{application}"
set :rails_env, "production"
set :use_sudo, false
set :keep_releases, 3
# Git Settings
set :scm, :git
set :branch, "master"
set :repository, "[email protected]..."
set :deploy_via, :remote_cache
# Uses local instead of remote server keys, good for github ssh key deploy.
ssh_options[:forward_agent] = true
# Server Roles
role :web, "127.0.0.1"
role :app, "127.0.0.1"
role :db, "127.0.0.1", :primary => true
# Passenger Deploy Reconfigure
namespace :deploy do
desc "Restart passenger process"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} does nothing for passenger"
task t, :roles => :app do ; 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
"rails"
end
set :database_password do
Capistrano::CLI.password_prompt "Database Password: "
end
db_config = <<-EOF
base: &base
adapter: mysql2
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
# Bundler Integration
require "bundler/capistrano"
# Application Settings
set :application, "yourapplicationname"
set :user, "serveruser"
set :deploy_to, "/home/#{user}/rails-applications/#{application}"
set :rails_env, "production"
set :use_sudo, false
set :keep_releases, 3
# Git Settings
set :scm, :git
set :branch, "master"
set :repository, "[email protected]..."
set :deploy_via, :remote_cache
# Uses local instead of remote server keys, good for github ssh key deploy.
ssh_options[:forward_agent] = true
# Server Roles
role :web, "127.0.0.1"
role :app, "127.0.0.1"
role :db, "127.0.0.1", :primary => true
# Passenger Deploy Reconfigure
namespace :deploy do
desc "Restart passenger process"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} does nothing for passenger"
task t, :roles => :app do ; 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
"rails"
end
set :database_password do
Capistrano::CLI.password_prompt "Database Password: "
end
db_config = <<-EOF
base: &base
adapter: mysql
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
namespace :s3 do
desc "Create s3 config yaml in shared path"
task :configure do
set :s3_bucket do
"lolwuts"
end
set :access_key_id do
Capistrano::CLI.password_prompt "Enter your amazon s3 access key id: "
end
set :secret_access_key do
Capistrano::CLI.password_prompt "Enter your amazon s3 secret access key: "
end
s3_config = <<-EOF
production:
access_key_id: #{access_key_id}
secret_access_key: #{secret_access_key}
bucket: #{s3_bucket}
EOF
run "mkdir -p #{shared_path}/config"
put s3_config, "#{shared_path}/config/s3.yml"
end
desc "Make symlink for s3 yaml"
task :symlink do
run "ln -nfs #{shared_path}/config/s3.yml #{latest_release}/config/s3.yml"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment