harbr 0.1.9 → 0.1.10
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 -39
- data/lib/harbr/next/job.rb +68 -61
- data/lib/harbr/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cb79dc0e68c2cb185caf3a1ff09234daeee64c7bdc1bbb97c1a916de40b0099
|
4
|
+
data.tar.gz: dc873fbf09ca7c7b0a8b0df9e407a396b30056cf5caa11c984507470bf91bbf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28d24d71cfe3e23c69ab405e2932a0d8deb1ef290f36286e3d50674c1056c1da1854ca141838c790768f7054f0f6aa6699b55614fc20240540acec38daa6005a
|
7
|
+
data.tar.gz: 628a1d7e58c8591b2953feaa87e67606ce688cf38b354ad3b30dbc75cfd679b4df64c7ee64ecf8549553cc88f3916af3d3959fc1fa642061bdb31c2c47805f41
|
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,43 @@ 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
|
-
|
44
|
-
|
45
|
-
puts "Traefik configuration written to /etc/traefik/harbr.toml"
|
50
|
+
|
51
|
+
config
|
46
52
|
end
|
47
|
-
|
53
|
+
|
48
54
|
def collate_containers(name,host,port)
|
49
|
-
|
55
|
+
|
50
56
|
containers = Harbr::Container::Repository.new
|
51
57
|
container = containers.find_by_header(host)
|
52
|
-
|
58
|
+
|
53
59
|
if container.nil?
|
54
60
|
container = Harbr::Container.new
|
55
61
|
container.name = name
|
@@ -63,67 +69,67 @@ module Harbr
|
|
63
69
|
end
|
64
70
|
containers.all
|
65
71
|
end
|
66
|
-
|
67
|
-
|
72
|
+
|
73
|
+
|
68
74
|
module Runit
|
69
|
-
|
75
|
+
|
70
76
|
class Run
|
71
77
|
def initialize(container, port)
|
72
78
|
@container_name = container
|
73
79
|
@port = port
|
74
80
|
end
|
75
|
-
|
81
|
+
|
76
82
|
def to_s
|
77
83
|
script_template = <<~SCRIPT
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
84
|
+
#!/bin/sh
|
85
|
+
exec 2>&1
|
86
|
+
cd /var/harbr/containers/#{@container_name}/current
|
87
|
+
exec ./exe/run #{@port} live
|
82
88
|
SCRIPT
|
83
89
|
end
|
84
|
-
|
90
|
+
|
85
91
|
def link
|
86
92
|
"ln -s /etc/sv/harbr/#{@container_name} /etc/service/#{@container_name}"
|
87
93
|
end
|
88
94
|
end
|
89
|
-
|
90
|
-
|
95
|
+
|
96
|
+
|
91
97
|
class Finish
|
92
98
|
def initialize(port)
|
93
99
|
@port = port
|
94
100
|
end
|
95
|
-
|
101
|
+
|
96
102
|
def to_s
|
97
103
|
script_template = <<~SCRIPT
|
98
|
-
|
99
|
-
|
100
|
-
|
104
|
+
#!/bin/sh
|
105
|
+
sleep 3
|
106
|
+
`lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
|
101
107
|
SCRIPT
|
102
108
|
end
|
103
109
|
end
|
104
|
-
|
110
|
+
|
105
111
|
class Log
|
106
112
|
def initialize(container)
|
107
113
|
@container_name = container
|
108
114
|
end
|
109
|
-
|
115
|
+
|
110
116
|
def to_s
|
111
117
|
script_template = <<~SCRIPT
|
112
|
-
|
113
|
-
|
118
|
+
#!/bin/sh
|
119
|
+
exec svlogd -tt /var/log/harbr/#{@container_name}
|
114
120
|
SCRIPT
|
115
121
|
end
|
116
|
-
|
122
|
+
|
117
123
|
end
|
118
|
-
|
124
|
+
|
119
125
|
end
|
120
|
-
|
126
|
+
|
121
127
|
def write_to_file(path, contents)
|
122
128
|
File.open(path, 'w') do |file|
|
123
129
|
file.write(contents)
|
124
130
|
end
|
125
131
|
end
|
126
|
-
|
132
|
+
|
127
133
|
def load_manifest(container, version)
|
128
134
|
manifest_path = "/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml"
|
129
135
|
raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
|
@@ -132,7 +138,7 @@ module Harbr
|
|
132
138
|
end
|
133
139
|
|
134
140
|
def perform(name,version)
|
135
|
-
|
141
|
+
|
136
142
|
Dir.chdir "/var/harbr/containers/#{name}/versions/#{version}" do
|
137
143
|
|
138
144
|
`bundle config set --local path 'vendor/bundle'`
|
@@ -141,11 +147,11 @@ module Harbr
|
|
141
147
|
system "sv stop #{name}" if File.exist?("/etc/service/#{name}")
|
142
148
|
system 'bundle install'
|
143
149
|
|
144
|
-
|
150
|
+
|
145
151
|
`mkdir -p /etc/sv/harbr/#{name}`
|
146
152
|
`mkdir -p /etc/sv/harbr/#{name}/log`
|
147
153
|
`mkdir -p /var/log/harbr/#{name}`
|
148
|
-
|
154
|
+
|
149
155
|
write_to_file "/etc/sv/harbr/#{name}/run", Runit::Run.new(name, port).to_s
|
150
156
|
write_to_file "/etc/sv/harbr/#{name}/finish", Runit::Finish.new(port).to_s
|
151
157
|
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,52 @@ 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
|
-
|
49
|
-
|
50
|
-
puts "Traefik configuration written to /etc/traefik/harbr.toml"
|
56
|
+
|
57
|
+
config
|
51
58
|
end
|
52
|
-
|
59
|
+
|
53
60
|
def collate_containers(name,host,port)
|
54
|
-
|
61
|
+
|
55
62
|
containers = Harbr::Container::Repository.new
|
56
63
|
container = containers.find_by_header(host)
|
57
|
-
|
64
|
+
|
58
65
|
if container.nil?
|
59
66
|
container = Harbr::Container.new
|
60
67
|
container.name = name
|
@@ -68,99 +75,99 @@ module Harbr
|
|
68
75
|
end
|
69
76
|
containers.all
|
70
77
|
end
|
71
|
-
|
72
|
-
|
78
|
+
|
79
|
+
|
73
80
|
module Runit
|
74
|
-
|
81
|
+
|
75
82
|
class Run
|
76
83
|
def initialize(container, port)
|
77
84
|
@container_name = container
|
78
85
|
@port = port
|
79
86
|
end
|
80
|
-
|
87
|
+
|
81
88
|
def to_s
|
82
89
|
script_template = <<~SCRIPT
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
90
|
+
#!/bin/sh
|
91
|
+
exec 2>&1
|
92
|
+
cd /var/harbr/#{@container_name}/current
|
93
|
+
exec ./exe/run #{@port} live
|
87
94
|
SCRIPT
|
88
95
|
end
|
89
|
-
|
96
|
+
|
90
97
|
def link
|
91
98
|
"ln -s /etc/sv/harbr/#{@container_name} /etc/service/#{@container_name}"
|
92
99
|
end
|
93
100
|
end
|
94
|
-
|
95
|
-
|
101
|
+
|
102
|
+
|
96
103
|
class Finish
|
97
104
|
def initialize(port)
|
98
105
|
@port = port
|
99
106
|
end
|
100
|
-
|
107
|
+
|
101
108
|
def to_s
|
102
109
|
script_template = <<~SCRIPT
|
103
|
-
|
104
|
-
|
105
|
-
|
110
|
+
#!/bin/sh
|
111
|
+
sleep 3
|
112
|
+
`lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
|
106
113
|
SCRIPT
|
107
114
|
end
|
108
115
|
end
|
109
|
-
|
116
|
+
|
110
117
|
class Log
|
111
118
|
def initialize(container, port)
|
112
119
|
@container_name = container
|
113
120
|
end
|
114
|
-
|
121
|
+
|
115
122
|
def to_s
|
116
123
|
script_template = <<~SCRIPT
|
117
|
-
|
118
|
-
|
124
|
+
#!/bin/sh
|
125
|
+
exec svlogd -tt /var/log/harbr/#{@container_name}/next/
|
119
126
|
SCRIPT
|
120
127
|
end
|
121
|
-
|
128
|
+
|
122
129
|
end
|
123
|
-
|
130
|
+
|
124
131
|
module Next
|
125
|
-
|
132
|
+
|
126
133
|
class Run
|
127
134
|
def initialize(container, port)
|
128
135
|
@container_name = container
|
129
136
|
@port = port
|
130
137
|
end
|
131
|
-
|
138
|
+
|
132
139
|
def to_s
|
133
140
|
script_template = <<~SCRIPT
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
141
|
+
#!/bin/sh
|
142
|
+
exec 2>&1
|
143
|
+
cd /var/harbr/containers/#{@container_name}/next
|
144
|
+
exec ./exe/run #{@port} next
|
138
145
|
SCRIPT
|
139
146
|
end
|
140
147
|
end
|
141
|
-
|
148
|
+
|
142
149
|
class Log
|
143
150
|
def initialize(container)
|
144
151
|
@container_name = container
|
145
152
|
end
|
146
|
-
|
153
|
+
|
147
154
|
def to_s
|
148
155
|
script_template = <<~SCRIPT
|
149
|
-
|
150
|
-
|
156
|
+
#!/bin/sh
|
157
|
+
exec svlogd -tt /var/log/harbr/#{@container_name}/next/
|
151
158
|
SCRIPT
|
152
159
|
end
|
153
160
|
end
|
154
|
-
|
161
|
+
|
155
162
|
end
|
156
163
|
end
|
157
|
-
|
164
|
+
|
158
165
|
def write_to_file(path, contents)
|
159
166
|
File.open(path, 'w') do |file|
|
160
167
|
file.write(contents)
|
161
168
|
end
|
162
169
|
end
|
163
|
-
|
170
|
+
|
164
171
|
def load_manifest(container, version)
|
165
172
|
manifest_path = "/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml"
|
166
173
|
raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
|
@@ -170,46 +177,46 @@ module Harbr
|
|
170
177
|
|
171
178
|
def perform(name, version)
|
172
179
|
`bundle config set --local path 'vendor/bundle'`
|
173
|
-
|
180
|
+
|
174
181
|
manifest = load_manifest(name,version)
|
175
182
|
current_path = "/var/harbr/containers/#{name}/versions/#{version}"
|
176
|
-
|
183
|
+
|
177
184
|
port = `port assign next.#{manifest.port}`.strip
|
178
|
-
|
185
|
+
|
179
186
|
Dir.chdir current_path do
|
180
|
-
|
187
|
+
|
181
188
|
system "sv stop next.#{name}"
|
182
189
|
system "bundle install"
|
183
|
-
|
190
|
+
|
184
191
|
`mkdir -p /etc/sv/harbr/#{name}/next`
|
185
192
|
`mkdir -p /etc/sv/harbr/#{name}/next/log`
|
186
193
|
`mkdir -p /var/log/harbr/#{name}/next/log`
|
187
|
-
|
194
|
+
|
188
195
|
write_to_file "/etc/sv/harbr/#{name}/next/run", Runit::Next::Run.new(name,port).to_s
|
189
196
|
write_to_file "/etc/sv/harbr/#{name}/next/finish", Runit::Finish.new(port).to_s
|
190
197
|
write_to_file "/etc/sv/harbr/#{name}/next/log/run", Runit::Next::Log.new(name).to_s
|
191
|
-
|
198
|
+
|
192
199
|
`chmod +x /etc/sv/harbr/#{name}/next/run`
|
193
200
|
`chmod +x /etc/sv/harbr/#{name}/next/log/run`
|
194
201
|
`chmod +x /etc/sv/harbr/#{name}/next/finish`
|
195
|
-
|
196
|
-
|
202
|
+
|
203
|
+
|
197
204
|
system "rm /etc/service/next.#{name}"
|
198
205
|
system "rm /var/harbr/containers/#{name}/next"
|
199
|
-
|
206
|
+
|
200
207
|
system "ln -sf /var/harbr/containers/#{name}/versions/#{version} /var/harbr/containers/#{name}/next"
|
201
208
|
system "ln -sf /etc/sv/harbr/#{name}/next /etc/service/next.#{name}"
|
202
209
|
system "sv restart next.#{name}"
|
203
|
-
|
210
|
+
|
204
211
|
containers = collate_containers("next.#{name}","next.#{manifest.host}",port)
|
205
212
|
create_traefik_config(containers)
|
206
213
|
end
|
207
|
-
|
214
|
+
|
208
215
|
puts "process #{version} of #{name}"
|
209
|
-
|
216
|
+
|
210
217
|
end
|
211
218
|
|
212
219
|
end
|
213
|
-
|
220
|
+
|
214
221
|
end
|
215
222
|
end
|
data/lib/harbr/version.rb
CHANGED