smartcloud 0.0.206 → 0.1.0
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/grids/buildpacker.rb +40 -14
- data/lib/smartcloud/grids/grid-runner/Dockerfile +1 -1
- data/lib/smartcloud/grids/grid-runner/buildpacks/rails/Dockerfile +1 -2
- data/lib/smartcloud/grids/runner.rb +22 -48
- data/lib/smartcloud/templates/dotsmartcloud/grids/grid-runner/pre-receive +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa2a3f8c929555cb37a5587ddbcf00af3e266afecc59442cdfe7c6c445d5a81b
|
4
|
+
data.tar.gz: be14f3480b057ccc010c596665313dbbd5d7e6a5aec6098b7a8225b142f5cbea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42c54ce67d371361a9c6ffced3e81a864bc9e48feec61248fa5ed35099d62cc905beaf6a100ec6a450102cc5c129d7f4f7883f323cc5c459f2d129cbb7c9f44a
|
7
|
+
data.tar.gz: cf1d7349d53f1d31abedbc9d403319ed1b2c0f277e8c9fe6ba877636f5a781765c562765a33838490f2e1cf90b6d66d625068d4644a2e485df4f09085e5d2207
|
@@ -17,11 +17,20 @@ module Smartcloud
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def pack_rails
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
if File.exist? "tmp/smartcloud/packed"
|
21
|
+
begin
|
22
|
+
pid = File.read('tmp/smartcloud/packed').to_i
|
23
|
+
Process.kill('QUIT', pid)
|
24
|
+
rescue Errno::ESRCH # No such process
|
25
|
+
end
|
26
|
+
exec "bundle", "exec", "puma", "--config", "config/puma.rb"
|
27
|
+
else
|
28
|
+
return unless bundle_install?
|
29
|
+
return unless precompile_assets?
|
30
|
+
return unless test_web_server?
|
23
31
|
|
24
|
-
|
32
|
+
exit 0
|
33
|
+
end
|
25
34
|
end
|
26
35
|
|
27
36
|
# Perform bundle install
|
@@ -64,17 +73,34 @@ module Smartcloud
|
|
64
73
|
end
|
65
74
|
end
|
66
75
|
|
67
|
-
# Perform
|
68
|
-
def
|
69
|
-
logger.
|
70
|
-
|
71
|
-
#
|
72
|
-
FileUtils.
|
76
|
+
# Perform testing of web server
|
77
|
+
def test_web_server?
|
78
|
+
logger.info "Setting up Web Server ..."
|
79
|
+
|
80
|
+
# tmp folder
|
81
|
+
FileUtils.mkdir_p("tmp/smartcloud")
|
82
|
+
FileUtils.rm_f("tmp/smartcloud/packed")
|
83
|
+
|
84
|
+
# Spawn Process
|
85
|
+
pid = Process.spawn("bundle", "exec", "puma", "--config", "config/puma.rb", out: File::NULL)
|
86
|
+
Process.detach(pid)
|
87
|
+
|
88
|
+
# Sleep
|
89
|
+
sleep 5
|
90
|
+
|
91
|
+
# Check PID running
|
92
|
+
status = nil
|
93
|
+
begin
|
94
|
+
Process.kill(0, pid)
|
95
|
+
system("echo '#{pid}' > tmp/smartcloud/packed")
|
96
|
+
status = true
|
97
|
+
rescue Errno::ESRCH # No such process
|
98
|
+
logger.info "Web Server could not start"
|
99
|
+
status = false
|
100
|
+
end
|
73
101
|
|
74
|
-
#
|
75
|
-
|
76
|
-
# end
|
77
|
-
# return false
|
102
|
+
# Return status
|
103
|
+
return status
|
78
104
|
end
|
79
105
|
|
80
106
|
def set_logger_formatter_arrow
|
@@ -113,7 +113,7 @@ module Smartcloud
|
|
113
113
|
--build-arg USER_NAME=`id -un` \
|
114
114
|
--build-arg USER_UID=`id -u` \
|
115
115
|
--build-arg DOCKER_GID=`getent group docker | cut -d: -f3` \
|
116
|
-
#{Smartcloud.config.root_path}/lib/smartcloud/grids/grid-runner")
|
116
|
+
#{Smartcloud.config.root_path}/lib/smartcloud/grids/grid-runner", out: File::NULL)
|
117
117
|
puts "done"
|
118
118
|
end
|
119
119
|
end
|
@@ -123,7 +123,7 @@ module Smartcloud
|
|
123
123
|
if system("docker image build -t smartcloud/buildpacks/rails \
|
124
124
|
--build-arg USER_UID=`id -u` \
|
125
125
|
--build-arg USER_NAME=`id -un` \
|
126
|
-
#{Smartcloud.config.root_path}/lib/smartcloud/grids/grid-runner/buildpacks/rails")
|
126
|
+
#{Smartcloud.config.root_path}/lib/smartcloud/grids/grid-runner/buildpacks/rails", out: File::NULL)
|
127
127
|
puts "done"
|
128
128
|
end
|
129
129
|
end
|
@@ -293,6 +293,7 @@ module Smartcloud
|
|
293
293
|
# Setup rails env
|
294
294
|
env_path = "#{container_path}/env"
|
295
295
|
system("grep -q '^## Rails' #{env_path} || echo '## Rails' >> #{env_path}")
|
296
|
+
system("grep -q '^MALLOC_ARENA_MAX=' #{env_path} || echo '# MALLOC_ARENA_MAX=2' >> #{env_path}")
|
296
297
|
system("grep -q '^RAILS_ENV=' #{env_path} || echo 'RAILS_ENV=production' >> #{env_path}")
|
297
298
|
system("grep -q '^RACK_ENV=' #{env_path} || echo 'RACK_ENV=production' >> #{env_path}")
|
298
299
|
system("grep -q '^RAILS_LOG_TO_STDOUT=' #{env_path} || echo 'RAILS_LOG_TO_STDOUT=enabled' >> #{env_path}")
|
@@ -307,46 +308,41 @@ module Smartcloud
|
|
307
308
|
FileUtils.mkdir_p("#{container_path}/app/public")
|
308
309
|
FileUtils.mkdir_p("#{container_path}/app/node_modules")
|
309
310
|
|
310
|
-
# Setup Godfile
|
311
|
-
unless File.exist? "#{container_path_with_version}/Godfile"
|
312
|
-
logger.warn "Godfile not detected. Adding a default Godfile. It is recommended to add your own Godfile."
|
313
|
-
page = <<~"HEREDOC"
|
314
|
-
God.watch do |w|
|
315
|
-
w.name = "web"
|
316
|
-
w.start = "bundle exec puma -C config/puma.rb"
|
317
|
-
w.behavior(:clean_pid_file)
|
318
|
-
w.keepalive
|
319
|
-
end
|
320
|
-
HEREDOC
|
321
|
-
system("echo '#{page}' > #{container_path_with_version}/Godfile")
|
322
|
-
end
|
323
|
-
|
324
311
|
# Creating & Starting container
|
325
|
-
|
312
|
+
container_id = `docker ps -a -q --filter='name=^#{appname}_1$' --filter='status=running'`.chomp
|
313
|
+
new_container = container_id.empty? ? "#{appname}_1" : "#{appname}_2"
|
314
|
+
old_container = container_id.empty? ? "#{appname}_2" : "#{appname}_1"
|
315
|
+
|
316
|
+
self.stop_app("#{new_container}")
|
326
317
|
if system("docker create \
|
327
|
-
--name='#{
|
318
|
+
--name='#{new_container}' \
|
328
319
|
--env-file='#{container_path}/env' \
|
329
|
-
--expose='
|
320
|
+
--expose='3000' \
|
330
321
|
--volume='#{Smartcloud.config.user_home_path}/.smartcloud/config:#{Smartcloud.config.user_home_path}/.smartcloud/config' \
|
331
322
|
--volume='#{container_path_with_version}:/app' \
|
332
323
|
--volume='#{container_path}/app/vendor/bundle:/app/vendor/bundle' \
|
333
324
|
--volume='#{container_path}/app/public:/app/public' \
|
334
325
|
--volume='#{container_path}/app/node_modules:/app/node_modules' \
|
335
326
|
--restart='always' \
|
327
|
+
--init \
|
336
328
|
--network='nginx-network' \
|
337
329
|
smartcloud/buildpacks/rails", out: File::NULL)
|
338
330
|
|
339
|
-
system("docker network connect solr-network #{
|
340
|
-
system("docker network connect mysql-network #{
|
331
|
+
system("docker network connect solr-network #{new_container}")
|
332
|
+
system("docker network connect mysql-network #{new_container}")
|
341
333
|
|
342
|
-
if system("docker start --attach #{
|
343
|
-
|
334
|
+
if system("docker start --attach #{new_container}")
|
335
|
+
logger.debug "Starting Web Server ..."
|
336
|
+
if system("docker start #{new_container}", out: File::NULL)
|
337
|
+
sleep 5
|
338
|
+
logger.info "Web Server started successfully."
|
339
|
+
self.stop_app(old_container)
|
344
340
|
self.clean_up(container_path)
|
345
341
|
logger.info "Launched Application ... Success."
|
346
|
-
exit
|
342
|
+
exit 10
|
347
343
|
end
|
348
344
|
else
|
349
|
-
self.stop_app("#{
|
345
|
+
self.stop_app("#{new_container}")
|
350
346
|
end
|
351
347
|
end
|
352
348
|
end
|
@@ -367,29 +363,6 @@ module Smartcloud
|
|
367
363
|
end
|
368
364
|
end
|
369
365
|
|
370
|
-
# Hot reloading app containers and removing old app container
|
371
|
-
def self.hot_reloaded_app?(appname)
|
372
|
-
logger.debug "Hot reloading '#{appname}' containers ..."
|
373
|
-
|
374
|
-
container_id = `docker ps -a -q --filter='name=^#{appname}$'`.chomp
|
375
|
-
unless container_id.empty?
|
376
|
-
if system("docker container rename #{appname} #{appname}_old", [:out, :err] => File::NULL)
|
377
|
-
logger.debug "Container renamed from #{appname} #{appname}_old"
|
378
|
-
if system("docker container rename #{appname}_new #{appname}", [:out, :err] => File::NULL)
|
379
|
-
logger.debug "Container renamed from #{appname}_new #{appname}"
|
380
|
-
self.stop_app("#{appname}_old")
|
381
|
-
return true
|
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
|
-
return true
|
388
|
-
end
|
389
|
-
end
|
390
|
-
return false
|
391
|
-
end
|
392
|
-
|
393
366
|
def self.load_container_env_vars(container_path)
|
394
367
|
unless File.exist? "#{container_path}/env"
|
395
368
|
logger.fatal "Environment could not be loaded ... Failed."
|
@@ -406,6 +379,7 @@ module Smartcloud
|
|
406
379
|
true
|
407
380
|
end
|
408
381
|
|
382
|
+
# Stop Container
|
409
383
|
def self.stop_container(container_name)
|
410
384
|
if Smartcloud::Docker.running?
|
411
385
|
container_id = `docker ps -a -q --filter='name=^#{container_name}$'`.chomp
|
@@ -10,7 +10,7 @@ while read oldrev newrev refname; do
|
|
10
10
|
REPOSITORY_BASENAME=$(basename $(readlink -nf "$PWD"/..))
|
11
11
|
fi
|
12
12
|
script --quiet --return --flush --command "runner prereceive $REPOSITORY_BASENAME $REMOTE_USER $oldrev $newrev $refname" /home/$(whoami)/.smartcloud/grids/grid-runner/apps/containers/$REPOSITORY_BASENAME/typescript
|
13
|
-
if [ "$?" -eq
|
13
|
+
if [ "$?" -eq 10 ]; then
|
14
14
|
exit 0
|
15
15
|
fi
|
16
16
|
exit 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartcloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timeboard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|