Skip to content

Instantly share code, notes, and snippets.

@jmather
Forked from ed-lea/gist:3637903
Created September 5, 2012 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmather/3637959 to your computer and use it in GitHub Desktop.
Save jmather/3637959 to your computer and use it in GitHub Desktop.
# deploy.rb
#
# Multistage Deployment
#
set :stages, %w(production staging)
set :default_stage, "staging"
set :stage_dir, "app/config"
require 'capistrano/ext/multistage'
#
# SCM
#
set :user, "my-deploy-user"
set :repository, "git@github.com:ed-lea/site.me.git"
set :scm, :git
set :branch, "master"
set :deploy_via, :copy
#
# Application
#
set :model_manager, "doctrine"
set :app_path, "app"
set :shared_files, [ "app/config/parameters.ini" ]
set :shared_children, [ app_path + "/logs", web_path + "/uploads", "vendor" ]
#
# Deployment
#
set :keep_releases, 3
set :use_sudo, false
set :update_vendors, true
set :vendors_mode, "install"
set :dump_assetic_assets, true
set :cache_warmup, false
# -------
namespace :symfony do
namespace :doctrine do
namespace :migrations do
desc "Executes a migration to a specified version or the latest available version"
task :migrate, :roles => :app, :except => { :no_release => true } do
currentVersion = nil
run "sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} --no-ansi doctrine:migrations:status --env=#{symfony_env_prod}'", :once => true do |ch, stream, out|
if stream == :out and out =~ /Current Version:.+\(([\w]+)\)/
currentVersion = Regexp.last_match(1)
end
if stream == :out and out =~ /Current Version:\s*0\s*$/
currentVersion = 0
end
end
if currentVersion == nil
raise "Could not find current database migration version"
end
puts " Current database version: #{currentVersion}"
on_rollback {
if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database back to version #{currentVersion}? (y/N)")
run "sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate #{currentVersion} --env=#{symfony_env_prod} --no-interaction'", :once => true
end
}
if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database? (y/N)")
run "sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate --env=#{symfony_env_prod} --no-interaction'", :once => true
end
end
desc "Views the status of a set of migrations"
task :status, :roles => :app, :except => { :no_release => true } do
run "sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:status --env=#{symfony_env_prod}'", :once => true
end
end
end
end
# staging.rb
server 'site.me', :app, :web, :primary => true
#
# Project
#
set :application, "app-name"
set :domain, "site.me"
set :deploy_to, "/var/www/site"
#
# Deployment
#
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where Rails migrations will run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment