harbr 0.1.41 → 0.1.43

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: 961d2fcd8bbf17593359f10c94fedb0dea4ee66ddd63847e5aa4b22d26b7e2ba
4
- data.tar.gz: 8bd0be2d101562f224e8101556514eea70fc9cf31b74b6bd838df08a79059736
3
+ metadata.gz: '076794bdda8b2767ab64cc26a50c05c1b3a7a750a61b03450195fda508f505c5'
4
+ data.tar.gz: 4147dc377d4417377ff8fa34bd07eb80f78ea7ffb7047c53b115311db3eed8d9
5
5
  SHA512:
6
- metadata.gz: 714bd9940f1cfdacfa242567adbe006470c919c50c31669f03f32c60a28a9ef0b45bfdb8834605ddfcea6157716ba0486f5686183584f098788a8bafe2602db6
7
- data.tar.gz: 7e800f4514d06701ced3a12a359458201be7ad2b5c51c2cf5603e9a34a6eef1ec18f34e5b616bd14cddaaca0c5f672df3150739da120b2c82ed1fc3641822cd2
6
+ metadata.gz: fba0915b058562945a4763d8fde2e9b57bc6e261d2054f94fb61410420eac617e54d0b78c4cc6a984c2dcfda4675a7ba5bcc24f21a0b33e36b118425ff189c54
7
+ data.tar.gz: 43119cdff5e63886109274a90d01e95657fb8e5fe914b8e6e03b071e9c84d6323607ccaf05775720e22855d1075cf25698dbd29a8acfda166f341ec7b17cf9b2
data/exe/harbr CHANGED
@@ -92,10 +92,10 @@ class HarbrCLI < Thor
92
92
  Dir.exist?("/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml")
93
93
  end
94
94
 
95
- Harbr::Job.perform_async(container, version)
95
+ Harbr::Job.perform_async(container, versio,"live")
96
96
  else
97
97
  sleep 3
98
- Harbr::Next::Job.perform_async(container, version)
98
+ Harbr::Job.perform_async(container, version,"next")
99
99
  puts "deploy next version #{version} of #{container}"
100
100
  end
101
101
 
data/lib/harbr/job.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "harbr"
2
1
  module Harbr
3
2
  class Job
4
3
  include SuckerPunch::Job
@@ -10,13 +9,7 @@ module Harbr
10
9
  def create_traefik_config(containers)
11
10
  config = {
12
11
  "http" => {
13
- "routers" => {
14
- "traefik-dashboard" => {
15
- "rule" => "Host(`traefik.harbr.zero2one.ee`)",
16
- "service" => "api@internal",
17
- "tls" => {} # Enable TLS for the dashboard
18
- }
19
- },
12
+ "routers" => {},
20
13
  "services" => {}
21
14
  }
22
15
  }
@@ -25,18 +18,16 @@ module Harbr
25
18
  container.ip = "127.0.0.1"
26
19
  name = container.name.tr(".", "-")
27
20
 
28
- # Create the router with TLS enabled and specific format
29
21
  router_key = "#{name}-router-secure"
30
22
  config["http"]["routers"][router_key] = {
31
23
  "rule" => "Host(`#{container.host_header}`)",
32
24
  "service" => "#{name}-service",
33
25
  "entryPoints" => ["https"],
34
26
  "tls" => {
35
- "certResolver" => "myresolver" # Use a custom certificate resolver
27
+ "certResolver" => "myresolver"
36
28
  }
37
29
  }
38
30
 
39
- # Create the service
40
31
  config["http"]["services"]["#{name}-service"] = {
41
32
  "loadBalancer" => {
42
33
  "servers" => [{"url" => "http://#{container.ip}:#{container.port}"}]
@@ -44,7 +35,6 @@ module Harbr
44
35
  }
45
36
  end
46
37
 
47
- # Write the configuration to a TOML file
48
38
  File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
49
39
  puts "Traefik configuration written to /etc/traefik/harbr.toml"
50
40
  end
@@ -64,99 +54,130 @@ module Harbr
64
54
  container.port = port
65
55
  containers.update(container)
66
56
  end
57
+
67
58
  containers.all
68
59
  end
69
60
 
70
- module Runit
71
- class Run
72
- def initialize(container, port)
73
- @container_name = container
74
- @port = port
75
- end
61
+ def write_to_file(path, contents)
62
+ File.write(path, contents)
63
+ end
76
64
 
77
- def to_s
78
- <<~SCRIPT
79
- #!/bin/sh
80
- exec 2>&1
81
- cd /var/harbr/containers/#{@container_name}/current
82
- exec ./exe/run #{@port} live
83
- SCRIPT
84
- end
65
+ def load_manifest(container, version)
66
+ manifest_path = "/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml"
67
+ raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
85
68
 
86
- def link
87
- "ln -s /etc/sv/harbr/#{@container_name} /etc/service/#{@container_name}"
88
- end
69
+ manifest_data = YAML.load_file(manifest_path)
70
+ OpenStruct.new(manifest_data)
71
+ end
72
+
73
+ def perform(name, version, env)
74
+ Harbr.notifiable(name, version) do
75
+ manifest = load_manifest(name, version)
76
+ port = `port assign #{env}.#{manifest.port}`.strip
77
+
78
+ current_path = "/var/harbr/containers/#{name}/versions/#{version}"
79
+ check_dir_exists(current_path)
80
+
81
+ process_container(name, version, port, env, manifest)
89
82
  end
83
+ end
90
84
 
91
- class Finish
92
- def initialize(port)
93
- @port = port
94
- end
85
+ private
95
86
 
96
- def to_s
97
- <<~SCRIPT
98
- #!/bin/sh
99
- sleep 3
100
- `lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
101
- SCRIPT
87
+ def check_dir_exists(path)
88
+ sleep_times = [1, 3, 5, 8, 23]
89
+ begin
90
+ sleep_times.each do |time|
91
+ return if Dir.exist?(path)
92
+ sleep(time)
102
93
  end
94
+ raise "Directory not found: #{path}"
95
+ rescue => e
96
+ puts "Error: #{e.message}"
103
97
  end
98
+ end
104
99
 
105
- class Log
106
- def initialize(container)
107
- @container_name = container
108
- end
100
+ def process_container(name, version, port, env, manifest)
101
+ env_path = "/var/harbr/containers/#{name}/#{env}"
102
+ system "sv stop #{env}.#{name}" if env == 'next'
109
103
 
110
- def to_s
111
- <<~SCRIPT
112
- #!/bin/sh
113
- exec svlogd -tt /var/log/harbr/#{@container_name}
114
- SCRIPT
104
+ bundle_install_if_needed(env_path)
105
+ create_runit_scripts(name, port, env)
106
+ link_directories(name, version, env)
107
+ sync_live_data_if_next(name) if env == 'next'
108
+
109
+ containers = collate_containers("#{env}.#{name}", "#{env}.#{manifest.host}", port)
110
+ create_traefik_config(containers)
111
+ puts "harbr: #{version} of #{name} in #{env} environment"
112
+ end
113
+
114
+ def bundle_install_if_needed(path)
115
+ Dir.chdir(path) do
116
+ if File.exist?("Gemfile")
117
+ `bundle config set --local path 'vendor/bundle'`
118
+ system "bundle install"
115
119
  end
116
120
  end
117
121
  end
118
122
 
119
- def write_to_file(path, contents)
120
- File.write(path, contents)
123
+ def create_runit_scripts(name, port, env)
124
+ run_script = Runit::Script.new(name, port, env).run_script
125
+ finish_script = Runit::Script.new(name, port, env).finish_script
126
+ log_script = Runit::Script.new(name, port, env).log_script
127
+
128
+ write_to_file "/etc/sv/harbr/#{name}/#{env}/run", run_script
129
+ write_to_file "/etc/sv/harbr/#{name}/#{env}/finish", finish_script
130
+ write_to_file "/etc/sv/harbr/#{name}/#{env}/log/run", log_script
131
+
132
+ `chmod +x /etc/sv/harbr/#{name}/#{env}/run`
133
+ `chmod +x /etc/sv/harbr/#{name}/#{env}/log/run`
134
+ `chmod +x /etc/sv/harbr/#{name}/#{env}/finish`
121
135
  end
122
136
 
123
- def load_manifest(container, version)
124
- manifest_path = "/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml"
125
- raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
126
- manifest_data = YAML.load_file(manifest_path)
127
- OpenStruct.new(manifest_data)
137
+ def link_directories(name, version, env)
138
+ `rm -f /etc/service/#{env}.#{name}`
139
+ `rm -f /var/harbr/containers/#{name}/#{env}`
140
+
141
+ `ln -sf /var/harbr/containers/#{name}/versions/#{version} /var/harbr/containers/#{name}/#{env}`
142
+ `ln -sf /etc/sv/harbr/#{name}/#{env} /etc/service/#{env}.#{name}`
128
143
  end
129
144
 
130
- def perform(name, version)
131
- Harbr.notifiable(name, version) do
132
- Dir.chdir "/var/harbr/containers/#{name}/versions/#{version}" do
133
- manifest = load_manifest(name, version)
134
- port = `port assign #{manifest.port}`.strip
135
- system "sv stop #{name}" if File.exist?("/etc/service/#{name}")
136
- if File.exist?("Gemfile")
137
- `bundle config set --local path 'vendor/bundle'`
138
- system "bundle install"
139
- end
140
-
141
- `mkdir -p /etc/sv/harbr/#{name}`
142
- `mkdir -p /etc/sv/harbr/#{name}/log`
143
- `mkdir -p /var/log/harbr/#{name}`
144
-
145
- write_to_file "/etc/sv/harbr/#{name}/run", Runit::Run.new(name, port).to_s
146
- write_to_file "/etc/sv/harbr/#{name}/finish", Runit::Finish.new(port).to_s
147
- write_to_file "/etc/sv/harbr/#{name}/log/run", Runit::Log.new(name).to_s
148
-
149
- `chmod +x /etc/sv/harbr/#{name}/run`
150
- `chmod +x /etc/sv/harbr/#{name}/log/run`
151
- `chmod +x /etc/sv/harbr/#{name}/finish`
152
-
153
- system "ln -sf /var/harbr/containers/#{name}/versions/#{version} /var/harbr/containers/#{name}/current"
154
- system "ln -sf /etc/sv/harbr/#{name} /etc/service/#{name}"
155
-
156
- containers = collate_containers(name, manifest.host, port)
157
- create_traefik_config(containers)
158
- puts "process #{version} of #{name}"
159
- end
145
+ def sync_live_data_if_next(name)
146
+ `rsync -av /var/dddr/#{name}/live /var/dddr/#{name}/next`
147
+ puts "sync live data to next"
148
+ end
149
+ end
150
+
151
+ module Runit
152
+ class Script
153
+ def initialize(container, port, env)
154
+ @container_name = container
155
+ @port = port
156
+ @env = env
157
+ end
158
+
159
+ def run_script
160
+ <<~SCRIPT
161
+ #!/bin/sh
162
+ exec 2>&1
163
+ cd /var/harbr/containers/#{@container_name}/#{@env}
164
+ exec ./exe/run #{@port} #{@env}
165
+ SCRIPT
166
+ end
167
+
168
+ def finish_script
169
+ <<~SCRIPT
170
+ #!/bin/sh
171
+ sleep 3
172
+ `lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
173
+ SCRIPT
174
+ end
175
+
176
+ def log_script
177
+ <<~SCRIPT
178
+ #!/bin/sh
179
+ exec svlogd -tt /var/log/harbr/#{@container_name}/#{@env}/
180
+ SCRIPT
160
181
  end
161
182
  end
162
183
  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.1.41"
4
+ VERSION = "0.1.43"
5
5
  end
data/lib/harbr.rb CHANGED
@@ -11,7 +11,6 @@ require "resend"
11
11
  require_relative "harbr/version"
12
12
  require_relative "harbr/container"
13
13
  require_relative "harbr/job"
14
- require_relative "harbr/next/job"
15
14
 
16
15
  # Harbr module for managing containers, jobs, ports, and 2s
17
16
  module Harbr
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.1.41
4
+ version: 0.1.43
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delaney Kuldvee Burke
@@ -149,7 +149,6 @@ files:
149
149
  - lib/harbr.rb
150
150
  - lib/harbr/container.rb
151
151
  - lib/harbr/job.rb
152
- - lib/harbr/next/job.rb
153
152
  - lib/harbr/version.rb
154
153
  - sig/harbr.rbs
155
154
  - vendor/bundle/ruby/3.2.0/bin/bundle
@@ -1,249 +0,0 @@
1
- require "yaml"
2
- require "ostruct"
3
- require "sucker_punch"
4
-
5
- require "harbr"
6
- module Harbr
7
- module Next
8
- class Job
9
- include SuckerPunch::Job
10
-
11
-
12
- def check
13
- sleep_times = [1, 3, 5, 8, 23]
14
- begin
15
- result = yield if block_given?
16
- unless result
17
- sleep_times.each do |time|
18
- result = yield if block_given?
19
- break if result
20
- sleep(time)
21
- end
22
- end
23
- rescue => e
24
- puts "Error: #{e.message}"
25
- end
26
- end
27
-
28
- def get_container_name(path)
29
- File.basename(path)
30
- end
31
-
32
- def create_traefik_config(containers)
33
- config = {
34
- "http" => {
35
- "routers" => {
36
- "traefik-dashboard" => {
37
- "rule" => "Host(`traefik.harbr.zero2one.ee`)",
38
- "service" => "api@internal",
39
- "tls" => {} # Enable TLS for the dashboard
40
- }
41
- },
42
- "services" => {}
43
- }
44
- }
45
-
46
- containers.each do |container|
47
- container.ip = "127.0.0.1"
48
- name = container.name.tr(".", "-")
49
-
50
- # Create the router with TLS enabled and specific format
51
- router_key = "#{name}-router-secure"
52
- config["http"]["routers"][router_key] = {
53
- "rule" => "Host(`#{container.host_header}`)",
54
- "service" => "#{name}-service",
55
- "entryPoints" => ["https"],
56
- "tls" => {
57
- "certResolver" => "myresolver" # Use a custom certificate resolver
58
- }
59
- }
60
-
61
- # Create the service
62
- config["http"]["services"]["#{name}-service"] = {
63
- "loadBalancer" => {
64
- "servers" => [{"url" => "http://#{container.ip}:#{container.port}"}]
65
- }
66
- }
67
- end
68
-
69
- # Write the configuration to a TOML file
70
- File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
71
- puts "Traefik configuration written to /etc/traefik/harbr.toml"
72
- end
73
-
74
- def collate_containers(name, host, port)
75
- containers = Harbr::Container::Repository.new
76
- container = containers.find_by_header(host)
77
-
78
- if container.nil?
79
- container = Harbr::Container.new
80
- container.name = name
81
- container.host_header = host
82
- container.ip = "127.0.0.1"
83
- container.port = port
84
- containers.create(container)
85
- else
86
- container.port = port
87
- containers.update(container)
88
- end
89
- containers.all
90
- end
91
-
92
- module Runit
93
- class Run
94
- def initialize(container, port)
95
- @container_name = container
96
- @port = port
97
- end
98
-
99
- def to_s
100
- <<~SCRIPT
101
- #!/bin/sh
102
- exec 2>&1
103
- cd /var/harbr/#{@container_name}/current
104
- exec ./exe/run #{@port} live
105
- SCRIPT
106
- end
107
-
108
- def link
109
- "ln -s /etc/sv/harbr/#{@container_name} /etc/service/#{@container_name}"
110
- end
111
- end
112
-
113
- class Finish
114
- def initialize(port)
115
- @port = port
116
- end
117
-
118
- def to_s
119
- <<~SCRIPT
120
- #!/bin/sh
121
- sleep 3
122
- `lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
123
- SCRIPT
124
- end
125
- end
126
-
127
- class Log
128
- def initialize(container, port)
129
- @container_name = container
130
- end
131
-
132
- def to_s
133
- <<~SCRIPT
134
- #!/bin/sh
135
- exec svlogd -tt /var/log/harbr/#{@container_name}/next/
136
- SCRIPT
137
- end
138
- end
139
-
140
- module Next
141
- class Run
142
- def initialize(container, port)
143
- @container_name = container
144
- @port = port
145
- end
146
-
147
- def to_s
148
- <<~SCRIPT
149
- #!/bin/sh
150
- exec 2>&1
151
- cd /var/harbr/containers/#{@container_name}/next
152
- exec ./exe/run #{@port} next
153
- SCRIPT
154
- end
155
- end
156
-
157
- class Log
158
- def initialize(container)
159
- @container_name = container
160
- end
161
-
162
- def to_s
163
- <<~SCRIPT
164
- #!/bin/sh
165
- exec svlogd -tt /var/log/harbr/#{@container_name}/next/
166
- SCRIPT
167
- end
168
- end
169
- end
170
- end
171
-
172
- def write_to_file(path, contents)
173
- File.write(path, contents)
174
- end
175
-
176
- def load_manifest(container, version)
177
- manifest_path = "/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml"
178
- raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
179
- manifest_data = YAML.load_file(manifest_path)
180
- OpenStruct.new(manifest_data)
181
- end
182
-
183
- def check
184
- sleep_times = [1, 3, 5, 8, 23]
185
- begin
186
- result = yield if block_given?
187
- unless result
188
- sleep_times.each do |time|
189
- result = yield if block_given?
190
- break if result
191
- sleep(time)
192
- end
193
- end
194
- rescue => e
195
- puts "Error: #{e.message}"
196
- end
197
- end
198
-
199
- def perform(name, version)
200
- Harbr.notifiable(name, version) do
201
- manifest = load_manifest(name, version)
202
- current_path = "/var/harbr/containers/#{name}/versions/#{version}"
203
-
204
- port = `port assign next.#{manifest.port}`.strip
205
-
206
- check do
207
- puts "Waiting for container #{current_path} 5to be available..."
208
- Dir.exist?(current_path)
209
- end
210
-
211
- Dir.chdir current_path do
212
- system "sv stop next.#{name}"
213
- if File.exist?("Gemfile")
214
- `bundle config set --local path 'vendor/bundle'`
215
- system "bundle install"
216
- end
217
-
218
- `mkdir -p /etc/sv/harbr/#{name}/next`
219
- `mkdir -p /etc/sv/harbr/#{name}/next/log`
220
- `mkdir -p /var/log/harbr/#{name}/next/log`
221
-
222
- write_to_file "/etc/sv/harbr/#{name}/next/run", Runit::Next::Run.new(name, port).to_s
223
- write_to_file "/etc/sv/harbr/#{name}/next/finish", Runit::Finish.new(port).to_s
224
- write_to_file "/etc/sv/harbr/#{name}/next/log/run", Runit::Next::Log.new(name).to_s
225
-
226
- `chmod +x /etc/sv/harbr/#{name}/next/run`
227
- `chmod +x /etc/sv/harbr/#{name}/next/log/run`
228
- `chmod +x /etc/sv/harbr/#{name}/next/finish`
229
-
230
- system "rm /etc/service/next.#{name}"
231
- system "rm /var/harbr/containers/#{name}/next"
232
-
233
- system "ln -sf /var/harbr/containers/#{name}/versions/#{version} /var/harbr/containers/#{name}/next"
234
- system "ln -sf /etc/sv/harbr/#{name}/next /etc/service/next.#{name}"
235
-
236
- `rsync -av /var/dddr/#{name}/live /var/dddr/#{name}/next`
237
- puts "sync live data to next"
238
-
239
- system "sv restart next.#{name}"
240
- end
241
-
242
- containers = collate_containers("next.#{name}", "next.#{manifest.host}", port)
243
- create_traefik_config(containers)
244
- puts "harbr: #{version} of #{name} into next environment"
245
- end
246
- end
247
- end
248
- end
249
- end