smartcloud 0.0.156 → 0.0.157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/smartcloud/grids/runner.rb +47 -24
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0f4d3dda6b40f12732bfe026083343ca4b14e3df467ab9d50e5c73aff6069cc
4
- data.tar.gz: c72c3cdbb604173423dae83b8b4338da8dd95523c1d3ef4e2f10a6da8fa48961
3
+ metadata.gz: 032f1337c34584f6feeb39a11d56a506767512c20bce09d720e0eae56920acec
4
+ data.tar.gz: 88c4779b043ec39965c2b0ed5c9ca0cb03b9cf4a0e1dd36983e32e94066f17dc
5
5
  SHA512:
6
- metadata.gz: 7a8ab72089a33b697c7947fdbdb331293510a30dec7125a99d9126118bc245d10ab6a27d3ba2aea4d45f4ae1ca54a66672490fb525604631b13af101ec2ba996
7
- data.tar.gz: 6166b6b3035bddef48c7611f27c6e8d0f5dd7e7065dfd639ea859bb00af919f149041ba4d03c596db86a0787794ac9a6ac56c27a4ed87a8db00d9f65d763494c
6
+ metadata.gz: 97ccd5c3e2625198d0b5afb756f9e1d61f923d8e99409621ac290ed732d0fc05c5134f70c712e7d37b511c328d970c63e0e78a5e079123741267948b626d1af4
7
+ data.tar.gz: e5424293c420c75ab9c00f9c1ec6b7eb94fe6b5086cec3be1cc5ad918e80b6d50bc31c0cc2d7c20659665aa69e791f66c6f7d676351d8435d8687bef74a140a9
@@ -290,24 +290,10 @@ module Smartcloud
290
290
  end
291
291
 
292
292
  def self.stop_app(appname)
293
- if Smartcloud::Docker.running?
294
- if system("docker inspect -f '{{.State.Running}}' #{appname}", [:out, :err] => File::NULL)
295
- logger.debug "Stopping container #{appname} ..."
296
- if system("docker stop '#{appname}'", out: File::NULL)
297
- logger.debug "Removing container #{appname} ..."
298
- if system("docker rm '#{appname}'", out: File::NULL)
299
- logger.debug "Stopped & Removed #{appname} ..."
300
- end
301
- end
302
- end
303
- end
293
+ self.stop_container(appname)
304
294
  end
305
295
 
306
296
  def self.start_app_rails(appname, container_path, container_path_with_version)
307
- # Stopping & Removing not required app containers
308
- # TODO: To be removed after dynamic container switching has been implemented as it should be done in the end at the time of cleanup after the new container is running.
309
- self.stop_app(appname)
310
-
311
297
  logger.info "Ruby on Rails application detected."
312
298
 
313
299
  # Setup rails env
@@ -340,8 +326,9 @@ module Smartcloud
340
326
  end
341
327
 
342
328
  # Creating & Starting container
329
+ self.stop_app("#{appname}_new")
343
330
  if system("docker create \
344
- --name='#{appname}' \
331
+ --name='#{appname}_new' \
345
332
  --env-file='#{container_path}/env' \
346
333
  --expose='5000' \
347
334
  --volume='#{container_path_with_version}:/code' \
@@ -351,21 +338,23 @@ module Smartcloud
351
338
  --network='nginx-network' \
352
339
  smartcloud/buildpacks/rails", out: File::NULL)
353
340
 
354
- system("docker network connect solr-network #{appname}")
355
- system("docker network connect mysql-network #{appname}")
341
+ system("docker network connect solr-network #{appname}_new")
342
+ system("docker network connect mysql-network #{appname}_new")
356
343
 
357
- system("docker start --attach #{appname}")
358
- self.clean_up(container_path)
344
+ system("docker start --attach #{appname}_new")
345
+
346
+ # Runs only if #{appname}_new has been started successfully and is reachable.
347
+ # self.hot_reloading_app(appname)
348
+ # self.clean_up(container_path)
349
+
350
+ # Runs only if #{appname}_new starting has failed.
351
+ # self.stop_app("#{appname}_new")
359
352
  end
360
353
  end
361
354
 
362
355
  def self.clean_up(container_path)
363
356
  logger.info "Cleaning up ..."
364
357
 
365
- # Stopping & Removing not required app containers
366
- appname = File.basename(container_path)
367
- self.stop_app(appname)
368
-
369
358
  # Clean up very old versions
370
359
  Dir.chdir("#{container_path}/releases") do
371
360
  app_versions = Dir.glob('*').select { |f| File.directory? f }.sort
@@ -379,6 +368,26 @@ module Smartcloud
379
368
  end
380
369
  end
381
370
 
371
+ # Hot reloading app containers and removing old app container
372
+ def self.hot_reloading_app(appname)
373
+ logger.debug "Hot reloading '#{appname}' containers ..."
374
+
375
+ container_id = `docker ps -a -q --filter='name=^#{appname}$'`.chomp
376
+ unless container_id.empty?
377
+ if system("docker container rename #{appname} #{appname}_old", [:out, :err] => File::NULL)
378
+ logger.debug "Container renamed from #{appname} #{appname}_old"
379
+ if system("docker container rename #{appname}_new #{appname}", [:out, :err] => File::NULL)
380
+ logger.debug "Container renamed from #{appname}_new #{appname}"
381
+ self.stop_app("#{appname}_old")
382
+ end
383
+ end
384
+ else
385
+ if system("docker container rename #{appname}_new #{appname}", [:out, :err] => File::NULL)
386
+ logger.debug "Container renamed from #{appname}_new #{appname}"
387
+ end
388
+ end
389
+ end
390
+
382
391
  def self.load_container_env_vars(container_path)
383
392
  unless File.exist? "#{container_path}/env"
384
393
  logger.fatal "Environment could not be loaded ... Failed."
@@ -394,6 +403,20 @@ module Smartcloud
394
403
 
395
404
  true
396
405
  end
406
+
407
+ def self.stop_container(container_name)
408
+ if Smartcloud::Docker.running?
409
+ container_id = `docker ps -a -q --filter='name=^#{container_name}$'`.chomp
410
+ unless container_id.empty?
411
+ logger.debug "Stopping & Removing container #{container_name} ..."
412
+ if system("docker stop #{container_name} && docker rm #{container_name}", out: File::NULL)
413
+ logger.debug "Stopped & Removed container #{container_name} ..."
414
+ end
415
+ else
416
+ logger.debug "Container '#{container_name}' does not exist to stop."
417
+ end
418
+ end
419
+ end
397
420
  end
398
421
  end
399
422
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.156
4
+ version: 0.0.157
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timeboard