harbr 0.1.9 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/harbr/job.rb +45 -37
- data/lib/harbr/next/job.rb +68 -59
- data/lib/harbr/version.rb +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: 0ed38a4498af70d36cfd5442fc1fb1d77ae2de56466a0d2998a031090986c39d
|
4
|
+
data.tar.gz: 5cc03945ce54b81bf6f9dff07182906892e34b6338a1aa107452e766cb4357ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aa54b35eeaaa6e3740a3d5eab5da75dca9ec8da8948041f85cb0048799777fa3beb157b63942f53b4dd19583c59dd434b396c45a72949c79b72d398940121b7
|
7
|
+
data.tar.gz: 1872036214b4260836cb321291a6fa8575c8267a51ce16a04a800c51ec140b5dfa12f7add532a810d5d7edae26c5deb1465cd831130a0f7fc0e919775a83d8bb
|
data/lib/harbr/job.rb
CHANGED
@@ -7,11 +7,11 @@ module Harbr
|
|
7
7
|
directories = Dir.glob("#{path}/*").select { |entry| File.directory?(entry) }
|
8
8
|
directories.max_by { |entry| entry[/\d+/].to_i }
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def get_container_name(path)
|
12
12
|
File.basename(path)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
|
16
16
|
def create_traefik_config(containers)
|
17
17
|
config = {
|
@@ -19,37 +19,45 @@ module Harbr
|
|
19
19
|
"routers" => {
|
20
20
|
"traefik-dashboard" => {
|
21
21
|
"rule" => "Host(`traefik.harbr.zero2one.ee`)",
|
22
|
-
"service" => "api@internal"
|
22
|
+
"service" => "api@internal",
|
23
|
+
"tls" => {} # Enable TLS for the dashboard
|
23
24
|
}
|
24
25
|
},
|
25
26
|
"services" => {}
|
26
27
|
}
|
27
28
|
}
|
28
|
-
|
29
|
+
|
29
30
|
containers.each do |container|
|
30
31
|
container.ip = "127.0.0.1"
|
31
|
-
name = container.name.gsub(".","-")
|
32
|
-
|
32
|
+
name = container.name.gsub(".", "-")
|
33
|
+
|
34
|
+
# Create the router with TLS enabled
|
33
35
|
config["http"]["routers"]["#{name}-router"] = {
|
34
36
|
"rule" => "Host(`#{container.host_header}`)",
|
35
|
-
"service" => "#{name}-service"
|
37
|
+
"service" => "#{name}-service",
|
38
|
+
"tls" => {
|
39
|
+
"certResolver" => "letsencrypt" # Specify the certificate resolver for TLS
|
40
|
+
}
|
36
41
|
}
|
42
|
+
|
43
|
+
# Create the service
|
37
44
|
config["http"]["services"]["#{name}-service"] = {
|
38
45
|
"loadBalancer" => {
|
39
46
|
"servers" => [{"url" => "http://#{container.ip}:#{container.port}"}]
|
40
47
|
}
|
41
48
|
}
|
42
49
|
end
|
43
|
-
|
50
|
+
|
51
|
+
|
44
52
|
File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
|
45
53
|
puts "Traefik configuration written to /etc/traefik/harbr.toml"
|
46
54
|
end
|
47
|
-
|
55
|
+
|
48
56
|
def collate_containers(name,host,port)
|
49
|
-
|
57
|
+
|
50
58
|
containers = Harbr::Container::Repository.new
|
51
59
|
container = containers.find_by_header(host)
|
52
|
-
|
60
|
+
|
53
61
|
if container.nil?
|
54
62
|
container = Harbr::Container.new
|
55
63
|
container.name = name
|
@@ -63,67 +71,67 @@ module Harbr
|
|
63
71
|
end
|
64
72
|
containers.all
|
65
73
|
end
|
66
|
-
|
67
|
-
|
74
|
+
|
75
|
+
|
68
76
|
module Runit
|
69
|
-
|
77
|
+
|
70
78
|
class Run
|
71
79
|
def initialize(container, port)
|
72
80
|
@container_name = container
|
73
81
|
@port = port
|
74
82
|
end
|
75
|
-
|
83
|
+
|
76
84
|
def to_s
|
77
85
|
script_template = <<~SCRIPT
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
86
|
+
#!/bin/sh
|
87
|
+
exec 2>&1
|
88
|
+
cd /var/harbr/containers/#{@container_name}/current
|
89
|
+
exec ./exe/run #{@port} live
|
82
90
|
SCRIPT
|
83
91
|
end
|
84
|
-
|
92
|
+
|
85
93
|
def link
|
86
94
|
"ln -s /etc/sv/harbr/#{@container_name} /etc/service/#{@container_name}"
|
87
95
|
end
|
88
96
|
end
|
89
|
-
|
90
|
-
|
97
|
+
|
98
|
+
|
91
99
|
class Finish
|
92
100
|
def initialize(port)
|
93
101
|
@port = port
|
94
102
|
end
|
95
|
-
|
103
|
+
|
96
104
|
def to_s
|
97
105
|
script_template = <<~SCRIPT
|
98
|
-
|
99
|
-
|
100
|
-
|
106
|
+
#!/bin/sh
|
107
|
+
sleep 3
|
108
|
+
`lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
|
101
109
|
SCRIPT
|
102
110
|
end
|
103
111
|
end
|
104
|
-
|
112
|
+
|
105
113
|
class Log
|
106
114
|
def initialize(container)
|
107
115
|
@container_name = container
|
108
116
|
end
|
109
|
-
|
117
|
+
|
110
118
|
def to_s
|
111
119
|
script_template = <<~SCRIPT
|
112
|
-
|
113
|
-
|
120
|
+
#!/bin/sh
|
121
|
+
exec svlogd -tt /var/log/harbr/#{@container_name}
|
114
122
|
SCRIPT
|
115
123
|
end
|
116
|
-
|
124
|
+
|
117
125
|
end
|
118
|
-
|
126
|
+
|
119
127
|
end
|
120
|
-
|
128
|
+
|
121
129
|
def write_to_file(path, contents)
|
122
130
|
File.open(path, 'w') do |file|
|
123
131
|
file.write(contents)
|
124
132
|
end
|
125
133
|
end
|
126
|
-
|
134
|
+
|
127
135
|
def load_manifest(container, version)
|
128
136
|
manifest_path = "/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml"
|
129
137
|
raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
|
@@ -132,7 +140,7 @@ module Harbr
|
|
132
140
|
end
|
133
141
|
|
134
142
|
def perform(name,version)
|
135
|
-
|
143
|
+
|
136
144
|
Dir.chdir "/var/harbr/containers/#{name}/versions/#{version}" do
|
137
145
|
|
138
146
|
`bundle config set --local path 'vendor/bundle'`
|
@@ -141,11 +149,11 @@ module Harbr
|
|
141
149
|
system "sv stop #{name}" if File.exist?("/etc/service/#{name}")
|
142
150
|
system 'bundle install'
|
143
151
|
|
144
|
-
|
152
|
+
|
145
153
|
`mkdir -p /etc/sv/harbr/#{name}`
|
146
154
|
`mkdir -p /etc/sv/harbr/#{name}/log`
|
147
155
|
`mkdir -p /var/log/harbr/#{name}`
|
148
|
-
|
156
|
+
|
149
157
|
write_to_file "/etc/sv/harbr/#{name}/run", Runit::Run.new(name, port).to_s
|
150
158
|
write_to_file "/etc/sv/harbr/#{name}/finish", Runit::Finish.new(port).to_s
|
151
159
|
write_to_file "/etc/sv/harbr/#{name}/log/run", Runit::Log.new(name).to_s
|
data/lib/harbr/next/job.rb
CHANGED
@@ -16,45 +16,54 @@ module Harbr
|
|
16
16
|
def get_container_name(path)
|
17
17
|
File.basename(path)
|
18
18
|
end
|
19
|
-
|
20
|
-
|
19
|
+
|
20
|
+
|
21
|
+
|
21
22
|
def create_traefik_config(containers)
|
22
23
|
config = {
|
23
24
|
"http" => {
|
24
25
|
"routers" => {
|
25
26
|
"traefik-dashboard" => {
|
26
27
|
"rule" => "Host(`traefik.harbr.zero2one.ee`)",
|
27
|
-
"service" => "api@internal"
|
28
|
+
"service" => "api@internal",
|
29
|
+
"tls" => {} # Enable TLS for the dashboard
|
28
30
|
}
|
29
31
|
},
|
30
32
|
"services" => {}
|
31
33
|
}
|
32
34
|
}
|
33
|
-
|
35
|
+
|
34
36
|
containers.each do |container|
|
35
37
|
container.ip = "127.0.0.1"
|
36
|
-
name = container.name.gsub(".","-")
|
37
|
-
|
38
|
+
name = container.name.gsub(".", "-")
|
39
|
+
|
40
|
+
# Create the router with TLS enabled
|
38
41
|
config["http"]["routers"]["#{name}-router"] = {
|
39
42
|
"rule" => "Host(`#{container.host_header}`)",
|
40
|
-
"service" => "#{name}-service"
|
43
|
+
"service" => "#{name}-service",
|
44
|
+
"tls" => {
|
45
|
+
"certResolver" => "letsencrypt" # Specify the certificate resolver for TLS
|
46
|
+
}
|
41
47
|
}
|
48
|
+
|
49
|
+
# Create the service
|
42
50
|
config["http"]["services"]["#{name}-service"] = {
|
43
51
|
"loadBalancer" => {
|
44
52
|
"servers" => [{"url" => "http://#{container.ip}:#{container.port}"}]
|
45
53
|
}
|
46
54
|
}
|
47
55
|
end
|
48
|
-
|
56
|
+
|
49
57
|
File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
|
50
58
|
puts "Traefik configuration written to /etc/traefik/harbr.toml"
|
59
|
+
|
51
60
|
end
|
52
|
-
|
61
|
+
|
53
62
|
def collate_containers(name,host,port)
|
54
|
-
|
63
|
+
|
55
64
|
containers = Harbr::Container::Repository.new
|
56
65
|
container = containers.find_by_header(host)
|
57
|
-
|
66
|
+
|
58
67
|
if container.nil?
|
59
68
|
container = Harbr::Container.new
|
60
69
|
container.name = name
|
@@ -68,99 +77,99 @@ module Harbr
|
|
68
77
|
end
|
69
78
|
containers.all
|
70
79
|
end
|
71
|
-
|
72
|
-
|
80
|
+
|
81
|
+
|
73
82
|
module Runit
|
74
|
-
|
83
|
+
|
75
84
|
class Run
|
76
85
|
def initialize(container, port)
|
77
86
|
@container_name = container
|
78
87
|
@port = port
|
79
88
|
end
|
80
|
-
|
89
|
+
|
81
90
|
def to_s
|
82
91
|
script_template = <<~SCRIPT
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
92
|
+
#!/bin/sh
|
93
|
+
exec 2>&1
|
94
|
+
cd /var/harbr/#{@container_name}/current
|
95
|
+
exec ./exe/run #{@port} live
|
87
96
|
SCRIPT
|
88
97
|
end
|
89
|
-
|
98
|
+
|
90
99
|
def link
|
91
100
|
"ln -s /etc/sv/harbr/#{@container_name} /etc/service/#{@container_name}"
|
92
101
|
end
|
93
102
|
end
|
94
|
-
|
95
|
-
|
103
|
+
|
104
|
+
|
96
105
|
class Finish
|
97
106
|
def initialize(port)
|
98
107
|
@port = port
|
99
108
|
end
|
100
|
-
|
109
|
+
|
101
110
|
def to_s
|
102
111
|
script_template = <<~SCRIPT
|
103
|
-
|
104
|
-
|
105
|
-
|
112
|
+
#!/bin/sh
|
113
|
+
sleep 3
|
114
|
+
`lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
|
106
115
|
SCRIPT
|
107
116
|
end
|
108
117
|
end
|
109
|
-
|
118
|
+
|
110
119
|
class Log
|
111
120
|
def initialize(container, port)
|
112
121
|
@container_name = container
|
113
122
|
end
|
114
|
-
|
123
|
+
|
115
124
|
def to_s
|
116
125
|
script_template = <<~SCRIPT
|
117
|
-
|
118
|
-
|
126
|
+
#!/bin/sh
|
127
|
+
exec svlogd -tt /var/log/harbr/#{@container_name}/next/
|
119
128
|
SCRIPT
|
120
129
|
end
|
121
|
-
|
130
|
+
|
122
131
|
end
|
123
|
-
|
132
|
+
|
124
133
|
module Next
|
125
|
-
|
134
|
+
|
126
135
|
class Run
|
127
136
|
def initialize(container, port)
|
128
137
|
@container_name = container
|
129
138
|
@port = port
|
130
139
|
end
|
131
|
-
|
140
|
+
|
132
141
|
def to_s
|
133
142
|
script_template = <<~SCRIPT
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
143
|
+
#!/bin/sh
|
144
|
+
exec 2>&1
|
145
|
+
cd /var/harbr/containers/#{@container_name}/next
|
146
|
+
exec ./exe/run #{@port} next
|
138
147
|
SCRIPT
|
139
148
|
end
|
140
149
|
end
|
141
|
-
|
150
|
+
|
142
151
|
class Log
|
143
152
|
def initialize(container)
|
144
153
|
@container_name = container
|
145
154
|
end
|
146
|
-
|
155
|
+
|
147
156
|
def to_s
|
148
157
|
script_template = <<~SCRIPT
|
149
|
-
|
150
|
-
|
158
|
+
#!/bin/sh
|
159
|
+
exec svlogd -tt /var/log/harbr/#{@container_name}/next/
|
151
160
|
SCRIPT
|
152
161
|
end
|
153
162
|
end
|
154
|
-
|
163
|
+
|
155
164
|
end
|
156
165
|
end
|
157
|
-
|
166
|
+
|
158
167
|
def write_to_file(path, contents)
|
159
168
|
File.open(path, 'w') do |file|
|
160
169
|
file.write(contents)
|
161
170
|
end
|
162
171
|
end
|
163
|
-
|
172
|
+
|
164
173
|
def load_manifest(container, version)
|
165
174
|
manifest_path = "/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml"
|
166
175
|
raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
|
@@ -170,46 +179,46 @@ module Harbr
|
|
170
179
|
|
171
180
|
def perform(name, version)
|
172
181
|
`bundle config set --local path 'vendor/bundle'`
|
173
|
-
|
182
|
+
|
174
183
|
manifest = load_manifest(name,version)
|
175
184
|
current_path = "/var/harbr/containers/#{name}/versions/#{version}"
|
176
|
-
|
185
|
+
|
177
186
|
port = `port assign next.#{manifest.port}`.strip
|
178
|
-
|
187
|
+
|
179
188
|
Dir.chdir current_path do
|
180
|
-
|
189
|
+
|
181
190
|
system "sv stop next.#{name}"
|
182
191
|
system "bundle install"
|
183
|
-
|
192
|
+
|
184
193
|
`mkdir -p /etc/sv/harbr/#{name}/next`
|
185
194
|
`mkdir -p /etc/sv/harbr/#{name}/next/log`
|
186
195
|
`mkdir -p /var/log/harbr/#{name}/next/log`
|
187
|
-
|
196
|
+
|
188
197
|
write_to_file "/etc/sv/harbr/#{name}/next/run", Runit::Next::Run.new(name,port).to_s
|
189
198
|
write_to_file "/etc/sv/harbr/#{name}/next/finish", Runit::Finish.new(port).to_s
|
190
199
|
write_to_file "/etc/sv/harbr/#{name}/next/log/run", Runit::Next::Log.new(name).to_s
|
191
|
-
|
200
|
+
|
192
201
|
`chmod +x /etc/sv/harbr/#{name}/next/run`
|
193
202
|
`chmod +x /etc/sv/harbr/#{name}/next/log/run`
|
194
203
|
`chmod +x /etc/sv/harbr/#{name}/next/finish`
|
195
|
-
|
196
|
-
|
204
|
+
|
205
|
+
|
197
206
|
system "rm /etc/service/next.#{name}"
|
198
207
|
system "rm /var/harbr/containers/#{name}/next"
|
199
|
-
|
208
|
+
|
200
209
|
system "ln -sf /var/harbr/containers/#{name}/versions/#{version} /var/harbr/containers/#{name}/next"
|
201
210
|
system "ln -sf /etc/sv/harbr/#{name}/next /etc/service/next.#{name}"
|
202
211
|
system "sv restart next.#{name}"
|
203
|
-
|
212
|
+
|
204
213
|
containers = collate_containers("next.#{name}","next.#{manifest.host}",port)
|
205
214
|
create_traefik_config(containers)
|
206
215
|
end
|
207
|
-
|
216
|
+
|
208
217
|
puts "process #{version} of #{name}"
|
209
|
-
|
218
|
+
|
210
219
|
end
|
211
220
|
|
212
221
|
end
|
213
|
-
|
222
|
+
|
214
223
|
end
|
215
224
|
end
|
data/lib/harbr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delaney Kuldvee Burke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: listen
|