質問編集履歴

1

該当コードの追加

2020/07/08 00:21

投稿

sakanafuto
sakanafuto

スコア0

test CHANGED
File without changes
test CHANGED
@@ -105,3 +105,301 @@
105
105
 
106
106
 
107
107
  この後にローカルで先程のようにデプロイするとエラーに成ってしまいます。
108
+
109
+
110
+
111
+ ##該当コード
112
+
113
+ `config/deproy.rb`
114
+
115
+ ```
116
+
117
+ lock "3.5.0"
118
+
119
+
120
+
121
+ set :application, "stelle"
122
+
123
+ set :repo_url, "git@github.com:sakanafuto/xxx.git"
124
+
125
+
126
+
127
+ set :deploy_to, "/var/www/stelle"
128
+
129
+
130
+
131
+ set :scm, :git
132
+
133
+ set :format, :pretty
134
+
135
+ set :log_level, :debug
136
+
137
+
138
+
139
+ set :pty, true
140
+
141
+
142
+
143
+ set :keep_releases, 5
144
+
145
+
146
+
147
+ set :rbenv_type, :user
148
+
149
+ set :rbenv_ruby, '2.6.5'
150
+
151
+
152
+
153
+ set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
154
+
155
+ set :rbenv_map_bins, %w{rake gem bundle ruby rails}
156
+
157
+
158
+
159
+ set :linked_files, fetch(:linked_files, []).push('config/master.key')
160
+
161
+
162
+
163
+ set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
164
+
165
+
166
+
167
+ set :bundle_jobs, 4
168
+
169
+
170
+
171
+
172
+
173
+ namespace :deploy do
174
+
175
+
176
+
177
+ desc 'Restart application'
178
+
179
+ task :restart do
180
+
181
+ on roles(:app) do
182
+
183
+ invoke 'unicorn:restart'
184
+
185
+ end
186
+
187
+ end
188
+
189
+
190
+
191
+ desc 'Create database'
192
+
193
+ task :db_create do
194
+
195
+ on roles(:db) do |host|
196
+
197
+ with rails_env: fetch(:rails_env) do
198
+
199
+ within current_path do
200
+
201
+ execute :bundle, :exec, :rake, 'db:create'
202
+
203
+ end
204
+
205
+ end
206
+
207
+ end
208
+
209
+ end
210
+
211
+
212
+
213
+ desc 'Run seed'
214
+
215
+ task :seed do
216
+
217
+ on roles(:app) do
218
+
219
+ with rails_env: fetch(:rails_env) do
220
+
221
+ within current_path do
222
+
223
+ execute :bundle, :exec, :rake, 'db:seed'
224
+
225
+ end
226
+
227
+ end
228
+
229
+ end
230
+
231
+ end
232
+
233
+ end
234
+
235
+
236
+
237
+ after 'deploy:publishing', 'deploy:restart'
238
+
239
+ ```
240
+
241
+
242
+
243
+ `config/deploy/production.rb`
244
+
245
+ ```
246
+
247
+ server '3.xxx.xxx.x', user: 'Stelle', roles: %w{app db web}
248
+
249
+
250
+
251
+ set :ssh_options, {
252
+
253
+ keys: '~/.ssh/xxx_key_rsa',
254
+
255
+ forward_agent: true
256
+
257
+ }
258
+
259
+ ```
260
+
261
+
262
+
263
+ `config/unicorn/production.rb`
264
+
265
+
266
+
267
+ ```
268
+
269
+ app_path = '/var/www/stelle'
270
+
271
+
272
+
273
+ worker_processes 2
274
+
275
+ working_directory "#{app_path}" + "/current"
276
+
277
+
278
+
279
+ preload_app true
280
+
281
+
282
+
283
+ timeout 30
284
+
285
+
286
+
287
+ listen "/tmp/sockets/unicorn.sock", :backlog => 64
288
+
289
+
290
+
291
+ pid "#{app_path}/shared/tmp/pids/unicorn.pid"
292
+
293
+
294
+
295
+ # Set the path of the log files inside the log folder of the testapp
296
+
297
+ stderr_path "#{app_path}/current/log/unicorn.stderr.log"
298
+
299
+ stdout_path "#{app_path}/current/log/unicorn.stdout.log"
300
+
301
+
302
+
303
+ before_fork do |server, worker|
304
+
305
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile', ENV['RAILS_ROOT'])
306
+
307
+ end
308
+
309
+
310
+
311
+ before_fork do |server, worker|
312
+
313
+ defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
314
+
315
+
316
+
317
+ old_pid = "#{server.config[:pid]}.oldbin"
318
+
319
+ if old_pid != server.pid
320
+
321
+ begin
322
+
323
+ sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
324
+
325
+ Process.kill(sig, File.read(old_pid).to_i)
326
+
327
+ rescue Errno::ENOENT, Errno::ESRCH
328
+
329
+ end
330
+
331
+ end
332
+
333
+
334
+
335
+ sleep 1
336
+
337
+ end
338
+
339
+
340
+
341
+ after_fork do |server, worker|
342
+
343
+ defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
344
+
345
+ end
346
+
347
+ ```
348
+
349
+
350
+
351
+ `Capfile`
352
+
353
+ ```
354
+
355
+ require "capistrano/setup"
356
+
357
+ require "capistrano/deploy"
358
+
359
+
360
+
361
+ # require "capistrano/scm/git"
362
+
363
+ # install_plugin Capistrano::SCM::Git
364
+
365
+
366
+
367
+ require "capistrano/rbenv"
368
+
369
+
370
+
371
+ require "capistrano/rails"
372
+
373
+ require "capistrano/rails/assets"
374
+
375
+ require "capistrano/rails/migrations"
376
+
377
+
378
+
379
+ require "capistrano/bundler"
380
+
381
+ require "capistrano3/unicorn"
382
+
383
+
384
+
385
+ Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
386
+
387
+ ```
388
+
389
+
390
+
391
+ `Gemfile`
392
+
393
+ ```
394
+
395
+ gem 'capistrano', '~>3.5.0'
396
+
397
+ gem 'capistrano-bundler', '~> 1.1.3'
398
+
399
+ gem 'capistrano-rails', '~> 1.1.7'
400
+
401
+ gem 'capistrano-rbenv'
402
+
403
+ gem 'capistrano3-unicorn'
404
+
405
+ ```