smartcloud 0.0.83 → 0.0.88
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 +4 -4
- data/lib/smartcloud.rb +1 -0
- data/lib/smartcloud/grids/grid-runner/buildpacks/buildpacker.rb +2 -2
- data/lib/smartcloud/grids/runner.rb +35 -29
- 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: 24b3f805e1fd1c1f9997ef327ccefafb104c8ce44a969d681151a2e1344e4d51
|
4
|
+
data.tar.gz: 734a0dfb85808d01e676dad61aaa717408620269d34f7c0463ad05022f305028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cae4c977dd08da48f05963db0453f3ffe2ea20ddfc33698594f2a562653ce767d433a56d12cbc4cea5ba51cfae6b062f95cdecf4de9f48205879c7c0a516cc26
|
7
|
+
data.tar.gz: 7e9d1ef94df2969dd02f753ad2a603d2d3412032cb6491d6a390a53a06c434dddf37aade9af3b3181291cd29c73753398669c61508337d2a8630cf44a5bab78b
|
data/lib/smartcloud.rb
CHANGED
@@ -12,7 +12,7 @@ class Buildpacker
|
|
12
12
|
FileUtils.rm("tmp/pids/server.pid") if File.exist? "tmp/pids/server.pid"
|
13
13
|
|
14
14
|
puts "-----> Performing bundle install ... "
|
15
|
-
if system("bundle install --deployment --clean
|
15
|
+
if system("bundle install --deployment --clean")
|
16
16
|
puts "-----> Installing Javascript Dependencies & Pre-compiling Assets ... "
|
17
17
|
if system("bundle exec rails assets:precompile", out: File::NULL)
|
18
18
|
puts "done"
|
@@ -21,7 +21,7 @@ class Buildpacker
|
|
21
21
|
if system("god -c Godfile -D")
|
22
22
|
puts "-----> Launched Application ... Success."
|
23
23
|
end
|
24
|
-
exit 0
|
24
|
+
# exit 0
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -186,7 +186,7 @@ module Smartcloud
|
|
186
186
|
end
|
187
187
|
unless File.exist? "#{container_path}/env"
|
188
188
|
print "-----> Creating App Environment ... "
|
189
|
-
|
189
|
+
page = <<~HEREDOC
|
190
190
|
## System
|
191
191
|
USERNAME=#{username}
|
192
192
|
KEEP_RELEASES=3
|
@@ -196,8 +196,8 @@ module Smartcloud
|
|
196
196
|
LETSENCRYPT_HOST=#{appname}.#{Smartcloud.config.apps_domain}
|
197
197
|
LETSENCRYPT_EMAIL=#{Smartcloud.config.sysadmin_email}
|
198
198
|
LETSENCRYPT_TEST=false
|
199
|
-
|
200
|
-
puts "done"
|
199
|
+
HEREDOC
|
200
|
+
puts "done" if system("echo '#{page}' > #{container_path}/env")
|
201
201
|
end
|
202
202
|
end
|
203
203
|
end
|
@@ -218,13 +218,12 @@ module Smartcloud
|
|
218
218
|
end
|
219
219
|
|
220
220
|
def self.prereceive_app(appname, username, oldrev, newrev, refname)
|
221
|
-
|
222
|
-
$stdout.sync = true
|
221
|
+
logger = Logger.new(STDOUT)
|
223
222
|
|
224
223
|
container_path = "#{Smartcloud.config.user_home_path}/.smartcloud/grids/grid-runner/apps/containers/#{appname}"
|
225
224
|
|
226
225
|
## Verify the user and ensure the user is correct and has access to this repository
|
227
|
-
|
226
|
+
logger.info "-----> Verifying User ... "
|
228
227
|
unless File.exist? "#{container_path}/env"
|
229
228
|
puts "Environment could not be loaded ... Failed."
|
230
229
|
exit 1
|
@@ -240,28 +239,28 @@ module Smartcloud
|
|
240
239
|
|
241
240
|
# Match Username
|
242
241
|
unless ENV['USERNAME'] == username
|
243
|
-
puts "
|
242
|
+
puts "Unauthorized."
|
244
243
|
exit 1
|
245
244
|
end
|
246
|
-
|
245
|
+
logger.info "done"
|
247
246
|
|
248
247
|
# Only run this script for the master branch. You can remove this
|
249
248
|
# if block if you wish to run it for others as well.
|
250
249
|
if refname == "refs/heads/master"
|
251
|
-
|
250
|
+
logger.info "-----> Initializing Application ... "
|
252
251
|
|
253
|
-
# Note: There should be no space between + and " in
|
252
|
+
# Note: There should be no space between + and " in version.
|
254
253
|
# Note: date will be UTC date until timezone has been changed.
|
255
|
-
|
256
|
-
|
254
|
+
version = `date +"%Y%m%d%H%M%S"`.chomp!
|
255
|
+
container_path_with_version = "#{container_path}/releases/#{version}"
|
257
256
|
|
258
|
-
unless Dir.exist?
|
259
|
-
FileUtils.mkdir_p(
|
260
|
-
if system("git archive #{newrev} | tar -x -C #{
|
257
|
+
unless Dir.exist? container_path_with_version
|
258
|
+
FileUtils.mkdir_p(container_path_with_version)
|
259
|
+
if system("git archive #{newrev} | tar -x -C #{container_path_with_version}")
|
261
260
|
puts "done"
|
262
261
|
|
263
262
|
# Clean up very old versions
|
264
|
-
Dir.chdir(container_path) do
|
263
|
+
Dir.chdir("#{container_path}/releases") do
|
265
264
|
app_versions = Dir.glob('*').select { |f| File.directory? f }.sort
|
266
265
|
destroy_count = app_versions.count - ENV['KEEP_RELEASES'].to_i
|
267
266
|
if destroy_count > 0
|
@@ -279,6 +278,9 @@ module Smartcloud
|
|
279
278
|
puts "Could not extract new app version ... Failed."
|
280
279
|
exit 1
|
281
280
|
end
|
281
|
+
else
|
282
|
+
puts "This version name already exists ... Failed."
|
283
|
+
exit 1
|
282
284
|
end
|
283
285
|
end
|
284
286
|
end
|
@@ -287,27 +289,26 @@ module Smartcloud
|
|
287
289
|
if Smartcloud::Docker.running?
|
288
290
|
container_path = "#{Smartcloud.config.user_home_path}/.smartcloud/grids/grid-runner/apps/containers/#{appname}"
|
289
291
|
|
290
|
-
Dir.chdir(container_path) do
|
292
|
+
Dir.chdir("#{container_path}/releases") do
|
291
293
|
if app_version == 0
|
292
294
|
app_versions = Dir.glob('*').select { |f| File.directory? f }.sort
|
293
295
|
app_version = app_versions.last
|
294
296
|
end
|
295
297
|
|
296
|
-
|
298
|
+
container_path_with_version = "#{container_path}/releases/#{app_version}"
|
297
299
|
|
298
300
|
# Setup Buildpacker
|
299
301
|
buildpacker_path = "#{Smartcloud.config.root_path}/lib/smartcloud/grids/grid-runner/buildpacks/buildpacker.rb"
|
300
|
-
FileUtils.cp(buildpacker_path,
|
302
|
+
FileUtils.cp(buildpacker_path, container_path_with_version)
|
301
303
|
|
302
304
|
puts "-----> Launching Application ... "
|
303
305
|
|
304
|
-
if File.exist? "#{
|
305
|
-
|
306
|
+
if File.exist? "#{container_path_with_version}/bin/rails"
|
306
307
|
# Stopping & Removing container
|
307
308
|
self.stop_app(appname)
|
308
309
|
|
309
310
|
# Starting Rails App
|
310
|
-
self.start_app_rails(appname, container_path,
|
311
|
+
self.start_app_rails(appname, container_path, container_path_with_version)
|
311
312
|
end
|
312
313
|
end
|
313
314
|
end
|
@@ -334,12 +335,12 @@ module Smartcloud
|
|
334
335
|
end
|
335
336
|
end
|
336
337
|
|
337
|
-
def self.start_app_rails(appname, container_path,
|
338
|
-
puts "-----> Ruby on Rails application detected"
|
338
|
+
def self.start_app_rails(appname, container_path, container_path_with_version)
|
339
|
+
puts "-----> Ruby on Rails application detected."
|
339
340
|
|
340
341
|
# Setup rails env
|
341
342
|
env_path = "#{container_path}/env"
|
342
|
-
system("grep -q '^## Rails' #{env_path} || echo '
|
343
|
+
system("grep -q '^## Rails' #{env_path} || echo '## Rails' >> #{env_path}")
|
343
344
|
system("grep -q '^RAILS_ENV=' #{env_path} || echo 'RAILS_ENV=production' >> #{env_path}")
|
344
345
|
system("grep -q '^RACK_ENV=' #{env_path} || echo 'RACK_ENV=production' >> #{env_path}")
|
345
346
|
system("grep -q '^RAILS_LOG_TO_STDOUT=' #{env_path} || echo 'RAILS_LOG_TO_STDOUT=enabled' >> #{env_path}")
|
@@ -348,17 +349,22 @@ module Smartcloud
|
|
348
349
|
system("grep -q '^RAILS_MASTER_KEY=' #{env_path} || echo 'RAILS_MASTER_KEY=yourmasterkey' >> #{env_path}")
|
349
350
|
puts "-----> WARNING: Please set your RAILS_MASTER_KEY env var for this rails app." if system("grep -q '^RAILS_MASTER_KEY=yourmasterkey' #{env_path}")
|
350
351
|
|
352
|
+
# Setup gems folder. If this is not created then docker will create it while running the container,
|
353
|
+
# but the folder will have root user assigned instead of the current user.
|
354
|
+
FileUtils.mkdir_p("#{container_path}/gems")
|
355
|
+
|
351
356
|
# Setup Godfile
|
352
|
-
unless File.exist? "#{
|
357
|
+
unless File.exist? "#{container_path_with_version}/Godfile"
|
353
358
|
puts "-----> WARNING: Godfile not detected. Adding a default Godfile. It is recommended to add your own Godfile."
|
354
|
-
|
359
|
+
page = <<~HEREDOC
|
355
360
|
God.watch do |w|
|
356
361
|
w.name = 'web'
|
357
362
|
w.start = 'bundle exec puma -C config/puma.rb'
|
358
363
|
w.behavior(:clean_pid_file)
|
359
364
|
w.keepalive
|
360
365
|
end
|
361
|
-
|
366
|
+
HEREDOC
|
367
|
+
system("echo '#{page}' > #{container_path_with_version}/Godfile")
|
362
368
|
end
|
363
369
|
|
364
370
|
# Creating & Starting container
|
@@ -366,7 +372,7 @@ module Smartcloud
|
|
366
372
|
--name='#{appname}' \
|
367
373
|
--env-file='#{container_path}/env' \
|
368
374
|
--expose='5000' \
|
369
|
-
--volume='#{
|
375
|
+
--volume='#{container_path_with_version}:/code' \
|
370
376
|
--volume='#{container_path}/gems:/code/vendor/bundle' \
|
371
377
|
--workdir='/code' \
|
372
378
|
--restart='always' \
|