-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.rb
123 lines (98 loc) · 3.49 KB
/
deploy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# config valid only for Capistrano 3.1
lock '3.16.0'
# Added by the airbrake gem
# (appended after running: rails generate airbrake)
require './config/boot'
require 'airbrake/capistrano3'
set :application, 'BikeBinder'
set :repo_url, 'https://github.com/FreeRidePGH/BikeBinder.git'
set :branch, :master
set :rails_env, 'shared_host'
# set :assets_roles, [:web]
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
# Default deploy_to directory is /var/www/my_app
# set :deploy_to, '/var/www/my_app'
# Set this in the production/staging file (WW)
# Default value for :scm is :git
set :scm, :git
set :use_sudo, false
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
set :pty, false
# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for default_env is {}
# set :default_env, { path: "/#{ENV['HOME']}/.rvm/bin:$PATH"}
# Default value for keep_releases is 5
set :keep_releases, 5
# Default value for :linked_files is []
set(:linked_files,
%w(config/database.yml
config/application/mailer_config.rb
config/application/secret_base.txt
config/application/secret_token.txt
config/env_vals.rb
config/application/err_api_key.txt
))
# which config files should be copied by deploy:setup_config
# see documentation in lib/capistrano/tasks/setup_config.rake
# for details of operations
#
# Setup by running
# cap <stage> deploy:setup_config
set(:config_files,
[
['database.example.yml', 'config/database.yml'],
['mailer_config.sample.rb','config/application/mailer_config.rb'],
['secret_base.txt','config/application/secret_base.txt'],
['secret_token.txt', 'config/application/secret_token.txt'],
['err_api_key.txt', 'config/application/err_api_key.txt'],
['env_vals.rb', 'config/env_vals.rb']
])
namespace :deploy do
desc 'Take a backup of the app content'
task :auto_backup => [:set_rails_env] do
if fetch(:stage).to_s == 'production'
on roles(:app) do
within "/home/#{host.user}/ops/Backup" do
with rails_env: fetch(:rails_env) do
execute :bundle, :exec, :backup,
:perform, '--trigger', 'DH_frpgh', '--root-path', './'
end # with rails_env
end # within ~/Backup
end # on roles
else
warn " Auto backups only performed on production deploy"
end # if stage=='production'
end # task
before :started, :auto_backup
after :updated, :setup_shared_host
desc 'Restart application'
task :restart => [:set_rails_env] do
on roles(:app), in: :sequence, wait: 5 do |host|
if fetch(:rails_env) == 'shared_host'
capture(:echo, '$USER')
# ps x | grep .*#{fetch(:deploy_to)}/.*\dispatch_fcgi.rb | awk '!/grep/ {print$1}' | xargs -i kill {}
pattern_str = ".*#{fetch(:deploy_to)}/.*\.rb"
execute(:ps, 'x', '|',
:grep, pattern_str, '|',
:awk, "\'!/grep/ {print$1}\'", '|',
:xargs, '-i', 'kill', '{}')
end
end # on roles
end # task
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
after 'deploy:finished', 'airbrake:deploy'