harbr 0.1.41 → 0.1.42
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/exe/harbr +2 -2
- data/lib/harbr/job.rb +111 -84
- data/lib/harbr/version.rb +1 -1
- data/lib/harbr.rb +0 -1
- metadata +1 -2
- data/lib/harbr/next/job.rb +0 -249
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4a81834b6e281138d670063f16e6ce3aef3ba2a4c611126c5769f7a800c6a43
|
4
|
+
data.tar.gz: '09c9cb7ba2a44b1d61282c05c63d5cf6a9ea96711d063805268b15fbee0b4569'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11e9eb1bc37ab2095afcac4509521c414d38c7b40fbe0215d9e035d0bfda830999b9c210576cf8dea4903ad35e13bb8062eeb6c5eb2cdeb4f9a7b4fa6e4008c9
|
7
|
+
data.tar.gz: 1ecaed7982e06159ef3a16956754fc8d5c677c4ffa40548852a5685a36ab68971d22f317455fa27d01794118d14be762e6ea8caf832dbc73160e86f3ff81ca17
|
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,
|
95
|
+
Harbr::Job.perform_async(container, versio,"live")
|
96
96
|
else
|
97
97
|
sleep 3
|
98
|
-
Harbr::
|
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,9 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "ostruct"
|
3
|
+
require "sucker_punch"
|
1
4
|
require "harbr"
|
5
|
+
require "tomlrb"
|
6
|
+
|
2
7
|
module Harbr
|
3
8
|
class Job
|
4
9
|
include SuckerPunch::Job
|
@@ -10,13 +15,7 @@ module Harbr
|
|
10
15
|
def create_traefik_config(containers)
|
11
16
|
config = {
|
12
17
|
"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
|
-
},
|
18
|
+
"routers" => {},
|
20
19
|
"services" => {}
|
21
20
|
}
|
22
21
|
}
|
@@ -25,18 +24,16 @@ module Harbr
|
|
25
24
|
container.ip = "127.0.0.1"
|
26
25
|
name = container.name.tr(".", "-")
|
27
26
|
|
28
|
-
# Create the router with TLS enabled and specific format
|
29
27
|
router_key = "#{name}-router-secure"
|
30
28
|
config["http"]["routers"][router_key] = {
|
31
29
|
"rule" => "Host(`#{container.host_header}`)",
|
32
30
|
"service" => "#{name}-service",
|
33
31
|
"entryPoints" => ["https"],
|
34
32
|
"tls" => {
|
35
|
-
"certResolver" => "myresolver"
|
33
|
+
"certResolver" => "myresolver"
|
36
34
|
}
|
37
35
|
}
|
38
36
|
|
39
|
-
# Create the service
|
40
37
|
config["http"]["services"]["#{name}-service"] = {
|
41
38
|
"loadBalancer" => {
|
42
39
|
"servers" => [{"url" => "http://#{container.ip}:#{container.port}"}]
|
@@ -44,7 +41,6 @@ module Harbr
|
|
44
41
|
}
|
45
42
|
end
|
46
43
|
|
47
|
-
# Write the configuration to a TOML file
|
48
44
|
File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
|
49
45
|
puts "Traefik configuration written to /etc/traefik/harbr.toml"
|
50
46
|
end
|
@@ -64,99 +60,130 @@ module Harbr
|
|
64
60
|
container.port = port
|
65
61
|
containers.update(container)
|
66
62
|
end
|
63
|
+
|
67
64
|
containers.all
|
68
65
|
end
|
69
66
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
@container_name = container
|
74
|
-
@port = port
|
75
|
-
end
|
67
|
+
def write_to_file(path, contents)
|
68
|
+
File.write(path, contents)
|
69
|
+
end
|
76
70
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
exec 2>&1
|
81
|
-
cd /var/harbr/containers/#{@container_name}/current
|
82
|
-
exec ./exe/run #{@port} live
|
83
|
-
SCRIPT
|
84
|
-
end
|
71
|
+
def load_manifest(container, version)
|
72
|
+
manifest_path = "/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml"
|
73
|
+
raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
|
85
74
|
|
86
|
-
|
87
|
-
|
88
|
-
|
75
|
+
manifest_data = YAML.load_file(manifest_path)
|
76
|
+
OpenStruct.new(manifest_data)
|
77
|
+
end
|
78
|
+
|
79
|
+
def perform(name, version, env)
|
80
|
+
Harbr.notifiable(name, version) do
|
81
|
+
manifest = load_manifest(name, version)
|
82
|
+
port = `port assign #{env}.#{manifest.port}`.strip
|
83
|
+
|
84
|
+
current_path = "/var/harbr/containers/#{name}/versions/#{version}"
|
85
|
+
check_dir_exists(current_path)
|
86
|
+
|
87
|
+
process_container(name, version, port, env, manifest)
|
89
88
|
end
|
89
|
+
end
|
90
90
|
|
91
|
-
|
92
|
-
def initialize(port)
|
93
|
-
@port = port
|
94
|
-
end
|
91
|
+
private
|
95
92
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
93
|
+
def check_dir_exists(path)
|
94
|
+
sleep_times = [1, 3, 5, 8, 23]
|
95
|
+
begin
|
96
|
+
sleep_times.each do |time|
|
97
|
+
return if Dir.exist?(path)
|
98
|
+
sleep(time)
|
102
99
|
end
|
100
|
+
raise "Directory not found: #{path}"
|
101
|
+
rescue => e
|
102
|
+
puts "Error: #{e.message}"
|
103
103
|
end
|
104
|
+
end
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
def process_container(name, version, port, env, manifest)
|
107
|
+
env_path = "/var/harbr/containers/#{name}/#{env}"
|
108
|
+
system "sv stop #{env}.#{name}" if env == 'next'
|
109
|
+
|
110
|
+
bundle_install_if_needed(env_path)
|
111
|
+
create_runit_scripts(name, port, env)
|
112
|
+
link_directories(name, version, env)
|
113
|
+
sync_live_data_if_next(name) if env == 'next'
|
109
114
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
+
containers = collate_containers("#{env}.#{name}", "#{env}.#{manifest.host}", port)
|
116
|
+
create_traefik_config(containers)
|
117
|
+
puts "harbr: #{version} of #{name} in #{env} environment"
|
118
|
+
end
|
119
|
+
|
120
|
+
def bundle_install_if_needed(path)
|
121
|
+
Dir.chdir(path) do
|
122
|
+
if File.exist?("Gemfile")
|
123
|
+
`bundle config set --local path 'vendor/bundle'`
|
124
|
+
system "bundle install"
|
115
125
|
end
|
116
126
|
end
|
117
127
|
end
|
118
128
|
|
119
|
-
def
|
120
|
-
|
129
|
+
def create_runit_scripts(name, port, env)
|
130
|
+
run_script = Runit::Script.new(name, port, env).run_script
|
131
|
+
finish_script = Runit::Script.new(name, port, env).finish_script
|
132
|
+
log_script = Runit::Script.new(name, port, env).log_script
|
133
|
+
|
134
|
+
write_to_file "/etc/sv/harbr/#{name}/#{env}/run", run_script
|
135
|
+
write_to_file "/etc/sv/harbr/#{name}/#{env}/finish", finish_script
|
136
|
+
write_to_file "/etc/sv/harbr/#{name}/#{env}/log/run", log_script
|
137
|
+
|
138
|
+
`chmod +x /etc/sv/harbr/#{name}/#{env}/run`
|
139
|
+
`chmod +x /etc/sv/harbr/#{name}/#{env}/log/run`
|
140
|
+
`chmod +x /etc/sv/harbr/#{name}/#{env}/finish`
|
121
141
|
end
|
122
142
|
|
123
|
-
def
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
143
|
+
def link_directories(name, version, env)
|
144
|
+
`rm -f /etc/service/#{env}.#{name}`
|
145
|
+
`rm -f /var/harbr/containers/#{name}/#{env}`
|
146
|
+
|
147
|
+
`ln -sf /var/harbr/containers/#{name}/versions/#{version} /var/harbr/containers/#{name}/#{env}`
|
148
|
+
`ln -sf /etc/sv/harbr/#{name}/#{env} /etc/service/#{env}.#{name}`
|
128
149
|
end
|
129
150
|
|
130
|
-
def
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
151
|
+
def sync_live_data_if_next(name)
|
152
|
+
`rsync -av /var/dddr/#{name}/live /var/dddr/#{name}/next`
|
153
|
+
puts "sync live data to next"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
module Runit
|
158
|
+
class Script
|
159
|
+
def initialize(container, port, env)
|
160
|
+
@container_name = container
|
161
|
+
@port = port
|
162
|
+
@env = env
|
163
|
+
end
|
164
|
+
|
165
|
+
def run_script
|
166
|
+
<<~SCRIPT
|
167
|
+
#!/bin/sh
|
168
|
+
exec 2>&1
|
169
|
+
cd /var/harbr/containers/#{@container_name}/#{@env}
|
170
|
+
exec ./exe/run #{@port} #{@env}
|
171
|
+
SCRIPT
|
172
|
+
end
|
173
|
+
|
174
|
+
def finish_script
|
175
|
+
<<~SCRIPT
|
176
|
+
#!/bin/sh
|
177
|
+
sleep 3
|
178
|
+
`lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
|
179
|
+
SCRIPT
|
180
|
+
end
|
181
|
+
|
182
|
+
def log_script
|
183
|
+
<<~SCRIPT
|
184
|
+
#!/bin/sh
|
185
|
+
exec svlogd -tt /var/log/harbr/#{@container_name}/#{@env}/
|
186
|
+
SCRIPT
|
160
187
|
end
|
161
188
|
end
|
162
189
|
end
|
data/lib/harbr/version.rb
CHANGED
data/lib/harbr.rb
CHANGED
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.
|
4
|
+
version: 0.1.42
|
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
|
data/lib/harbr/next/job.rb
DELETED
@@ -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
|