smartcloud 0.0.206 → 0.1.0

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: 6c62081c62d76faea905c0502e283247123f433d020ae50d47f50dfb1416c293
4
- data.tar.gz: 91bc5b352f3f2c87c23aa7e6d65fdde68acb7994f7fad982374456556bf09689
3
+ metadata.gz: aa2a3f8c929555cb37a5587ddbcf00af3e266afecc59442cdfe7c6c445d5a81b
4
+ data.tar.gz: be14f3480b057ccc010c596665313dbbd5d7e6a5aec6098b7a8225b142f5cbea
5
5
  SHA512:
6
- metadata.gz: 6ec10636c50c3aa415047521e5e1e4712a21c4497f565d65f55cc3a9a34cb14990cf29067c0994dd3d51e67b32a01b48f4c60c96eaa2fa2f6c34536817c24282
7
- data.tar.gz: a140bbac432112aaf0e33020612238ff2f11a24242ecf22a17bb28930934af23eea383d15b5c88e9cce1d08d1fa3de5c4cf6d5a5dded857e7f1c66b63bcfe183
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
- return unless bundle_install?
21
- return unless precompile_assets?
22
- return unless start_web_server?
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
- exit 0
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 starting of web server
68
- def start_web_server?
69
- logger.debug "Starting Web Server ..."
70
-
71
- # Remove server.pid if it exists
72
- FileUtils.rm("tmp/pids/server.pid") if File.exist? "tmp/pids/server.pid"
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
- # if system("god -c Godfile -D")
75
- return true
76
- # end
77
- # return false
102
+ # Return status
103
+ return status
78
104
  end
79
105
 
80
106
  def set_logger_formatter_arrow
@@ -1,5 +1,5 @@
1
1
  FROM ruby:2.6.4-alpine3.10
2
- MAINTAINER Timeboard <hello@timeboard.me>
2
+ LABEL maintainer="Timeboard <hello@timeboard.me>"
3
3
 
4
4
  # User
5
5
  # --- Fix to change gid of 999 to 99 so that addgroup is free to create a group with 999 as gid
@@ -24,7 +24,6 @@ WORKDIR "/app"
24
24
 
25
25
  # Gems
26
26
  RUN gem install smartcloud && \
27
- gem install bundler && \
28
- gem install god
27
+ gem install bundler
29
28
 
30
29
  CMD ["buildpacker", "start"]
@@ -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
- self.stop_app("#{appname}_new")
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='#{appname}_new' \
318
+ --name='#{new_container}' \
328
319
  --env-file='#{container_path}/env' \
329
- --expose='5000' \
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 #{appname}_new")
340
- system("docker network connect mysql-network #{appname}_new")
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 #{appname}_new")
343
- if self.hot_reloaded_app?(appname)
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 0
342
+ exit 10
347
343
  end
348
344
  else
349
- self.stop_app("#{appname}_new")
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 0 ]; then
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.206
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-04 00:00:00.000000000 Z
11
+ date: 2019-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh