harbr 0.1.96 → 0.1.98
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/harbr +2 -118
- 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: fe153e32f06547c4c498a5d08f8a7aef1fc27e44ed3857d73696e59062b8f80e
|
4
|
+
data.tar.gz: d5a7ad6a5f5564625a44500c396482c187fed60d9db85406e74a372d9a5fd0d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d0c6ffe147df8016539d6e126f201ba8607d6fc554fe55827cd47bb36c0aa7c7a1ca86e871d714f44280e04b09c817d8db6e9f2407488402b9e2e848d1693d0
|
7
|
+
data.tar.gz: 20271d95fb0ea8aee04d1cae9dd28949389d70ea333106060de8e1cd9a897bf20b7aca94a382bf3b98e738a36d9ddd863ece93d20a97234108b308b5fddf59e3
|
data/exe/harbr
CHANGED
@@ -48,81 +48,6 @@ class HarbrCLI < Thor
|
|
48
48
|
system("sudo apt install #{package}") or raise "Failed to install #{package}"
|
49
49
|
end
|
50
50
|
|
51
|
-
def scan_for_containers
|
52
|
-
Dir.glob("/var/harbr/containers/*").each_with_object({}) do |container_path, hash|
|
53
|
-
next unless File.directory?(container_path)
|
54
|
-
container_name = File.basename(container_path)
|
55
|
-
versions = Dir.glob("#{container_path}/versions/*").select { |path| File.directory?(path) }
|
56
|
-
versions.each { |version_path| hash["#{container_name}/versions/#{File.basename(version_path)}"] = true }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
PLACED_FILE = "/var/harbr/.placed"
|
61
|
-
|
62
|
-
def place(container, version)
|
63
|
-
placed_containers = File.exist?(PLACED_FILE) ? File.read(PLACED_FILE).split("\n") : []
|
64
|
-
|
65
|
-
if placed_containers.include?("#{container}/#{version}")
|
66
|
-
puts "Container '#{container}', Version '#{version}' is already placed."
|
67
|
-
else
|
68
|
-
puts "Placing container: '#{container}', Version: '#{version}'"
|
69
|
-
run_jobs(container, version)
|
70
|
-
File.open(PLACED_FILE, "a") { |file| file.puts("#{container}/#{version}") }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def check
|
75
|
-
sleep_times = [1, 3, 5, 8, 23]
|
76
|
-
begin
|
77
|
-
result = yield if block_given?
|
78
|
-
unless result
|
79
|
-
sleep_times.each do |time|
|
80
|
-
result = yield if block_given?
|
81
|
-
break if result
|
82
|
-
sleep(time)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
rescue => e
|
86
|
-
puts "Error: #{e.message}"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def run_jobs(container, version)
|
91
|
-
`harbr deploy #{container} #{version} --next`
|
92
|
-
end
|
93
|
-
|
94
|
-
def create_traefik_config(containers)
|
95
|
-
`rm -rf "/etc/traefik/harbr.toml"`
|
96
|
-
|
97
|
-
config = {
|
98
|
-
"http" => {
|
99
|
-
"routers" => {
|
100
|
-
"traefik-dashboard" => {
|
101
|
-
"rule" => "Host(`traefik.harbr.zero2one.ee`)",
|
102
|
-
"service" => "api@internal"
|
103
|
-
}
|
104
|
-
},
|
105
|
-
"services" => {}
|
106
|
-
}
|
107
|
-
}
|
108
|
-
|
109
|
-
containers.each do |container|
|
110
|
-
container.ip = "127.0.0.1"
|
111
|
-
|
112
|
-
config["http"]["routers"]["#{container.name}-router"] = {
|
113
|
-
"rule" => "Host(`#{container.host_header}`)",
|
114
|
-
"service" => "#{container.name}-service"
|
115
|
-
}
|
116
|
-
config["http"]["services"]["#{container.name}-service"] = {
|
117
|
-
"loadBalancer" => {
|
118
|
-
"servers" => [{"url" => "http://#{container.ip}:#{container.port}"}]
|
119
|
-
}
|
120
|
-
}
|
121
|
-
end
|
122
|
-
|
123
|
-
File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
|
124
|
-
puts "Traefik configuration written to /etc/traefik/harbr.toml"
|
125
|
-
end
|
126
51
|
end
|
127
52
|
|
128
53
|
desc "destroy", "Destroy a container and remove all traces"
|
@@ -173,33 +98,11 @@ class HarbrCLI < Thor
|
|
173
98
|
def setup
|
174
99
|
# Check and create /var/harbr directory
|
175
100
|
check_and_create_directory("/var/harbr/containers")
|
176
|
-
|
101
|
+
check_and_create_directory("/var/dddr")
|
177
102
|
# Check for Ruby, Traefik, and runit, and install if necessary
|
178
103
|
install_with_snap("ruby") unless command_exists?("ruby")
|
179
104
|
install_with_snap("traefik") unless command_exists?("traefik")
|
180
105
|
install_with_apt("runit") unless command_exists?("runit")
|
181
|
-
|
182
|
-
run_script = <<~SCRIPT
|
183
|
-
#!/bin/sh
|
184
|
-
exec 2>&1
|
185
|
-
harbr monitor
|
186
|
-
SCRIPT
|
187
|
-
|
188
|
-
log_script = <<~SCRIPT
|
189
|
-
#!/bin/sh
|
190
|
-
exec svlogd -tt /var/log/harbr/
|
191
|
-
SCRIPT
|
192
|
-
|
193
|
-
write_to_file("/etc/sv/harbr/run", run_script)
|
194
|
-
write_to_file("/etc/sv/harbr/log/run", log_script)
|
195
|
-
|
196
|
-
`chmod +x /etc/sv/harbr/run`
|
197
|
-
`chmod +x /etc/sv/harbr/log/run`
|
198
|
-
`mkdir -p /var/log/harbr`
|
199
|
-
`ln -sf /etc/sv/harbr /etc/service/harbr`
|
200
|
-
`sv start harbr`
|
201
|
-
puts "Harbr service started successfully."
|
202
|
-
|
203
106
|
puts "Setup completed successfully."
|
204
107
|
end
|
205
108
|
|
@@ -255,25 +158,6 @@ class HarbrCLI < Thor
|
|
255
158
|
system "gem update harbr && sv stop harbr && sv start harbr"
|
256
159
|
end
|
257
160
|
|
258
|
-
desc "monitor", "Monitor /var/harbr/comtainers for new container versions"
|
259
|
-
def monitor
|
260
|
-
puts "version: (#{Harbr::VERSION})"
|
261
|
-
puts "Monitoring /var/harbr/containers for new container versions..."
|
262
|
-
|
263
|
-
last_known_state = {}
|
264
|
-
|
265
|
-
loop do
|
266
|
-
current_state = scan_for_containers
|
267
|
-
new_versions = current_state.keys - last_known_state.keys
|
268
|
-
|
269
|
-
new_versions.each do |container_version|
|
270
|
-
container, version = container_version.split("/versions/")
|
271
|
-
place(container, version)
|
272
|
-
end
|
273
|
-
|
274
|
-
last_known_state = current_state
|
275
|
-
sleep 3 # Poll every 10 seconds
|
276
|
-
end
|
277
|
-
end
|
278
161
|
end
|
162
|
+
|
279
163
|
HarbrCLI.start(ARGV)
|
data/lib/harbr/version.rb
CHANGED