Skip to content

Instantly share code, notes, and snippets.

@BobNisco
Created February 14, 2014 20:26
Show Gist options
  • Save BobNisco/9008577 to your computer and use it in GitHub Desktop.
Save BobNisco/9008577 to your computer and use it in GitHub Desktop.
Capistrano 3.1 + Rails 4 + RVM Simple Single-Stage Configuration
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
#
require 'capistrano/rvm'
# We're going to use the full capistrano/rails since
# it includes the asset compilation, DB migrations
# and bundler
require 'capistrano/rails'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
# require 'capistrano/bundler'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
# Ensure that bundle is used for rake tasks
SSHKit.config.command_map[:rake] = "bundle exec rake"
# config valid only for Capistrano 3.1
lock '3.1.0'
set :repo_url, 'YOUR_REPO_URL'
set :branch, "master"
set :deploy_via, :remote_cache
set :application, "YOUR-APPLICATION-NAME"
# We are only going to use a single stage: production
set :stages, ["production"]
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/var/www/YOUR_APP_PATH'
# Default value for :scm is :git
# set :scm, :git
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
# set :linked_files, %w{config/database.yml}
# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
set :keep_releases, 5
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Restarts Phusion Passenger
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
# Gemfile
###############################################################
# NOTE: This is not a complete Gemfile. This only includes the
# necessary tweaks for a Capistrano 3 and Phusion
# Passenger deployment setup with rvm
###############################################################
# Be sure to include rake in your Gemfile
gem 'rake'
# Use Capistrano for deployment
gem 'capistrano', '~> 3.0', require: false, group: :development
gem 'capistrano-rvm'
group :development do
gem 'capistrano-rails', '~> 1.1', require: false
gem 'capistrano-bundler', '~> 1.1', require: false
end
# For a simple environment like we have, our app, web, and db are all on a single server
server "YOUR_SERVER_IP", user: 'YOUR_DEPLOY_USER', roles: %w{app web db}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment