Skip to content
Extraits de code Groupes Projets
deploy.rb 2,36 ko
Newer Older
danielgrippi's avatar
danielgrippi a validé
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
Raphael's avatar
Raphael a validé
#   licensed under the Affero General Public License version 3 or later.  See
Raphael's avatar
Raphael a validé
#   the COPYRIGHT file.
set :config_yaml, YAML.load_file(File.dirname(__FILE__) + '/deploy_config.yml')
maxwell's avatar
maxwell a validé

require 'bundler/capistrano'
set :bundle_dir, ''
Sarah Mei's avatar
Sarah Mei a validé

set :stages, ['production', 'staging']
set :default_stage, 'staging'
require 'capistrano/ext/multistage'
set :scm, :git
Sarah Mei's avatar
Sarah Mei a validé
set :use_sudo, false
set :scm_verbose, true
set :repository_cache, "remote_cache"
set :deploy_via, :checkout

# Bonus! Colors are pretty!
def red(str)
  "\e[31m#{str}\e[0m"
end

# 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\//, '')
  puts "Deploying branch #{red branch}"
  branch
end

# Set the deploy branch to the current branch
set :branch, current_git_branch

namespace :deploy do
Sarah Mei's avatar
Sarah Mei a validé
  task :symlink_config_files do
    run "ln -s -f #{shared_path}/config/database.yml #{current_path}/config/database.yml"
    run "ln -s -f #{shared_path}/config/application.yml #{current_path}/config/application.yml"
Sarah Mei's avatar
Sarah Mei a validé
    run "ln -s -f #{shared_path}/config/oauth_keys.yml #{current_path}/config/oauth_keys.yml"
Sarah Mei's avatar
Sarah Mei a validé
  task :symlink_cookie_secret do
    run "ln -s -f #{shared_path}/config/initializers/secret_token.rb #{current_path}/config/initializers/secret_token.rb"
Sarah Mei's avatar
Sarah Mei a validé
  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 a validé
  end
Sarah Mei's avatar
Sarah Mei a validé
  task :restart do
    thins = capture "svstat /service/thin*"
    matches = thins.match(/(thin_\d+):/).captures

    matches.each_with_index do |thin, index|
      unless index == 0
      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*"
Sarah Mei's avatar
Sarah Mei a validé
  task :start do
    run "svc -u /service/thin*"
    run "svc -u /service/resque_worker*"
  end

  task :stop do
    run "svc -d /service/thin*"
    run "svc -d /service/resque_worker*"
after "deploy:symlink", "deploy:symlink_config_files", "deploy:symlink_cookie_secret", "deploy:bundle_static_assets"

        require './config/boot'
        require 'hoptoad_notifier/capistrano'