Commit d26dabf62e9774f8b5e83d043551c203bef18362

Authored by ivanvr
1 parent e5875d94
Exists in master and in 1 other branch production

Customizable deploy.rb through config.yml

Showing 2 changed files with 73 additions and 1 deletions   Show diff stats
.gitignore
... ... @@ -4,7 +4,6 @@ log/*.log
4 4 tmp/**/*
5 5 tmp/*
6 6 config/config.yml
7   -config/deploy.rb
8 7 config/deploy
9 8 config/mongoid.yml
10 9 config/newrelic.yml
... ...
config/deploy.rb 0 → 100644
... ... @@ -0,0 +1,73 @@
  1 +# Deploy Config
  2 +# =============
  3 +#
  4 +# Copy this file to config/deploy.rb and customize it as needed.
  5 +# Then run `cap deploy:setup` to set up your server and finally
  6 +# `cap deploy` whenever you would like to deploy Errbit. Refer
  7 +# to the Readme for more information.
  8 +
  9 +config = YAML.load_file('config/config.yml')['deployment']
  10 +
  11 +require 'bundler/capistrano'
  12 +
  13 +set :application, "errbit"
  14 +set :repository, config['repository']
  15 +
  16 +role :web, config['hosts']['web']
  17 +role :app, config['hosts']['app']
  18 +role :db, config['hosts']['db'], :primary => true
  19 +
  20 +set :user, config['user']
  21 +set :use_sudo, false
  22 +# if config.has_key?('ssh_key')
  23 + set :ssh_options, { :forward_agent => true, :keys => [ config['ssh_key'] ] }
  24 +# else
  25 + # set :ssh_options, { :forward_agent => true }
  26 +# end
  27 +default_run_options[:pty] = true
  28 +
  29 +set :deploy_to, config['deploy_to']
  30 +set :deploy_via, :remote_cache
  31 +set :copy_cache, true
  32 +set :copy_exclude, [".git"]
  33 +set :copy_compression, :bz2
  34 +
  35 +set :scm, :git
  36 +set :scm_verbose, true
  37 +set(:current_branch) { `git branch`.match(/\* (\S+)\s/m)[1] || raise("Couldn't determine current branch") }
  38 +set :branch, defer { current_branch }
  39 +
  40 +after 'deploy:update_code', 'errbit:symlink_configs'
  41 +
  42 +namespace :deploy do
  43 + task :start do ; end
  44 + task :stop do ; end
  45 + task :restart, :roles => :app, :except => { :no_release => true } do
  46 + run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  47 + end
  48 +end
  49 +
  50 +namespace :errbit do
  51 + task :setup_configs do
  52 + shared_configs = File.join(shared_path,'config')
  53 + run "mkdir -p #{shared_configs}"
  54 + run "if [ ! -f #{shared_configs}/config.yml ]; then cp #{latest_release}/config/config.example.yml #{shared_configs}/config.yml; fi"
  55 + run "if [ ! -f #{shared_configs}/mongoid.yml ]; then cp #{latest_release}/config/mongoid.example.yml #{shared_configs}/mongoid.yml; fi"
  56 + end
  57 +
  58 + task :symlink_configs do
  59 + errbit.setup_configs
  60 + shared_configs = File.join(shared_path,'config')
  61 + release_configs = File.join(release_path,'config')
  62 + run("ln -nfs #{shared_configs}/config.yml #{release_configs}/config.yml")
  63 + run("ln -nfs #{shared_configs}/mongoid.yml #{release_configs}/mongoid.yml")
  64 + end
  65 +end
  66 +
  67 +namespace :db do
  68 + desc "Create the indexes defined on your mongoid models"
  69 + task :create_mongoid_indexes do
  70 + run "cd #{current_path} && bundle exec rake db:mongoid:create_indexes"
  71 + end
  72 +end
  73 +
... ...