smartcloud 0.0.151 → 0.0.152
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smartcloud/grids/runner.rb +34 -38
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3146224d7a28c5f2be95c7c1df25a6aee6f389063869f6c779203835522b1371
|
4
|
+
data.tar.gz: 68e4fd2197a102fbe154f941342d5073a0fdfc071bae2cc60e6580b4a78610f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaa85bfdcf08755d72b2bc56185c8fb37b1874a174d96f697c52fc75aff92adb13073a6cbccf2d80711065e9a4e2661bc1d11adb7f5988569e9a64542eee5498
|
7
|
+
data.tar.gz: 91212d5681a150e13e144f73bd96c6c4ae4bf6844140a3c83d17a74c891495bc0b7a3821bffca40c7c9cb0de99b508ca37f0dedc7abb79b459189e27bc428cab
|
@@ -220,16 +220,16 @@ module Smartcloud
|
|
220
220
|
|
221
221
|
def self.prereceive_app(appname, username, oldrev, newrev, refname)
|
222
222
|
logger.formatter = proc do |severity, datetime, progname, message|
|
223
|
-
"\t\t\t#{severity}: #{message}\n"
|
223
|
+
"\t\t\t-----> #{severity}: #{message}\n"
|
224
224
|
end
|
225
225
|
|
226
226
|
container_path = "#{Smartcloud.config.user_home_path}/.smartcloud/grids/grid-runner/apps/containers/#{appname}"
|
227
227
|
|
228
228
|
## Verify the user and ensure the user is correct and has access to this repository
|
229
|
-
logger.info "
|
229
|
+
logger.info "Verifying User ..."
|
230
230
|
unless File.exist? "#{container_path}/env"
|
231
|
-
|
232
|
-
|
231
|
+
logger.fatal "Environment could not be loaded ... Failed."
|
232
|
+
return
|
233
233
|
end
|
234
234
|
|
235
235
|
# Load ENV vars
|
@@ -242,16 +242,14 @@ module Smartcloud
|
|
242
242
|
|
243
243
|
# Match Username
|
244
244
|
unless ENV['USERNAME'] == username
|
245
|
-
|
246
|
-
|
245
|
+
logger.error "Unauthorized."
|
246
|
+
return
|
247
247
|
end
|
248
|
-
logger.formatter = nil
|
249
|
-
logger.info "done"
|
250
248
|
|
251
249
|
# Only run this script for the master branch. You can remove this
|
252
250
|
# if block if you wish to run it for others as well.
|
253
251
|
if refname == "refs/heads/master"
|
254
|
-
logger.info "
|
252
|
+
logger.info "Loading Application ..."
|
255
253
|
|
256
254
|
# Note: There should be no space between + and " in version.
|
257
255
|
# Note: date will be UTC date until timezone has been changed.
|
@@ -261,30 +259,15 @@ module Smartcloud
|
|
261
259
|
unless Dir.exist? container_path_with_version
|
262
260
|
FileUtils.mkdir_p(container_path_with_version)
|
263
261
|
if system("git archive #{newrev} | tar -x -C #{container_path_with_version}")
|
264
|
-
puts "done"
|
265
|
-
|
266
|
-
# Clean up very old versions
|
267
|
-
Dir.chdir("#{container_path}/releases") do
|
268
|
-
app_versions = Dir.glob('*').select { |f| File.directory? f }.sort
|
269
|
-
destroy_count = app_versions.count - ENV['KEEP_RELEASES'].to_i
|
270
|
-
if destroy_count > 0
|
271
|
-
print "-----> Deleting older application releases ... "
|
272
|
-
destroy_count.times do
|
273
|
-
FileUtils.rm_r(File.join(Dir.pwd, app_versions.shift))
|
274
|
-
end
|
275
|
-
puts "done"
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
262
|
# Start App
|
280
263
|
self.start_app(appname)
|
281
264
|
else
|
282
|
-
|
283
|
-
|
265
|
+
logger.fatal "Could not extract new app version ... Failed."
|
266
|
+
return
|
284
267
|
end
|
285
268
|
else
|
286
|
-
|
287
|
-
|
269
|
+
logger.fatal "This version name already exists ... Failed."
|
270
|
+
return
|
288
271
|
end
|
289
272
|
end
|
290
273
|
|
@@ -307,7 +290,7 @@ module Smartcloud
|
|
307
290
|
buildpacker_path = "#{Smartcloud.config.root_path}/lib/smartcloud/grids/grid-runner/buildpacks/buildpacker.rb"
|
308
291
|
FileUtils.cp(buildpacker_path, container_path_with_version)
|
309
292
|
|
310
|
-
|
293
|
+
logger.info "Launching Application ..."
|
311
294
|
|
312
295
|
if File.exist? "#{container_path_with_version}/bin/rails"
|
313
296
|
# Stopping & Removing container
|
@@ -322,19 +305,16 @@ module Smartcloud
|
|
322
305
|
# These two lines are important to stop and remove container and then cancel pre-receive push if finally the app could not be started.
|
323
306
|
# If the app was finally started, then these two lines should never be executed.
|
324
307
|
self.stop_app(appname)
|
325
|
-
exit 1
|
326
308
|
end
|
327
309
|
|
328
310
|
def self.stop_app(appname)
|
329
311
|
if Smartcloud::Docker.running?
|
330
312
|
if system("docker inspect -f '{{.State.Running}}' #{appname}", [:out, :err] => File::NULL)
|
331
|
-
|
313
|
+
logger.debug "Stopping container #{appname} ..."
|
332
314
|
if system("docker stop '#{appname}'", out: File::NULL)
|
333
|
-
|
334
|
-
|
335
|
-
print "-----> Removing container #{appname} ... "
|
315
|
+
logger.debug "Removing container #{appname} ..."
|
336
316
|
if system("docker rm '#{appname}'", out: File::NULL)
|
337
|
-
|
317
|
+
logger.info "Stopped & Removed #{appname} ..."
|
338
318
|
end
|
339
319
|
end
|
340
320
|
end
|
@@ -342,7 +322,7 @@ module Smartcloud
|
|
342
322
|
end
|
343
323
|
|
344
324
|
def self.start_app_rails(appname, container_path, container_path_with_version)
|
345
|
-
|
325
|
+
logger.info "Ruby on Rails application detected"
|
346
326
|
|
347
327
|
# Setup rails env
|
348
328
|
env_path = "#{container_path}/env"
|
@@ -353,7 +333,7 @@ module Smartcloud
|
|
353
333
|
system("grep -q '^RAILS_SERVE_STATIC_FILES=' #{env_path} || echo 'RAILS_SERVE_STATIC_FILES=enabled' >> #{env_path}")
|
354
334
|
system("grep -q '^LANG=' #{env_path} || echo 'LANG=en_US.UTF-8' >> #{env_path}")
|
355
335
|
system("grep -q '^RAILS_MASTER_KEY=' #{env_path} || echo 'RAILS_MASTER_KEY=yourmasterkey' >> #{env_path}")
|
356
|
-
logger.warn "
|
336
|
+
logger.warn "WARNING: Please set your RAILS_MASTER_KEY env var for this rails app." if system("grep -q '^RAILS_MASTER_KEY=yourmasterkey' #{env_path}")
|
357
337
|
|
358
338
|
# Setup gems folder. If this is not created then docker will create it while running the container,
|
359
339
|
# but the folder will have root user assigned instead of the current user.
|
@@ -361,7 +341,7 @@ module Smartcloud
|
|
361
341
|
|
362
342
|
# Setup Godfile
|
363
343
|
unless File.exist? "#{container_path_with_version}/Godfile"
|
364
|
-
|
344
|
+
logger.warn "WARNING: Godfile not detected. Adding a default Godfile. It is recommended to add your own Godfile."
|
365
345
|
page = <<~HEREDOC
|
366
346
|
God.watch do |w|
|
367
347
|
w.name = 'web'
|
@@ -389,6 +369,22 @@ module Smartcloud
|
|
389
369
|
system("docker network connect mysql-network #{appname}")
|
390
370
|
|
391
371
|
system("docker start --attach #{appname}")
|
372
|
+
self.clean_up(container_path)
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
def self.clean_up(container_path)
|
377
|
+
logger.info "Cleaning up ..."
|
378
|
+
|
379
|
+
# Clean up very old versions
|
380
|
+
Dir.chdir("#{container_path}/releases") do
|
381
|
+
app_versions = Dir.glob('*').select { |f| File.directory? f }.sort
|
382
|
+
destroy_count = app_versions.count - ENV['KEEP_RELEASES'].to_i
|
383
|
+
if destroy_count > 0
|
384
|
+
destroy_count.times do
|
385
|
+
FileUtils.rm_r(File.join(Dir.pwd, app_versions.shift))
|
386
|
+
end
|
387
|
+
end
|
392
388
|
end
|
393
389
|
end
|
394
390
|
end
|