smartcloud 0.0.147 → 0.0.152

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab4d783600234f10dae6ca73b7b8a3cf217f917788f49b848c6b3f77f76d6c93
4
- data.tar.gz: c5e3358e29d21a0ba107065a8a1371dd9d58f8ff03ea9c41b5e4840bfe4e8820
3
+ metadata.gz: 3146224d7a28c5f2be95c7c1df25a6aee6f389063869f6c779203835522b1371
4
+ data.tar.gz: 68e4fd2197a102fbe154f941342d5073a0fdfc071bae2cc60e6580b4a78610f0
5
5
  SHA512:
6
- metadata.gz: 461c82b342a2cd25038626c2e4757d4d9f0ca3ec5ac4624f3614d2fa8c379dd99ccdcb8d83d22c1aef6f75de820f095143d647becf79800425923d4651b049a0
7
- data.tar.gz: 6f76f795e36f91f2f4e629815c73ccb2862365570dcc9b8eeb52c366a50c197b95a5da2d7be5cabf3d12d2466d07f6d2a2424f282a40105af503fb59dcd124a0
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 "-----> Verifying User ... "
229
+ logger.info "Verifying User ..."
230
230
  unless File.exist? "#{container_path}/env"
231
- puts "Environment could not be loaded ... Failed."
232
- exit 1
231
+ logger.fatal "Environment could not be loaded ... Failed."
232
+ return
233
233
  end
234
234
 
235
235
  # Load ENV vars
@@ -242,15 +242,14 @@ module Smartcloud
242
242
 
243
243
  # Match Username
244
244
  unless ENV['USERNAME'] == username
245
- puts "Unauthorized."
246
- exit 1
245
+ logger.error "Unauthorized."
246
+ return
247
247
  end
248
- logger.info "done"
249
248
 
250
249
  # Only run this script for the master branch. You can remove this
251
250
  # if block if you wish to run it for others as well.
252
251
  if refname == "refs/heads/master"
253
- logger.info "-----> Initializing Application ... "
252
+ logger.info "Loading Application ..."
254
253
 
255
254
  # Note: There should be no space between + and " in version.
256
255
  # Note: date will be UTC date until timezone has been changed.
@@ -260,30 +259,15 @@ module Smartcloud
260
259
  unless Dir.exist? container_path_with_version
261
260
  FileUtils.mkdir_p(container_path_with_version)
262
261
  if system("git archive #{newrev} | tar -x -C #{container_path_with_version}")
263
- puts "done"
264
-
265
- # Clean up very old versions
266
- Dir.chdir("#{container_path}/releases") do
267
- app_versions = Dir.glob('*').select { |f| File.directory? f }.sort
268
- destroy_count = app_versions.count - ENV['KEEP_RELEASES'].to_i
269
- if destroy_count > 0
270
- print "-----> Deleting older application releases ... "
271
- destroy_count.times do
272
- FileUtils.rm_r(File.join(Dir.pwd, app_versions.shift))
273
- end
274
- puts "done"
275
- end
276
- end
277
-
278
262
  # Start App
279
263
  self.start_app(appname)
280
264
  else
281
- puts "Could not extract new app version ... Failed."
282
- exit 1
265
+ logger.fatal "Could not extract new app version ... Failed."
266
+ return
283
267
  end
284
268
  else
285
- puts "This version name already exists ... Failed."
286
- exit 1
269
+ logger.fatal "This version name already exists ... Failed."
270
+ return
287
271
  end
288
272
  end
289
273
 
@@ -306,7 +290,7 @@ module Smartcloud
306
290
  buildpacker_path = "#{Smartcloud.config.root_path}/lib/smartcloud/grids/grid-runner/buildpacks/buildpacker.rb"
307
291
  FileUtils.cp(buildpacker_path, container_path_with_version)
308
292
 
309
- puts "-----> Launching Application ... "
293
+ logger.info "Launching Application ..."
310
294
 
311
295
  if File.exist? "#{container_path_with_version}/bin/rails"
312
296
  # Stopping & Removing container
@@ -321,19 +305,16 @@ module Smartcloud
321
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.
322
306
  # If the app was finally started, then these two lines should never be executed.
323
307
  self.stop_app(appname)
324
- exit 1
325
308
  end
326
309
 
327
310
  def self.stop_app(appname)
328
311
  if Smartcloud::Docker.running?
329
312
  if system("docker inspect -f '{{.State.Running}}' #{appname}", [:out, :err] => File::NULL)
330
- print "-----> Stopping container #{appname} ... "
313
+ logger.debug "Stopping container #{appname} ..."
331
314
  if system("docker stop '#{appname}'", out: File::NULL)
332
- puts "done"
333
-
334
- print "-----> Removing container #{appname} ... "
315
+ logger.debug "Removing container #{appname} ..."
335
316
  if system("docker rm '#{appname}'", out: File::NULL)
336
- puts "done"
317
+ logger.info "Stopped & Removed #{appname} ..."
337
318
  end
338
319
  end
339
320
  end
@@ -341,7 +322,7 @@ module Smartcloud
341
322
  end
342
323
 
343
324
  def self.start_app_rails(appname, container_path, container_path_with_version)
344
- puts "-----> Ruby on Rails application detected."
325
+ logger.info "Ruby on Rails application detected"
345
326
 
346
327
  # Setup rails env
347
328
  env_path = "#{container_path}/env"
@@ -352,7 +333,7 @@ module Smartcloud
352
333
  system("grep -q '^RAILS_SERVE_STATIC_FILES=' #{env_path} || echo 'RAILS_SERVE_STATIC_FILES=enabled' >> #{env_path}")
353
334
  system("grep -q '^LANG=' #{env_path} || echo 'LANG=en_US.UTF-8' >> #{env_path}")
354
335
  system("grep -q '^RAILS_MASTER_KEY=' #{env_path} || echo 'RAILS_MASTER_KEY=yourmasterkey' >> #{env_path}")
355
- 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}")
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}")
356
337
 
357
338
  # Setup gems folder. If this is not created then docker will create it while running the container,
358
339
  # but the folder will have root user assigned instead of the current user.
@@ -360,7 +341,7 @@ module Smartcloud
360
341
 
361
342
  # Setup Godfile
362
343
  unless File.exist? "#{container_path_with_version}/Godfile"
363
- puts "-----> WARNING: Godfile not detected. Adding a default Godfile. It is recommended to add your own Godfile."
344
+ logger.warn "WARNING: Godfile not detected. Adding a default Godfile. It is recommended to add your own Godfile."
364
345
  page = <<~HEREDOC
365
346
  God.watch do |w|
366
347
  w.name = 'web'
@@ -388,6 +369,22 @@ module Smartcloud
388
369
  system("docker network connect mysql-network #{appname}")
389
370
 
390
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
391
388
  end
392
389
  end
393
390
  end
@@ -9,13 +9,21 @@ module Smartcloud
9
9
  # Use a hash class-ivar to cache a unique Logger per class:
10
10
  @loggers = {}
11
11
 
12
+ def self.included(base)
13
+ class << base
14
+ def logger
15
+ @logger ||= Smartcloud::Logger.logger_for(self.name)
16
+ end
17
+ end
18
+ end
19
+
12
20
  class << self
13
21
  def logger_for(classname)
14
22
  @loggers[classname] ||= configure_logger_for(classname)
15
23
  end
16
24
 
17
25
  def configure_logger_for(classname)
18
- logger = Logger.new($stdout)
26
+ logger = ::Logger.new($stdout)
19
27
  logger.progname = classname
20
28
  logger
21
29
  end
@@ -10,4 +10,5 @@ while read oldrev newrev refname; do
10
10
  REPOSITORY_BASENAME=$(basename $(readlink -nf "$PWD"/..))
11
11
  fi
12
12
  script -qfc "runner prereceive $REPOSITORY_BASENAME $REMOTE_USER $oldrev $newrev $refname" /home/$(whoami)/.smartcloud/grids/grid-runner/apps/containers/$REPOSITORY_BASENAME/typescript
13
+ exit 1
13
14
  done
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.147
4
+ version: 0.0.152
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timeboard