-
Notifications
You must be signed in to change notification settings - Fork 19
/
deploy.rb.sample
289 lines (252 loc) · 8.6 KB
/
deploy.rb.sample
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
# repository - Git repo to clone from. (needed by mina/git)
# branch - Branch name to deploy. (needed by mina/git)
# alpha branch, all interfaces unified
set :domain, 'registry'
set :deploy_to, '$HOME/registry'
set :repository, 'https://github.com/domify/registry' # dev repo
set :branch, 'master'
set :rails_env, 'alpha'
set :cron_group, 'registry'
# alpha branch, only use for heavy debugging
task :epp do
set :domain, 'registry'
set :deploy_to, '$HOME/epp'
set :repository, 'https://github.com/domify/registry' # dev repo
set :branch, 'master'
set :rails_env, 'alpha'
end
# alpha branch, only use for heavy debugging
task :registrar do
set :domain, 'registry'
set :deploy_to, '$HOME/registrar'
set :repository, 'https://github.com/domify/registry' # dev repo
set :branch, 'master'
set :rails_env, 'alpha'
set :cron_group, 'registrar'
end
# alpha branch, only use for heavy debugging
task :registrant do
set :domain, 'registryt'
set :deploy_to, '$HOME/registrant'
set :repository, 'https://github.com/domify/registry' # dev repo
set :branch, 'master'
set :rails_env, 'alpha'
set :cron_group, 'registrant'
end
# staging
task :st do
set :domain, 'registry-st'
set :deploy_to, '$HOME/registry'
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'staging'
set :rails_env, 'staging'
end
# staging
task :eppst do
set :domain, 'epp-st'
set :deploy_to, '$HOME/epp'
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'staging'
set :rails_env, 'staging'
set :cron_group, 'epp'
end
# staging
task :registrarst do
set :domain, 'registrar-st'
set :deploy_to, '$HOME/registrar'
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'staging'
set :rails_env, 'staging'
set :cron_group, 'registrar'
end
# staging
task :registrantst do
set :domain, 'registrant-st'
set :deploy_to, '$HOME/registrant'
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'staging'
set :rails_env, 'staging'
set :cron_group, 'registrant'
end
# production
task :pr do
set :domain, 'registry'
set :deploy_to, '$HOME/registry'
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'master'
set :rails_env, 'production'
end
# production
task :epppr do
set :domain, 'epp'
set :deploy_to, '$HOME/epp'
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'master'
set :rails_env, 'production'
set :cron_group, 'epp'
end
# production
task :registrarpr do
set :domain, 'registrar'
set :deploy_to, '$HOME/registrar'
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'master'
set :rails_env, 'production'
set :cron_group, 'registrar'
end
# production
task :registrantpr do
set :domain, 'registrant'
set :deploy_to, '$HOME/registrant'
set :repository, 'https://github.com/internetee/registry' # production repo
set :branch, 'master'
set :rails_env, 'production'
set :cron_group, 'registrant'
end
# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
# They will be linked in the 'deploy:link_shared_paths' step.
set :shared_paths, [
'config/application.yml',
'config/database.yml',
'config/initializers/current_commit_hash.rb',
'log',
'public/system',
'public/assets',
'export/zonefiles',
'import/bank_statements',
'import/legal_documents',
'tmp/pids'
]
# Optional settings:
# set :user, 'foobar' # Username in the server to SSH to.
# set :port, '30000' # SSH port number.
# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :environment do
# Be sure to commit your .ruby-version to your repository.
invoke :'rbenv:load'
end
# Put any custom mkdir's in here for when `mina setup` is ran.
# For Rails apps, we'll make some of the shared paths that are shared between
# all releases.
task setup: :environment do
queue! %(mkdir -p "#{deploy_to}/shared/log")
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/log")
queue! %(mkdir -p "#{deploy_to}/shared/config")
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/config")
queue! %(mkdir -p "#{deploy_to}/shared/config/initializers")
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/config/initializers")
queue! %(mkdir -p "#{deploy_to}/shared/public")
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/public")
queue! %(mkdir -p "#{deploy_to}/shared/public/system")
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/public/system")
queue! %(mkdir -p "#{deploy_to}/shared/public/assets")
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/public/assets")
queue! %(mkdir -p "#{deploy_to}/shared/export/zonefiles")
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/export/zonefiles")
queue! %(mkdir -p "#{deploy_to}/shared/import/bank_statements")
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/import/bank_statements")
queue! %(mkdir -p "#{deploy_to}/shared/import/legal_documents")
queue! %(chmod g+rx,u+rwx "#{deploy_to}/shared/import/legal_documents")
queue! %(touch "#{deploy_to}/shared/config/database.yml")
deploy do
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
to :launch do
queue! 'gem install bundler'
invoke :'bundle:install'
queue %(echo '\n NB! Please edit 'shared/config/database.yml'\n')
end
end
end
desc 'Deploys the current version to the server.'
task deploy: :environment do
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :load_commit_hash
# TEMP until all servers are updated
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'data_migration'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
to :launch do
invoke :restart
invoke :'deploy:cleanup'
invoke :que_restart if que_restart
end
end
end
# data_migrate=some_data_migration mina deploy env
desc 'Run data migrations if any set with ENV[data_migrate]'
task data_migration: :environment do
if ENV['data_migrate']
queue! %(echo "Running data migration #{ENV['data_migrate']}")
queue! %[cd #{current}]
queue! %[bundle exec rake data_migrations:#{ENV['data_migrate']} RAILS_ENV=#{rails_env}]
else
puts "No data migration specified"
end
end
desc 'Loads current commit hash'
task load_commit_hash: :environment do
queue! %(
echo "CURRENT_COMMIT_HASH = '$(git --git-dir #{deploy_to}/scm rev-parse --short #{branch})'" > \
#{deploy_to}/shared/config/initializers/current_commit_hash.rb
)
end
desc 'Restart Passenger application'
task restart: :environment do
queue "mkdir -p #{deploy_to}/current/tmp; touch #{deploy_to}/current/tmp/restart.txt"
end
namespace :cron do
desc 'Setup cron tasks.'
task setup: :environment do
invoke :'rbenv:load'
invoke :'whenever:update'
end
desc 'Clear cron tasks.'
task clear: :environment do
invoke :'rbenv:load'
invoke :'whenever:clear'
end
end
namespace :whenever do
name = -> { "#{domain}_#{rails_env}" }
desc "Clear crontab"
task clear: :environment do
queue %(
echo "-----> Clear crontab for #{name.call}"
#{echo_cmd %(cd #{deploy_to!}/#{current_path!} ; #{bundle_bin} exec whenever --clear-crontab #{name.call} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}&cron_group=#{cron_group}')}
)
end
desc "Update crontab"
task update: :environment do
queue %(
echo "-----> Update crontab for #{name.call}"
#{echo_cmd %(cd #{deploy_to!}/#{current_path!} ; #{bundle_bin} exec whenever --update-crontab #{name.call} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}&cron_group=#{cron_group}')}
)
end
desc "Write crontab"
task write: :environment do
queue %(
echo "-----> Update crontab for #{name.call}"
#{echo_cmd %(cd #{deploy_to!}/#{current_path!} ; #{bundle_bin} exec whenever --write-crontab #{name.call} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}&cron_group=#{cron_group}')}
)
end
end
# For help in making your deploy script, see the Mina documentation:
#
# - http://nadarei.co/mina
# - http://nadarei.co/mina/tasks
# - http://nadarei.co/mina/settings
# - http://nadarei.co/mina/helpers