harbr 0.1.97 → 0.1.99

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/exe/harbr +3 -120
  3. data/lib/harbr/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6523337d1554b46139ffb2f876b7b6a2370ae7ee20446cd2e97f9c3f92ead769
4
- data.tar.gz: 64ed1fdda1a29df228e1ce3131966a14dd2d588e52d8b1728a37f0d91766c272
3
+ metadata.gz: 52649fe0f492d23abe98964937b545745b93d50929d1ea5d282826216d081f19
4
+ data.tar.gz: f34b8e0088b230a905e48e0500d5b6a0247410a7454b13af5321a076143f0b05
5
5
  SHA512:
6
- metadata.gz: fd8a9c7b340d50d75ad4504c391a9c94ddba5e2b442ecfb0042c8b88fe153b90d412a853ac8b7e3e236c5593aba5c597295e36c08f2feec24c63f4f86287c4e5
7
- data.tar.gz: e14a7cdadc6f73879df16e52012e9104e8f6f0d208f4a597bb596bb1b7cd2cec256167e15dca6d98ef5b400961f02f2b3debd3542380c3b67d7ecfe7d5bf9f6f
6
+ metadata.gz: 165aa6e0f4d46857054bebce4147d9377ed9a0e3c7d7afd18665a84c1311f814cca9699101a0b9d2e849230d261b5c7e7c8440f4efdb799ae1dece12c0edb651
7
+ data.tar.gz: bc3b12f75986c672f98747fe5368a6e109daa9328ce9215c2306eacde3bfd542b2bdefc63f8596e63395c81b55c9e6af4cdcc9913de1bf38ea1f013cdccd2feb
data/exe/harbr CHANGED
@@ -48,82 +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
- def run_jobs(container, version)
90
- check_file_exists("/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml") do
91
- `harbr deploy #{container} #{version} --next`
92
- end
93
- end
94
-
95
- def create_traefik_config(containers)
96
- `rm -rf "/etc/traefik/harbr.toml"`
97
-
98
- config = {
99
- "http" => {
100
- "routers" => {
101
- "traefik-dashboard" => {
102
- "rule" => "Host(`traefik.harbr.zero2one.ee`)",
103
- "service" => "api@internal"
104
- }
105
- },
106
- "services" => {}
107
- }
108
- }
109
-
110
- containers.each do |container|
111
- container.ip = "127.0.0.1"
112
-
113
- config["http"]["routers"]["#{container.name}-router"] = {
114
- "rule" => "Host(`#{container.host_header}`)",
115
- "service" => "#{container.name}-service"
116
- }
117
- config["http"]["services"]["#{container.name}-service"] = {
118
- "loadBalancer" => {
119
- "servers" => [{"url" => "http://#{container.ip}:#{container.port}"}]
120
- }
121
- }
122
- end
123
-
124
- File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
125
- puts "Traefik configuration written to /etc/traefik/harbr.toml"
126
- end
127
51
  end
128
52
 
129
53
  desc "destroy", "Destroy a container and remove all traces"
@@ -174,33 +98,11 @@ class HarbrCLI < Thor
174
98
  def setup
175
99
  # Check and create /var/harbr directory
176
100
  check_and_create_directory("/var/harbr/containers")
177
-
101
+ check_and_create_directory("/var/dddr")
178
102
  # Check for Ruby, Traefik, and runit, and install if necessary
179
103
  install_with_snap("ruby") unless command_exists?("ruby")
180
104
  install_with_snap("traefik") unless command_exists?("traefik")
181
105
  install_with_apt("runit") unless command_exists?("runit")
182
-
183
- run_script = <<~SCRIPT
184
- #!/bin/sh
185
- exec 2>&1
186
- harbr monitor
187
- SCRIPT
188
-
189
- log_script = <<~SCRIPT
190
- #!/bin/sh
191
- exec svlogd -tt /var/log/harbr/
192
- SCRIPT
193
-
194
- write_to_file("/etc/sv/harbr/run", run_script)
195
- write_to_file("/etc/sv/harbr/log/run", log_script)
196
-
197
- `chmod +x /etc/sv/harbr/run`
198
- `chmod +x /etc/sv/harbr/log/run`
199
- `mkdir -p /var/log/harbr`
200
- `ln -sf /etc/sv/harbr /etc/service/harbr`
201
- `sv start harbr`
202
- puts "Harbr service started successfully."
203
-
204
106
  puts "Setup completed successfully."
205
107
  end
206
108
 
@@ -253,28 +155,9 @@ class HarbrCLI < Thor
253
155
 
254
156
  desc "update", "update to the latest version of harbr"
255
157
  def update
256
- system "gem update harbr && sv stop harbr && sv start harbr"
158
+ system "gem update harbr"
257
159
  end
258
160
 
259
- desc "monitor", "Monitor /var/harbr/comtainers for new container versions"
260
- def monitor
261
- puts "version: (#{Harbr::VERSION})"
262
- puts "Monitoring /var/harbr/containers for new container versions..."
263
-
264
- last_known_state = {}
265
-
266
- loop do
267
- current_state = scan_for_containers
268
- new_versions = current_state.keys - last_known_state.keys
269
-
270
- new_versions.each do |container_version|
271
- container, version = container_version.split("/versions/")
272
- place(container, version)
273
- end
274
-
275
- last_known_state = current_state
276
- sleep 3 # Poll every 10 seconds
277
- end
278
- end
279
161
  end
162
+
280
163
  HarbrCLI.start(ARGV)
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.97"
4
+ VERSION = "0.1.99"
5
5
  end
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.97
4
+ version: 0.1.99
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delaney Kuldvee Burke