harbr 0.0.75 → 0.0.76

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24c9a6c440b96bf2df8658095ee67d71f257f8d2ce1db94dbec1c0e6079a2c61
4
- data.tar.gz: 535eb68733f63f8bb561cc2b84365f786dd6395a00d824b76907541a0226c673
3
+ metadata.gz: b82b02c1688ef82d892d9119fc16de0ee53ecc9932ac5fce1044f411ac93eaf5
4
+ data.tar.gz: e37d42b6bf195d0e9369773270b449235b5430df9670b0406d2fa99dab11b41d
5
5
  SHA512:
6
- metadata.gz: 102dca943b77b5d715e2ae6cbe5b9eca8a5fda8b2657b477cce6e38c3b0660c0aa555e68842443262e6dd80b481d9c4efaed4bf6281ed7923025497dda639a0f
7
- data.tar.gz: dbd8193d07ff643901d0c91dde8c1f5b7fca9627a96398082770c1a3d47fe35ca6ed83fb86d3ff73a3fc65a3d781fc45bd7fc89426a31a45dc52ed0a47e884b8
6
+ metadata.gz: 910a38e79037bced8a8e7e38cbe774f2255cc30077b83c89360207caf6067767ff5456c8e73613f71372a5d627c6f773d6498de5fbd2a5cc07f00e7a0cbd4bb1
7
+ data.tar.gz: 4d71192400148675c41d89c4ec6d3d97556822e114eca6384a4ab2b0f111fc857ba6717d92b3be3429e64a7857e10e8036bdee5ac982dd908708d5db176b666e
data/exe/harbr CHANGED
@@ -2,9 +2,7 @@
2
2
  require_relative "../lib/harbr"
3
3
 
4
4
  class HarbrCLI < Thor
5
-
6
5
  no_commands do
7
-
8
6
  def display_containers_table(containers)
9
7
  return puts "No containers available." if containers.empty?
10
8
 
@@ -78,12 +76,11 @@ class HarbrCLI < Thor
78
76
  else
79
77
  Harbr::Next::Job.perform_async(container, version)
80
78
  puts "deploy next version #{version} of #{container}"
81
-
79
+
82
80
  end
83
81
  end
84
82
 
85
83
  def create_traefik_config(containers)
86
-
87
84
  `rm -rf "/etc/traefik/harbr.toml"`
88
85
 
89
86
  config = {
@@ -115,13 +112,11 @@ class HarbrCLI < Thor
115
112
  File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
116
113
  puts "Traefik configuration written to /etc/traefik/harbr.toml"
117
114
  end
118
-
119
115
  end
120
116
 
121
117
  desc "destroy", "Destroy a container and remove all traces"
122
118
  def destroy(container_name)
123
-
124
- puts "Destroying container: #{container_name}"
119
+ puts "Destroying container: #{container_name}"
125
120
  puts `sv stop #{container_name}`
126
121
 
127
122
  container_repo = Harbr::Container::Repository.new
@@ -129,7 +124,6 @@ class HarbrCLI < Thor
129
124
  if container
130
125
  puts `port release #{container.port}`
131
126
  create_traefik_config(container_repo.all)
132
-
133
127
 
134
128
  `rm -rf /var/harbr/#{container_name}`
135
129
  `rm -rf /etc/service/#{container_name}`
@@ -137,23 +131,21 @@ class HarbrCLI < Thor
137
131
  `rm -rf /var/log/harbr/#{container_name}`
138
132
 
139
133
  `lsof -i :#{container.port} | awk 'NR!=1 {print $2}' | xargs kill`
140
- container_repo.delete(container)
134
+ container_repo.delete(container)
141
135
 
142
136
  puts "Container #{container_name} destroyed successfully."
143
137
 
144
138
  else
145
139
  puts "Container #{container_name} not found."
146
140
  end
147
-
148
141
  end
149
142
 
150
143
  desc "logs CONTAINER", "Show logs for a given container"
151
144
  def logs(container)
152
-
153
145
  container_repo = Harbr::Container::Repository.new
154
146
  container = container_repo.find_by_name(container)
155
147
  if container
156
- exec "tail -f /var/log/harbr/#{container.name}/current"
148
+ exec "tail -f /var/log/harbr/#{container.name}/current"
157
149
  else
158
150
  puts "Container not recognized"
159
151
  end
@@ -7,6 +7,7 @@ module Harbr
7
7
  def find_by_header(host_header)
8
8
  all.find { |container| container.host_header.downcase == host_header.downcase }
9
9
  end
10
+
10
11
  def find_by_name(name)
11
12
  all.find { |container| container.name.downcase == name.downcase }
12
13
  end
data/lib/harbr/job.rb CHANGED
@@ -1,14 +1,32 @@
1
+ require 'harbr'
1
2
  module Harbr
2
3
  class Job
3
4
  include SuckerPunch::Job
4
5
 
5
- def load_manifest(container,version)
6
- manifest_path = "/var/harbr/#{container}/versions/#{version}/config/manifest.yml"
7
- raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
8
- manifest_data = YAML.load_file(manifest_path)
9
- OpenStruct.new(manifest_data)
6
+ def highest_numbered_directory(path)
7
+ directories = Dir.glob("#{path}/*").select { |entry| File.directory?(entry) }
8
+ directories.max_by { |entry| entry[/\d+/].to_i }
10
9
  end
11
-
10
+
11
+ def get_container_name(path)
12
+ File.basename(path)
13
+ end
14
+
15
+ def check_container_version(name, version)
16
+ file_path = '/var/harbr/.data/processed_next.txt' # replace with your file path
17
+ `touch #{file_path}`
18
+ container_version = "#{name},#{version}"
19
+
20
+ File.open(file_path, 'r') do |file|
21
+ if file.any? { |line| line.chomp == container_version }
22
+ puts 'containerised'
23
+ else
24
+ result = yield name, version
25
+ File.write(file_path, "#{container_version}\n", mode: 'a') unless result == false
26
+ end
27
+ end
28
+ end
29
+
12
30
  def create_traefik_config(containers)
13
31
  config = {
14
32
  "http" => {
@@ -21,102 +39,171 @@ module Harbr
21
39
  "services" => {}
22
40
  }
23
41
  }
24
-
42
+
25
43
  containers.each do |container|
26
44
  container.ip = "127.0.0.1"
27
-
28
- config["http"]["routers"]["#{container.name}-router"] = {
45
+ name = container.name.gsub(".","-")
46
+
47
+ config["http"]["routers"]["#{name}-router"] = {
29
48
  "rule" => "Host(`#{container.host_header}`)",
30
- "service" => "#{container.name}-service"
49
+ "service" => "#{name}-service"
31
50
  }
32
- config["http"]["services"]["#{container.name}-service"] = {
51
+ config["http"]["services"]["#{name}-service"] = {
33
52
  "loadBalancer" => {
34
53
  "servers" => [{"url" => "http://#{container.ip}:#{container.port}"}]
35
54
  }
36
55
  }
37
56
  end
38
-
57
+
39
58
  File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
40
59
  puts "Traefik configuration written to /etc/traefik/harbr.toml"
41
60
  end
42
-
43
- def create_run_script(container_name, port)
44
- service_dir = "/etc/sv/harbr/#{container_name}"
45
-
46
- script_template = <<~SCRIPT
47
- #!/bin/sh
48
- exec 2>&1
49
- cd /var/harbr/#{container_name}/current
50
- exec ./exe/run #{port}
51
- SCRIPT
52
-
53
- service_dir = "/etc/sv/harbr/#{container_name}"
54
- FileUtils.mkdir_p(service_dir)
55
-
56
- File.write("#{service_dir}/run", script_template)
57
- FileUtils.chmod("+x", "#{service_dir}/run")
58
- puts "Run script created and made executable for container: #{container_name}"
59
- end
60
-
61
- def create_log_script(container_name)
62
- log_dir = "/var/log/harbr/#{container_name}"
63
-
64
- FileUtils.mkdir_p(log_dir)
65
-
66
- script_template = <<~SCRIPT
67
- #!/bin/sh
68
- exec svlogd -tt #{log_dir}/
69
- SCRIPT
70
-
71
- dir_path = "/etc/sv/harbr/#{container_name}/log"
72
- FileUtils.mkdir_p(dir_path)
73
-
74
- File.write("#{dir_path}/run", script_template)
75
- FileUtils.chmod("+x", "#{dir_path}/run")
76
- puts "Log script created and made executable for container: #{container_name}"
77
- end
78
-
79
- def create_a_service(container_name, port)
80
- create_run_script(container_name, port)
81
- create_log_script(container_name)
82
- system("ln -s /etc/sv/harbr/#{container_name} /etc/service/#{container_name}") unless File.exist?("/etc/service/#{container_name}")
83
- end
84
-
85
- def run_container(manifest)
86
- puts "Starting container: #{manifest.name}"
87
- port = `port assign #{manifest.port}`.strip
88
-
89
-
90
-
91
- create_a_service(manifest.name, port)
92
-
93
- containers = Container::Repository.new
94
- container = containers.find_by_header(manifest.host)
95
-
61
+
62
+ def collate_containers(name,host,port)
63
+
64
+ containers = Harbr::Container::Repository.new
65
+ container = containers.find_by_header(host)
66
+
96
67
  if container.nil?
97
- container = Container.new
98
- container.name = manifest.name
99
- container.host_header = manifest.host
68
+ container = Harbr::Container.new
69
+ container.name = name
70
+ container.host_header =host
100
71
  container.ip = "127.0.0.1"
101
72
  container.port = port
102
73
  containers.create(container)
103
74
  else
104
- container.port = port
105
- containers.update(container)
75
+ container.port = port
76
+ containers.update(container)
106
77
  end
107
-
108
- system("cd /var/harbr/#{manifest.name}/current && bundle install")
109
- puts `lsof -i :#{port} | awk 'NR!=1 {print $2}' | xargs kill -9`
110
- system("sv restart #{manifest.name}")
111
- puts "Started container: #{manifest.name}"
112
- create_traefik_config(containers.all)
78
+ containers.all
79
+ end
80
+
81
+
82
+ module Runit
83
+
84
+ class Run
85
+ def initialize(container, port)
86
+ @container_name = container
87
+ @port = port
88
+ end
89
+
90
+ def to_s
91
+ script_template = <<~SCRIPT
92
+ #!/bin/sh
93
+ exec 2>&1
94
+ cd /var/harbr/#{@container_name}/current
95
+ exec ./exe/run #{@port}
96
+ SCRIPT
97
+ end
98
+
99
+ def link
100
+ "ln -s /etc/sv/harbr/#{@container_name} /etc/service/#{@container_name}"
101
+ end
102
+ end
103
+
104
+
105
+ class Finish
106
+ def initialize(port)
107
+ @port = port
108
+ end
109
+
110
+ def to_s
111
+ script_template = <<~SCRIPT
112
+ #!/bin/sh
113
+ sleep 3
114
+ `lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
115
+ SCRIPT
116
+ end
117
+ end
118
+
119
+ class Log
120
+ def initialize(container, port)
121
+ @container_name = container
122
+ end
123
+
124
+ def to_s
125
+ script_template = <<~SCRIPT
126
+ #!/bin/sh
127
+ exec svlogd -tt /var/log/harbr/#{@container_name}/next/
128
+ SCRIPT
129
+ end
130
+
131
+ end
132
+
133
+ module Next
134
+
135
+ class Run
136
+ def initialize(container, port)
137
+ @container_name = container
138
+ @port = port
139
+ end
140
+
141
+ def to_s
142
+ script_template = <<~SCRIPT
143
+ #!/bin/sh
144
+ exec 2>&1
145
+ cd /var/harbr/containers/#{@container_name}/next
146
+ exec ./exe/run #{@port}
147
+ SCRIPT
148
+ end
149
+ end
150
+
151
+ class Log
152
+ def initialize(container)
153
+ @container_name = container
154
+ end
155
+
156
+ def to_s
157
+ script_template = <<~SCRIPT
158
+ #!/bin/sh
159
+ exec svlogd -tt /var/log/harbr/#{@container_name}/next/
160
+ SCRIPT
161
+ end
162
+ end
163
+
164
+ end
165
+ end
166
+
167
+ def write_to_file(path, contents)
168
+ File.open(path, 'w') do |file|
169
+ file.write(contents)
170
+ end
171
+ end
172
+
173
+ def load_manifest(container, version)
174
+ manifest_path = "/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml"
175
+ raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
176
+ manifest_data = YAML.load_file(manifest_path)
177
+ OpenStruct.new(manifest_data)
113
178
  end
114
179
 
115
- def perform(container, version)
116
- puts "Running tasks for container: '#{container}', Version: '#{version}'"
117
- manifest = load_manifest(container, version)
118
- puts "Manifest: #{manifest}"
119
- run_container(manifest)
180
+ def perform(name,version)
181
+ Dir.chdir "/var/harbr/containers/#{name}/versions/#{version}" do
182
+ `bundle config set --local path 'vendor/bundle'`
183
+ manifest = load_manifest(name, version)
184
+ port = `port assign next.#{manifest.port}`.strip
185
+ system "sv stop #{name}"
186
+ system 'bundle install'
187
+ `mkdir -p /etc/sv/harbr/#{name}`
188
+ `mkdir -p /etc/sv/harbr/#{name}/log`
189
+
190
+ write_to_file "/etc/sv/harbr/#{name}/run", Runit::Next::Run.new(name, port).to_s
191
+ write_to_file "/etc/sv/harbr/#{name}/finish", Runit::Finish.new(port).to_s
192
+ write_to_file "/etc/sv/harbr/#{name}/log/run", Runit::Next::Log.new(name).to_s
193
+
194
+ `chmod +x /etc/sv/harbr/#{name}/run`
195
+ `chmod +x /etc/sv/harbr/#{name}/log/run`
196
+ `chmod +x /etc/sv/harbr/#{name}/finish`
197
+
198
+ system "ln -s /var/harbr/containers/#{name}/versions/#{version} /var/harbr/containers/#{name}/current"
199
+ system "ln -s /etc/sv/harbr/#{name}/next /etc/service/#{name}"
200
+
201
+ containers = collate_containers(name, manifest.host, port)
202
+ create_traefik_config(containers)
203
+ puts "process #{version} of #{name}"
204
+ end
120
205
  end
206
+
121
207
  end
208
+
122
209
  end
@@ -1,122 +1,78 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+ require 'sucker_punch'
4
+
5
+ require 'harbr'
1
6
  module Harbr
2
7
  module Next
3
8
  class Job
4
9
  include SuckerPunch::Job
5
10
 
6
- def load_manifest(container, version)
7
- manifest_path = "/var/harbr/#{container}/versions/#{version}/config/manifest.yml"
8
- raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
9
- manifest_data = YAML.load_file(manifest_path)
10
- OpenStruct.new(manifest_data)
11
+ def highest_numbered_directory(path)
12
+ directories = Dir.glob("#{path}/*").select { |entry| File.directory?(entry) }
13
+ directories.max_by { |entry| entry[/\d+/].to_i }
11
14
  end
12
-
13
15
 
14
- def create_traefik_config(containers)
15
- config = initialize_config
16
-
17
- containers.each do |container|
18
- container.ip = '127.0.0.1'
19
- add_router_to_config(config, container)
20
- add_service_to_config(config, container)
16
+ def get_container_name(path)
17
+ File.basename(path)
18
+ end
19
+
20
+ def check_container_version(name, version)
21
+ file_path = '/var/harbr/.data/processed_next.txt' # replace with your file path
22
+ `touch #{file_path}`
23
+ container_version = "#{name},#{version}"
24
+
25
+ File.open(file_path, 'r') do |file|
26
+ if file.any? { |line| line.chomp == container_version }
27
+ puts 'containerised'
28
+ else
29
+ result = yield name, version
30
+ File.write(file_path, "#{container_version}\n", mode: 'a') unless result == false
31
+ end
21
32
  end
22
-
23
- write_config_to_file(config)
24
33
  end
25
-
26
- private
27
-
28
- def initialize_config
29
- {
30
- 'http' => {
31
- 'routers' => {
32
- 'traefik-dashboard' => {
33
- 'rule' => 'Host(`traefik.harbr.zero2one.ee`)',
34
- 'service' => 'api@internal'
34
+
35
+ def create_traefik_config(containers)
36
+ config = {
37
+ "http" => {
38
+ "routers" => {
39
+ "traefik-dashboard" => {
40
+ "rule" => "Host(`traefik.harbr.zero2one.ee`)",
41
+ "service" => "api@internal"
35
42
  }
36
43
  },
37
- 'services' => {}
44
+ "services" => {}
38
45
  }
39
46
  }
40
- end
41
-
42
- def add_router_to_config(config, container)
43
- config['http']['routers']["#{container.name}-router"] = {
44
- 'rule' => "Host(`#{container.host_header}`)",
45
- 'service' => "#{container.name}-service"
46
- }
47
- end
48
-
49
- def add_service_to_config(config, container)
50
- config['http']['services']["#{container.name}-service"] = {
51
- 'loadBalancer' => {
52
- 'servers' => [{'url' => "http://#{container.ip}:#{container.port}"}]
47
+
48
+ containers.each do |container|
49
+ container.ip = "127.0.0.1"
50
+ name = container.name.gsub(".","-")
51
+
52
+ config["http"]["routers"]["#{name}-router"] = {
53
+ "rule" => "Host(`#{container.host_header}`)",
54
+ "service" => "#{name}-service"
53
55
  }
54
- }
55
- end
56
-
57
- def write_config_to_file(config)
58
- File.write('/etc/traefik/harbr.toml', TomlRB.dump(config))
59
- puts 'Traefik configuration written to /etc/traefik/harbr.toml'
60
- end
56
+ config["http"]["services"]["#{name}-service"] = {
57
+ "loadBalancer" => {
58
+ "servers" => [{"url" => "http://#{container.ip}:#{container.port}"}]
59
+ }
60
+ }
61
+ end
61
62
 
62
- def create_run_script(container_name, port)
63
- service_dir = "/etc/sv/harbr/#{container_name}/next"
64
-
65
- script_template = <<~SCRIPT
66
- #!/bin/sh
67
- exec 2>&1
68
- cd /var/harbr/#{container_name}/next
69
- exec ./exe/run #{port}
70
- SCRIPT
71
-
72
- service_dir = "/etc/sv/harbr/#{container_name}/next"
73
- FileUtils.mkdir_p(service_dir)
74
-
75
- File.write("#{service_dir}/run", script_template)
76
- FileUtils.chmod("+x", "#{service_dir}/run")
77
- puts "Run script created and made executable for container: next.#{container_name}"
78
- end
79
-
80
- def create_log_script(container_name)
81
- log_dir = "/var/log/harbr/#{container_name}/next"
82
-
83
- FileUtils.mkdir_p(log_dir)
84
-
85
- script_template = <<~SCRIPT
86
- #!/bin/sh
87
- exec svlogd -tt #{log_dir}/
88
- SCRIPT
89
-
90
- dir_path = "/etc/sv/harbr/#{container_name}/next/log"
91
- FileUtils.mkdir_p(dir_path)
92
-
93
- File.write("#{dir_path}/run", script_template)
94
- FileUtils.chmod("+x", "#{dir_path}/run")
95
- puts "Log script created and made executable for container: next.#{container_name}"
96
- end
97
- def create_a_service(container_name, port)
98
- create_run_script(container_name, port)
99
- create_log_script(container_name)
100
-
101
- system("ln -s /etc/sv/harbr/#{container_name}/next /etc/service/next.#{container_name}") unless File.exist?("/etc/service/next.#{container_name}")
63
+ File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
64
+ puts "Traefik configuration written to /etc/traefik/harbr.toml"
102
65
  end
103
-
104
- def run_container(manifest)
105
- puts "Starting container: next.#{manifest.name}"
106
- port = `port assign next.#{manifest.port}`.strip
107
- puts "Port assigned: #{port}"
108
-
109
- `rm -rf /etc/sv/harbr/#{manifest.name}/next`
110
-
111
- create_a_service(manifest.name, port)
112
-
113
- containers = Container::Repository.new
114
- container = containers.find_by_header("next.#{manifest.host}")
115
-
66
+
67
+ def collate_containers(name,host,port)
68
+
69
+ containers = Harbr::Container::Repository.new
70
+ container = containers.find_by_header(host)
71
+
116
72
  if container.nil?
117
- container = Container.new
118
- container.name = "next-#{manifest.name}"
119
- container.host_header = "next.#{manifest.host}"
73
+ container = Harbr::Container.new
74
+ container.name = name
75
+ container.host_header =host
120
76
  container.ip = "127.0.0.1"
121
77
  container.port = port
122
78
  containers.create(container)
@@ -124,27 +80,157 @@ module Harbr
124
80
  container.port = port
125
81
  containers.update(container)
126
82
  end
83
+ containers.all
84
+ end
85
+
86
+
87
+ module Runit
88
+
89
+ class Run
90
+ def initialize(container, port)
91
+ @container_name = container
92
+ @port = port
93
+ end
94
+
95
+ def to_s
96
+ script_template = <<~SCRIPT
97
+ #!/bin/sh
98
+ exec 2>&1
99
+ cd /var/harbr/#{@container_name}/current
100
+ exec ./exe/run #{@port}
101
+ SCRIPT
102
+ end
103
+
104
+ def link
105
+ "ln -s /etc/sv/harbr/#{@container_name} /etc/service/#{@container_name}"
106
+ end
107
+ end
108
+
109
+
110
+ class Finish
111
+ def initialize(port)
112
+ @port = port
113
+ end
114
+
115
+ def to_s
116
+ script_template = <<~SCRIPT
117
+ #!/bin/sh
118
+ sleep 3
119
+ `lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
120
+ SCRIPT
121
+ end
122
+ end
123
+
124
+ class Log
125
+ def initialize(container, port)
126
+ @container_name = container
127
+ end
128
+
129
+ def to_s
130
+ script_template = <<~SCRIPT
131
+ #!/bin/sh
132
+ exec svlogd -tt /var/log/harbr/#{@container_name}/next/
133
+ SCRIPT
134
+ end
135
+
136
+ end
137
+
138
+ module Next
139
+
140
+ class Run
141
+ def initialize(container, port)
142
+ @container_name = container
143
+ @port = port
144
+ end
145
+
146
+ def to_s
147
+ script_template = <<~SCRIPT
148
+ #!/bin/sh
149
+ exec 2>&1
150
+ cd /var/harbr/containers/#{@container_name}/next
151
+ exec ./exe/run #{@port}
152
+ SCRIPT
153
+ end
154
+ end
155
+
156
+ class Log
157
+ def initialize(container)
158
+ @container_name = container
159
+ end
160
+
161
+ def to_s
162
+ script_template = <<~SCRIPT
163
+ #!/bin/sh
164
+ exec svlogd -tt /var/log/harbr/#{@container_name}/next/
165
+ SCRIPT
166
+ end
167
+ end
168
+
169
+ end
170
+ end
171
+
172
+ def write_to_file(path, contents)
173
+ File.open(path, 'w') do |file|
174
+ file.write(contents)
175
+ end
176
+ end
177
+
178
+ def load_manifest(container, version)
179
+ manifest_path = "/var/harbr/containers/#{container}/versions/#{version}/config/manifest.yml"
180
+ raise "Manifest not found at #{manifest_path}" unless File.exist?(manifest_path)
181
+ manifest_data = YAML.load_file(manifest_path)
182
+ OpenStruct.new(manifest_data)
183
+ end
127
184
 
185
+ def perform
186
+ `bundle config set --local path 'vendor/bundle'`
187
+ `rm /var/harbr/.data/processed_next.txt`
128
188
 
189
+ Dir.glob('/var/harbr/containers/*').select { |f| File.directory? f }.each do |container_path|
190
+ latest_version = highest_numbered_directory("#{container_path}/versions")
191
+
192
+ version = get_container_name(latest_version)
193
+ name = get_container_name(container_path)
194
+ manifest = load_manifest(name,version)
129
195
 
130
- system("cd /var/harbr/#{manifest.name}/next && bundle install")
131
- system("sv restart next.#{manifest.name}")
132
- puts "Started container: next.#{manifest.name}"
133
-
134
- system("ln -s /var/harbr/#{manifest.name}/versions/#{manifest.version}/ /etc/sv/harbr/#{manifest.name}/next")
135
- puts "Linked to: /etc/sv/harbr/#{manifest.name}/next"
136
-
137
-
196
+ check_container_version(name, version) do
138
197
 
139
- create_traefik_config(containers.all)
140
- end
198
+ current_path = "/var/harbr/containers/#{name}/versions/#{version}"
199
+
200
+ port = `port assign next.#{manifest.port}`.strip
201
+
202
+ Dir.chdir current_path do
203
+
204
+ system "sv stop #{name}"
205
+ system "bundle install"
206
+
207
+ `mkdir -p /etc/sv/harbr/#{name}/next`
208
+ `mkdir -p /etc/sv/harbr/#{name}/next/log`
209
+ `mkdir -p /var/log/harbr/#{name}/next/log`
210
+
211
+ write_to_file "/etc/sv/harbr/#{name}/next/run", Runit::Next::Run.new(name,port).to_s
212
+ write_to_file "/etc/sv/harbr/#{name}/next/finish", Runit::Finish.new(port).to_s
213
+ write_to_file "/etc/sv/harbr/#{name}/next/log/run", Runit::Next::Log.new(name).to_s
214
+
215
+ `chmod +x /etc/sv/harbr/#{name}/next/run`
216
+ `chmod +x /etc/sv/harbr/#{name}/next/log/run`
217
+ `chmod +x /etc/sv/harbr/#{name}/next/finish`
218
+
219
+
220
+ system "ln -s /var/harbr/containers/#{name}/versions/#{version} /var/harbr/containers/#{name}/next"
221
+ system "ln -s /etc/sv/harbr/#{name}/next /etc/service/next.#{name}"
222
+
223
+ containers = collate_containers("next.#{name}","next.#{manifest.host}",port)
224
+ create_traefik_config(containers)
225
+ end
226
+
227
+ puts "process #{version} of #{name}"
228
+ end
229
+ end
141
230
 
142
- def perform(container, version)
143
- puts "Running tasks for container: 'next.#{container}', Version: '#{version}'"
144
- manifest = load_manifest(container, version)
145
- puts "Manifest: #{manifest}"
146
- run_container(manifest)
147
231
  end
232
+
148
233
  end
234
+
149
235
  end
150
236
  end
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.0.75"
4
+ VERSION = "0.0.76"
5
5
  end
data/lib/harbr.rb CHANGED
@@ -12,12 +12,94 @@ require_relative "harbr/container"
12
12
  require_relative "harbr/job"
13
13
  require_relative "harbr/next/job"
14
14
 
15
-
16
15
  # Harbr module for managing containers, jobs, ports, and 2s
17
16
  module Harbr
18
17
  DEFAULT_DIRECTORY = "/var/harbr"
19
18
  DEFAULT_DIRECTORY_DATA_DIR = "#{DEFAULT_DIRECTORY}/.data"
20
19
  class Error < StandardError; end
20
+
21
+ def self.highest_numbered_directory(path)
22
+ directories = Dir.glob("#{path}/*").select { |entry| File.directory?(entry) }
23
+ directories.max_by { |entry| entry[/\d+/].to_i }
24
+ end
25
+
26
+ module Runit
27
+ class Run
28
+ def initialize(container, port)
29
+ @container_name = container
30
+ @port = port
31
+ end
32
+
33
+ def to_s
34
+ <<~SCRIPT
35
+ #!/bin/sh
36
+ exec 2>&1
37
+ cd /var/harbr/#{@container_name}/current
38
+ exec ./exe/run #{@port}
39
+ SCRIPT
40
+ end
41
+
42
+ def link
43
+ "ln -s /etc/sv/harbr/#{@container_name} /etc/service/#{@container_name}"
44
+ end
45
+ end
46
+
47
+ class Log
48
+ def initialize(container, port)
49
+ @container_name = container
50
+ end
51
+
52
+ def to_s
53
+ <<~SCRIPT
54
+ #!/bin/sh
55
+ exec svlogd -tt /var/log/harbr/#{@container_name}/next/
56
+ SCRIPT
57
+ end
58
+
59
+ def link
60
+ "ln -s /etc/sv/harbr/#{@container_name}/log /etc/service/#{@container_name}/log"
61
+ end
62
+ end
63
+
64
+ module Next
65
+ class Run
66
+ def initialize(container, port)
67
+ @container_name = container
68
+ @port = port
69
+ end
70
+
71
+ def to_s
72
+ <<~SCRIPT
73
+ #!/bin/sh
74
+ exec 2>&1
75
+ cd /var/harbr/#{@container_name}/next
76
+ exec ./exe/run #{@port}
77
+ SCRIPT
78
+ end
79
+
80
+ def link
81
+ "ln -s /etc/sv/harbr/#{@container_name}/next /etc/service/next.#{@container_name}"
82
+ end
83
+ end
84
+
85
+ class Log
86
+ def initialize(container, port)
87
+ @container_name = container
88
+ end
89
+
90
+ def to_s
91
+ <<~SCRIPT
92
+ #!/bin/sh
93
+ exec svlogd -tt /var/log/harbr/#{@container_name}/next/
94
+ SCRIPT
95
+ end
96
+
97
+ def link
98
+ "ln -s /etc/sv/harbr/#{container_name}/next/log/ /etc/service/next.#{container_name}/log"
99
+ end
100
+ end
101
+ end
102
+ end
21
103
  end
22
104
 
23
105
  Dddr.configure do |config|
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.0.75
4
+ version: 0.0.76
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-12 00:00:00.000000000 Z
11
+ date: 2023-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: listen