deploy.rb 2.55 KB
Newer Older
danielgrippi's avatar
danielgrippi committed
1
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
Raphael's avatar
Raphael committed
2
#   licensed under the Affero General Public License version 3 or later.  See
Raphael's avatar
Raphael committed
3
#   the COPYRIGHT file.
4

5
set :config_yaml, YAML.load_file(File.dirname(__FILE__) + '/deploy_config.yml')
maxwell's avatar
maxwell committed
6

7
require './config/cap_colors'
8
require 'bundler/capistrano'
9 10
require './config/boot'
require 'hoptoad_notifier/capistrano'
11
set :bundle_dir, ''
Sarah Mei's avatar
Sarah Mei committed
12

13 14 15
set :stages, ['production', 'staging']
set :default_stage, 'staging'
require 'capistrano/ext/multistage'
16

17
set :application, 'diaspora'
18
set :scm, :git
Sarah Mei's avatar
Sarah Mei committed
19
set :use_sudo, false
20 21 22 23
set :scm_verbose, true
set :repository_cache, "remote_cache"
set :deploy_via, :checkout

24 25 26
# Figure out the name of the current local branch
def current_git_branch
  branch = `git symbolic-ref HEAD 2> /dev/null`.strip.gsub(/^refs\/heads\//, '')
27
  logger.info "Deploying branch #{branch}"
28 29 30
  branch
end

31
namespace :deploy do
Sarah Mei's avatar
Sarah Mei committed
32 33
  task :symlink_config_files do
    run "ln -s -f #{shared_path}/config/database.yml #{current_path}/config/database.yml"
34
    run "ln -s -f #{shared_path}/config/application.yml #{current_path}/config/application.yml"
Sarah Mei's avatar
Sarah Mei committed
35
    run "ln -s -f #{shared_path}/config/oauth_keys.yml #{current_path}/config/oauth_keys.yml"
36 37
  end

Sarah Mei's avatar
Sarah Mei committed
38 39
  task :symlink_cookie_secret do
    run "ln -s -f #{shared_path}/config/initializers/secret_token.rb #{current_path}/config/initializers/secret_token.rb"
40 41
  end

Sarah Mei's avatar
Sarah Mei committed
42 43 44
  task :bundle_static_assets do
    run "cd #{current_path} && sass --update public/stylesheets/sass:public/stylesheets"
    run "cd #{current_path} && bundle exec jammit"
Stephen Caudill's avatar
Stephen Caudill committed
45
  end
46

Sarah Mei's avatar
Sarah Mei committed
47
  task :restart do
48 49
    thins = capture "svstat /service/thin*"
    matches = thins.match(/(thin_\d+):/).captures
50 51 52

    matches.each_with_index do |thin, index|
      unless index == 0
53 54
        puts "sleeping for 20 seconds"
        sleep(20)
55 56 57 58 59 60 61 62 63 64
      end
      run "svc -t /service/#{thin}"
    end

    run "svc -t /service/resque_worker*"
  end

  task :kill do
    run "svc -k /service/thin*"
    run "svc -k /service/resque_worker*"
65 66
  end

Sarah Mei's avatar
Sarah Mei committed
67
  task :start do
68 69
    run "svc -u /service/thin*"
    run "svc -u /service/resque_worker*"
70 71 72
  end

  task :stop do
73 74
    run "svc -d /service/thin*"
    run "svc -d /service/resque_worker*"
75
  end
76 77 78 79 80 81

  desc 'Copy resque-web assets to public folder'
  task :copy_resque_assets do
    target = "#{release_path}/public/resque-jobs"
    run "cp -r `cd #{release_path} && bundle show resque`/lib/resque/server/public #{target}"
  end
82 83
end

84 85 86 87 88 89 90 91 92 93
before 'deploy:update' do
  set :branch, current_git_branch
end

after 'deploy:symlink' do
  deploy.symlink_config_files
  deploy.symlink_cookie_secret
  deploy.bundle_static_assets
  deploy.copy_resque_assets
end
94