smartcloud 0.0.152 → 0.0.153

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3146224d7a28c5f2be95c7c1df25a6aee6f389063869f6c779203835522b1371
4
- data.tar.gz: 68e4fd2197a102fbe154f941342d5073a0fdfc071bae2cc60e6580b4a78610f0
3
+ metadata.gz: c37e30863d1ea6b5a7a3c585cb4f41a6aadcf1f0dced48add9830a142213bc35
4
+ data.tar.gz: 1280b3a725d4331feef89ed347b241da53dcb44b0a83e87d63a7130823638117
5
5
  SHA512:
6
- metadata.gz: aaa85bfdcf08755d72b2bc56185c8fb37b1874a174d96f697c52fc75aff92adb13073a6cbccf2d80711065e9a4e2661bc1d11adb7f5988569e9a64542eee5498
7
- data.tar.gz: 91212d5681a150e13e144f73bd96c6c4ae4bf6844140a3c83d17a74c891495bc0b7a3821bffca40c7c9cb0de99b508ca37f0dedc7abb79b459189e27bc428cab
6
+ metadata.gz: 5135a9e4d789b0dcebf218ba6a24cf4344c766440a747695a16e82bbfa41dfafe5076c53b45a6dee4275ea2ebd50ac730e68e8025b20c020bce742320ca0cc98
7
+ data.tar.gz: 6077c2671d93ae32d888474f9afd8e46d3ab9a13c9158cade314d49b4bcb9072faeafddaf54fd72bd22e966922ffd9937ead3f67ed88eeba637402d86f1b18a0
@@ -222,25 +222,15 @@ module Smartcloud
222
222
  logger.formatter = proc do |severity, datetime, progname, message|
223
223
  "\t\t\t-----> #{severity}: #{message}\n"
224
224
  end
225
+ logger.level = ::Logger::DEBUG
225
226
 
226
227
  container_path = "#{Smartcloud.config.user_home_path}/.smartcloud/grids/grid-runner/apps/containers/#{appname}"
227
228
 
228
- ## Verify the user and ensure the user is correct and has access to this repository
229
- logger.info "Verifying User ..."
230
- unless File.exist? "#{container_path}/env"
231
- logger.fatal "Environment could not be loaded ... Failed."
232
- return
233
- end
234
-
235
229
  # Load ENV vars
236
- File.open("#{container_path}/env").each_line do |line|
237
- line.chomp!
238
- next if line.empty? || line.start_with?('#')
239
- key, value = line.split "="
240
- ENV[key] = value
241
- end
230
+ return unless self.load_container_env_vars(container_path)
242
231
 
243
- # Match Username
232
+ # Verify the user and ensure the user is correct and has access to this repository
233
+ logger.info "Verifying User ..."
244
234
  unless ENV['USERNAME'] == username
245
235
  logger.error "Unauthorized."
246
236
  return
@@ -279,32 +269,25 @@ module Smartcloud
279
269
  container_path = "#{Smartcloud.config.user_home_path}/.smartcloud/grids/grid-runner/apps/containers/#{appname}"
280
270
 
281
271
  Dir.chdir("#{container_path}/releases") do
272
+ # Getting App Version
282
273
  if app_version == 0
283
274
  app_versions = Dir.glob('*').select { |f| File.directory? f }.sort
284
275
  app_version = app_versions.last
285
276
  end
286
-
287
277
  container_path_with_version = "#{container_path}/releases/#{app_version}"
288
278
 
289
279
  # Setup Buildpacker
290
280
  buildpacker_path = "#{Smartcloud.config.root_path}/lib/smartcloud/grids/grid-runner/buildpacks/buildpacker.rb"
291
281
  FileUtils.cp(buildpacker_path, container_path_with_version)
292
282
 
283
+ # Launching Application
293
284
  logger.info "Launching Application ..."
294
-
295
285
  if File.exist? "#{container_path_with_version}/bin/rails"
296
- # Stopping & Removing container
297
- self.stop_app(appname)
298
-
299
286
  # Starting Rails App
300
287
  self.start_app_rails(appname, container_path, container_path_with_version)
301
288
  end
302
289
  end
303
290
  end
304
-
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.
306
- # If the app was finally started, then these two lines should never be executed.
307
- self.stop_app(appname)
308
291
  end
309
292
 
310
293
  def self.stop_app(appname)
@@ -314,7 +297,7 @@ module Smartcloud
314
297
  if system("docker stop '#{appname}'", out: File::NULL)
315
298
  logger.debug "Removing container #{appname} ..."
316
299
  if system("docker rm '#{appname}'", out: File::NULL)
317
- logger.info "Stopped & Removed #{appname} ..."
300
+ logger.debug "Stopped & Removed #{appname} ..."
318
301
  end
319
302
  end
320
303
  end
@@ -322,7 +305,10 @@ module Smartcloud
322
305
  end
323
306
 
324
307
  def self.start_app_rails(appname, container_path, container_path_with_version)
325
- logger.info "Ruby on Rails application detected"
308
+ # Stopping & Removing not required app containers
309
+ self.stop_app(appname)
310
+
311
+ logger.info "Ruby on Rails application detected."
326
312
 
327
313
  # Setup rails env
328
314
  env_path = "#{container_path}/env"
@@ -376,17 +362,37 @@ module Smartcloud
376
362
  def self.clean_up(container_path)
377
363
  logger.info "Cleaning up ..."
378
364
 
365
+ # Stopping & Removing not required app containers
366
+ self.stop_app(appname)
367
+
379
368
  # Clean up very old versions
380
369
  Dir.chdir("#{container_path}/releases") do
381
370
  app_versions = Dir.glob('*').select { |f| File.directory? f }.sort
382
371
  destroy_count = app_versions.count - ENV['KEEP_RELEASES'].to_i
383
372
  if destroy_count > 0
373
+ logger.debug "Deleting older application releases ..."
384
374
  destroy_count.times do
385
375
  FileUtils.rm_r(File.join(Dir.pwd, app_versions.shift))
386
376
  end
387
377
  end
388
378
  end
389
379
  end
380
+
381
+ def self.load_container_env_vars(container_path)
382
+ unless File.exist? "#{container_path}/env"
383
+ logger.fatal "Environment could not be loaded ... Failed."
384
+ false
385
+ end
386
+
387
+ File.open("#{container_path}/env").each_line do |line|
388
+ line.chomp!
389
+ next if line.empty? || line.start_with?('#')
390
+ key, value = line.split "="
391
+ ENV[key] = value
392
+ end
393
+
394
+ true
395
+ end
390
396
  end
391
397
  end
392
398
  end
@@ -24,6 +24,7 @@ module Smartcloud
24
24
 
25
25
  def configure_logger_for(classname)
26
26
  logger = ::Logger.new($stdout)
27
+ logger.level = ::Logger::INFO
27
28
  logger.progname = classname
28
29
  logger
29
30
  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.152
4
+ version: 0.0.153
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timeboard