harbr 0.0.69 → 0.0.71

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: 1848f4996f4de495baab3cb495d5322268fa2b241a6b730398a3eccdfdcbb14e
4
- data.tar.gz: fbea4944a710247e6bfbda103954b362fa5e263916cd59bed9f78e1f0b7d743d
3
+ metadata.gz: 78ae00a2ad38fc4706cf9587913490f8dd830474371bcf6a70a679d3c4d9ed73
4
+ data.tar.gz: ecda50fd182e1f485c601a855ef294fef77a31091a1e74680bc28a3f24ffea23
5
5
  SHA512:
6
- metadata.gz: 9ab00982214a62f82d3d7d718aec943db7b5c5056f0ee76f14c8b7c5abc51818492a83bf135b2017044591cf92e6f13984ca20c7250effbd67b309e52dbfafcc
7
- data.tar.gz: 971444bd9f9f62e2f370a2df122c800df01841182780a55d8e44cc73f4203fffb7c25c1777296fac1bcbc8b65631dab3a56df0091e2811a30c7b3f4dd812534f
6
+ metadata.gz: 21c963f4516ec87c577f3300c5c7d6911b5524ba19d3faf83a0e5208f5e2b720213cff513c03db3082af55ddf12cbf4bbfd5f8b61d412ad6895b0cb968f3fd7f
7
+ data.tar.gz: cc459e1ad581af6915b874ce00147d08daded9f60e5ac060a4a0d2a032b57369732b29367a760dfd08450eee7960cc62a08eca6f320a88d1edac03bc66d42652
data/lib/harbr/job.rb CHANGED
@@ -106,6 +106,7 @@ module Harbr
106
106
  end
107
107
 
108
108
  system("cd /var/harbr/#{manifest.name}/current && bundle install")
109
+ puts `lsof -i :#{port} | awk 'NR!=1 {print $2}' | xargs kill -9`
109
110
  system("sv restart #{manifest.name}")
110
111
  puts "Started container: #{manifest.name}"
111
112
  create_traefik_config(containers.all)
@@ -2,14 +2,14 @@ module Harbr
2
2
  module Next
3
3
  class Job
4
4
  include SuckerPunch::Job
5
-
6
- def load_manifest(container,version)
5
+
6
+ def load_manifest(container, version)
7
7
  manifest_path = "/var/harbr/#{container}/versions/#{version}/config/manifest.yml"
8
8
  raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
9
9
  manifest_data = YAML.load_file(manifest_path)
10
10
  OpenStruct.new(manifest_data)
11
11
  end
12
-
12
+
13
13
  def create_traefik_config(containers)
14
14
  config = {
15
15
  "http" => {
@@ -22,10 +22,10 @@ module Harbr
22
22
  "services" => {}
23
23
  }
24
24
  }
25
-
25
+
26
26
  containers.each do |container|
27
27
  container.ip = "127.0.0.1"
28
-
28
+
29
29
  config["http"]["routers"]["#{container.name}-router"] = {
30
30
  "rule" => "Host(`#{container.host_header}`)",
31
31
  "service" => "#{container.name}-service"
@@ -36,86 +36,93 @@ module Harbr
36
36
  }
37
37
  }
38
38
  end
39
-
39
+
40
40
  File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
41
41
  puts "Traefik configuration written to /etc/traefik/harbr.toml"
42
42
  end
43
-
44
- def create_run_script(container_name, port)
45
43
 
44
+ def create_run_script(container_name, port)
46
45
  service_dir = "/etc/sv/harbr/#{container_name}/next"
47
-
46
+
48
47
  script_template = <<~SCRIPT
49
48
  #!/bin/sh
50
49
  exec 2>&1
51
50
  cd /var/harbr/#{container_name}/next
52
51
  exec ./exe/run #{port}
53
52
  SCRIPT
54
-
53
+
55
54
  service_dir = "/etc/sv/harbr/#{container_name}/next"
56
55
  FileUtils.mkdir_p(service_dir)
57
-
56
+
58
57
  File.write("#{service_dir}/run", script_template)
59
58
  FileUtils.chmod("+x", "#{service_dir}/run")
60
59
  puts "Run script created and made executable for container: next.#{container_name}"
61
60
  end
62
-
61
+
63
62
  def create_log_script(container_name)
64
63
  log_dir = "/var/log/harbr/#{container_name}/next"
65
-
64
+
66
65
  FileUtils.mkdir_p(log_dir)
67
-
66
+
68
67
  script_template = <<~SCRIPT
69
68
  #!/bin/sh
70
69
  exec svlogd -tt #{log_dir}/
71
70
  SCRIPT
72
-
71
+
73
72
  dir_path = "/etc/sv/harbr/#{container_name}/next/log"
74
73
  FileUtils.mkdir_p(dir_path)
75
-
74
+
76
75
  File.write("#{dir_path}/run", script_template)
77
76
  FileUtils.chmod("+x", "#{dir_path}/run")
78
77
  puts "Log script created and made executable for container: next.#{container_name}"
79
78
  end
80
-
81
79
  def create_a_service(container_name, port)
82
80
  create_run_script(container_name, port)
83
81
  create_log_script(container_name)
82
+
84
83
  system("ln -s /etc/sv/harbr/#{container_name}/next /etc/service/next.#{container_name}") unless File.exist?("/etc/service/next.#{container_name}")
85
84
  end
86
-
85
+
87
86
  def run_container(manifest)
88
87
  puts "Starting container: next.#{manifest.name}"
89
- port = `port assign next.#{manifest.port}`.strip
88
+ port = `port assign next.#{manifest.port}"`.strip
89
+ puts "Port assigned: #{port}"
90
90
 
91
- create_a_service(manifest.name, port)
91
+ puts `lsof -i :#{port} | awk 'NR!=1 {print $2}' | xargs kill -9`
92
+
93
+ `rm -rf /etc/sv/harbr/#{manifest.name}/next`
94
+ system("ln -s /var/harbr/#{manifest.name}/versions/#{manifest.version}/ /etc/sv/harbr/#{manifest.name}/next")
95
+ puts "Linked to: /etc/sv/harbr/#{manifest.name}/next"
92
96
 
97
+ create_a_service(manifest.name, port)
98
+
93
99
  containers = Container::Repository.new
94
100
  container = containers.find_by_header("next.#{manifest.host}")
95
-
101
+
96
102
  if container.nil?
97
- container = Container.new
103
+ container = Container.new
98
104
  container.name = "next.#{manifest.name}"
99
105
  container.host_header = "next.#{manifest.host}"
100
106
  container.ip = "127.0.0.1"
101
107
  container.port = port
102
108
  containers.create(container)
103
109
  else
104
- container.port = port
105
- containers.update(container)
110
+ container.port = port
111
+ containers.update(container)
106
112
  end
107
-
108
- system("cd /var/harbr/#{manifest.name}/next && bundle install")
113
+
114
+
115
+
116
+ system("cd /var/harbr/#{manifest.name}/next && bundle install")
109
117
  system("sv restart next.#{manifest.name}")
110
118
  puts "Started container: next.#{manifest.name}"
111
119
  create_traefik_config(containers.all)
112
120
  end
113
-
121
+
114
122
  def perform(container, version)
115
123
  puts "Running tasks for container: 'next.#{container}', Version: '#{version}'"
116
124
  manifest = load_manifest(container, version)
117
125
  puts "Manifest: #{manifest}"
118
- system("ln -sf /var/harbr/#{container}/versions/#{version} /var/harbr/#{container}/next")
119
126
  run_container(manifest)
120
127
  end
121
128
  end
data/lib/harbr/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Harbr
4
- VERSION = "0.0.69"
4
+ VERSION = "0.0.71"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harbr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.69
4
+ version: 0.0.71
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delaney Kuldvee Burke