Skip to content

Commit

Permalink
Added capistrano
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Dec 9, 2011
1 parent 0b8404b commit 1089e6d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load 'deploy' if respond_to?(:namespace) # cap2 differentiator

# Uncomment if you are using Rails' asset pipeline
# load 'deploy/assets'

Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }

load 'config/deploy' # remove this line to skip loading any of the default tasks
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ gem "pg"
group :production do
gem 'unicorn'
end

group :development do
gem "capistrano"
end
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,26 @@ GEM
activeresource (2.3.8)
activesupport (= 2.3.8)
activesupport (2.3.8)
capistrano (2.9.0)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
devise (1.0.8)
warden (~> 0.10.3)
erubis (2.6.6)
abstract (>= 1.0.0)
haml (3.0.21)
highline (1.6.8)
kgio (2.6.0)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
net-ssh (2.2.1)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
pdfkit (0.4.6)
pg (0.10.1)
rack (1.1.0)
Expand All @@ -41,6 +55,7 @@ PLATFORMS
ruby

DEPENDENCIES
capistrano
devise (= 1.0.8)
erubis
haml
Expand Down
60 changes: 60 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# call with `cap -S app="<app>" deploy` to deploy to another instance.

$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Для работы rvm
require 'rvm/capistrano' # Для работы rvm
require 'bundler/capistrano' # Для работы bundler. При изменении гемов bundler автоматически обновит все гемы на сервере, чтобы они в точности соответствовали гемам разработчика.

ssh_options[:forward_agent] = true # Используем локальные ключи, а не ключи сервера
default_run_options[:pty] = true # Для того, чтобы можно было вводить пароль

set :application, "taurus"
set :rails_env, "production"
set :domain, "[email protected]" # Это необходимо для деплоя через ssh.

# Prevents error if not parameter passed, assumes that default 'cap deploy'
# command should deploy default application instance
set(:app, application) unless exists?(:app)
unless app.nil?
set :deploy_to, "/srv/#{app}"
else
set :deploy_to, "/srv/#{application}"
end

set :use_sudo, false
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"

set :rvm_ruby_string, 'ree@taurus' # Это указание на то, какой Ruby интерпретатор мы будем использовать.
set :rvm_type, :user # Указывает на то, что мы будем использовать rvm, установленный у пользователя, от которого происходит деплой, а не системный rvm.

set :scm, :git
set :repository, "[email protected]:AmurSU/taurus.git" # Путь до вашего репозитария. Кстати, забор кода с него происходит уже не от вас, а от сервера, поэтому стоит создать пару rsa ключей на сервере и добавить их в deployment keys в настройках репозитария.
set :branch, "master" # Ветка из которой будем тянуть код для деплоя.
set :deploy_via, :remote_cache # Указание на то, что стоит хранить кеш репозитария локально и с каждым деплоем лишь подтягивать произведенные изменения. Очень актуально для больших и тяжелых репозитариев.

role :web, domain
role :app, domain
role :db, domain, :primary => true

after 'deploy:update_code', :roles => :app do
# Конфиги. Их не трогаем!
run "rm -f #{current_release}/config/database.yml"
run "ln -s #{deploy_to}/shared/config/database.yml #{current_release}/config/database.yml"

run "rm -f #{current_release}/config/taurus.yml"
run "ln -s #{deploy_to}/shared/config/taurus.yml #{current_release}/config/taurus.yml"
end

# Далее идут правила для перезапуска unicorn.
# В случае с Rails 3 приложениями стоит заменять bundle exec unicorn_rails на bundle exec unicorn
namespace :deploy do
task :restart do
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn_rails -c #{unicorn_conf} -E #{rails_env} -D; fi"
end
task :start do
run "bundle exec unicorn_rails -c #{unicorn_conf} -E #{rails_env} -D"
end
task :stop do
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
end
end

0 comments on commit 1089e6d

Please sign in to comment.