Skip to content

Instantly share code, notes, and snippets.

@btoone
Created August 17, 2011 14:48
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save btoone/1151665 to your computer and use it in GitHub Desktop.
Save btoone/1151665 to your computer and use it in GitHub Desktop.
Example Capistrano configuration for multi stage deployment
# app/config/deploy.rb
# Most of the changes specific to your environment will be set in
# the `app/config/deploy/[env].rb` files.
# define multiple deployments
set :stages, %w(production staging)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
require 'bundler/capistrano'
# git
set :scm, :git
set :repository, "git@github.com:username/repo.git"
set :branch, "master"
set :deploy_via, :remote_cache # fetches from local git repo on the server rather then clone repo on each deploy
# server env
set :user, "deploy" # the name of the deployment user-account on the server
set :keep_releases, 3
set :use_sudo, false # disable sudo since the deploy user does not have sudo rights
# ssh connection
# default_run_options[:pty] = true # prompts for key passphrase, required when you're not using :forward_agent
set :ssh_options, {
:keys => [File.join(ENV["HOME"], ".ssh", "decwise", "deploy")], # specify the key to use when connecting to the deployment server
:forward_agent => true, # forward agent so deployment server can connect to github
:port => 35275
}
# deployment process
after "deploy:update", "passenger:setup_symlinks"
# tasks
namespace :passenger do
desc "Creates a symlink for the database.yml file"
task :setup_symlinks, :roles => :app do
puts "\n\n=== Setting up symbolic links ===\n\n"
run "ln -s #{deploy_to}/#{shared_dir}/config/database.yml #{current_path}/config/database.yml"
end
end
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
# app/config/deploy/production.rb
set :application, "app.example.com" # the name of your website - should also be the name of the directory
set :deploy_to, "/var/www/sites/#{application}" # the path to your new deployment directory on the server - by default, the name of the application (e.g. "/var/www/sites/example.com")
set :rails_env, "production" # tells cap to run migrations using staging env
# Define server roles; if using a single server you can define inline
# role :web, "#{application}"
# role :app, "#{application}"
# role :db, "#{application}", :primary => true
server "#{application}", :web, :app, :db, :primary => true
# app/config/deploy/staging.rb
set :application, "stage.app.example.com" # the name of your website - should also be the name of the directory
set :deploy_to, "/var/www/sites/stage.#{application}" # the path to your new deployment directory on the server - by default, the name of the application (e.g. "/var/www/sites/example.com")
set :rails_env, "staging" # tells cap to run migrations using staging env
# Define server roles; if using a single server you can define inline
# role :web, "#{application}"
# role :app, "#{application}"
# role :db, "#{application}", :primary => true
server "#{application}", :web, :app, :db, :primary => true
@migueldiganchi
Copy link

Hello! What about the database configuration? I suppose that I need to create another database in server right? Sorry about make my question here. I am not finding a topic that covers my doubt.

@kalelc
Copy link

kalelc commented Oct 9, 2018

hello @migueldiganchi.

Remember that this script is only to deploys, the database should is configured before. If you need you run the migration to can adds a custom task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment