harbr 0.0.68 → 0.0.70
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 -1
- data/lib/harbr/job.rb +1 -0
- data/lib/harbr/next/job.rb +129 -0
- data/lib/harbr/version.rb +1 -1
- data/lib/harbr.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e797dfe98b5f3f8b54dfd54f4300b98893c12d688aa799003cffc5616f59597
|
4
|
+
data.tar.gz: 3ba62188cf4275cfd2ee7d536bde3523ac3661df04bf25fa00f9f9df1e3ffb42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f84b37919dfbffb691e8823454457c40a2acd2d00710350632960e30462203f9638c5ab8b5b323ce08e373cadd3786b0409d87f717e1949317a651ea6f35c44a
|
7
|
+
data.tar.gz: edf02e829ba5bc62604ac3cd2fdbc7f3584f7a4305283426b2ae262d51be737263558d7e525c4949de37d1583d7a0a08ff77f7fd0fddc0730d62c74cced5469d
|
data/exe/harbr
CHANGED
@@ -76,7 +76,8 @@ class HarbrCLI < Thor
|
|
76
76
|
puts "Initial Deploy!!! of #{container}"
|
77
77
|
Harbr::Job.perform_async(container, version)
|
78
78
|
else
|
79
|
-
|
79
|
+
Harbr::Next::Job.perform_async(container, version)
|
80
|
+
puts "deploy next version #{version} of #{container}"
|
80
81
|
|
81
82
|
end
|
82
83
|
end
|
data/lib/harbr/job.rb
CHANGED
@@ -106,6 +106,7 @@ module Harbr
|
|
106
106
|
end
|
107
107
|
|
108
108
|
system("cd /var/harbr/#{manifest.name}/current && bundle install")
|
109
|
+
puts `lsof -i :#{port} | awk 'NR!=1 {print $2}' | xargs kill -9`
|
109
110
|
system("sv restart #{manifest.name}")
|
110
111
|
puts "Started container: #{manifest.name}"
|
111
112
|
create_traefik_config(containers.all)
|
@@ -0,0 +1,129 @@
|
|
1
|
+
module Harbr
|
2
|
+
module Next
|
3
|
+
class Job
|
4
|
+
include SuckerPunch::Job
|
5
|
+
|
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
|
+
end
|
12
|
+
|
13
|
+
def create_traefik_config(containers)
|
14
|
+
config = {
|
15
|
+
"http" => {
|
16
|
+
"routers" => {
|
17
|
+
"traefik-dashboard" => {
|
18
|
+
"rule" => "Host(`traefik.harbr.zero2one.ee`)",
|
19
|
+
"service" => "api@internal"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"services" => {}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
containers.each do |container|
|
27
|
+
container.ip = "127.0.0.1"
|
28
|
+
|
29
|
+
config["http"]["routers"]["#{container.name}-router"] = {
|
30
|
+
"rule" => "Host(`#{container.host_header}`)",
|
31
|
+
"service" => "#{container.name}-service"
|
32
|
+
}
|
33
|
+
config["http"]["services"]["#{container.name}-service"] = {
|
34
|
+
"loadBalancer" => {
|
35
|
+
"servers" => [{"url" => "http://#{container.ip}:#{container.port}"}]
|
36
|
+
}
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
File.write("/etc/traefik/harbr.toml", TomlRB.dump(config))
|
41
|
+
puts "Traefik configuration written to /etc/traefik/harbr.toml"
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_run_script(container_name, port)
|
45
|
+
service_dir = "/etc/sv/harbr/#{container_name}/next"
|
46
|
+
|
47
|
+
script_template = <<~SCRIPT
|
48
|
+
#!/bin/sh
|
49
|
+
exec 2>&1
|
50
|
+
cd /var/harbr/#{container_name}/next
|
51
|
+
exec ./exe/run #{port}
|
52
|
+
SCRIPT
|
53
|
+
|
54
|
+
service_dir = "/etc/sv/harbr/#{container_name}/next"
|
55
|
+
FileUtils.mkdir_p(service_dir)
|
56
|
+
|
57
|
+
File.write("#{service_dir}/run", script_template)
|
58
|
+
FileUtils.chmod("+x", "#{service_dir}/run")
|
59
|
+
puts "Run script created and made executable for container: next.#{container_name}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_log_script(container_name)
|
63
|
+
log_dir = "/var/log/harbr/#{container_name}/next"
|
64
|
+
|
65
|
+
FileUtils.mkdir_p(log_dir)
|
66
|
+
|
67
|
+
script_template = <<~SCRIPT
|
68
|
+
#!/bin/sh
|
69
|
+
exec svlogd -tt #{log_dir}/
|
70
|
+
SCRIPT
|
71
|
+
|
72
|
+
dir_path = "/etc/sv/harbr/#{container_name}/next/log"
|
73
|
+
FileUtils.mkdir_p(dir_path)
|
74
|
+
|
75
|
+
File.write("#{dir_path}/run", script_template)
|
76
|
+
FileUtils.chmod("+x", "#{dir_path}/run")
|
77
|
+
puts "Log script created and made executable for container: next.#{container_name}"
|
78
|
+
end
|
79
|
+
|
80
|
+
def create_a_service(container_name, port)
|
81
|
+
create_run_script(container_name, port)
|
82
|
+
create_log_script(container_name)
|
83
|
+
|
84
|
+
system("ln -s /etc/sv/harbr/#{container_name}/next /etc/service/next.#{container_name}") unless File.exist?("/etc/service/next.#{container_name}")
|
85
|
+
end
|
86
|
+
|
87
|
+
def run_container(manifest)
|
88
|
+
puts "Starting container: next.#{manifest.name}"
|
89
|
+
port = system("port assign next.#{manifest.port}").strip
|
90
|
+
puts "Port assigned: #{port}"
|
91
|
+
|
92
|
+
create_a_service(manifest.name, port)
|
93
|
+
|
94
|
+
containers = Container::Repository.new
|
95
|
+
container = containers.find_by_header("next.#{manifest.host}")
|
96
|
+
|
97
|
+
if container.nil?
|
98
|
+
container = Container.new
|
99
|
+
container.name = "next.#{manifest.name}"
|
100
|
+
container.host_header = "next.#{manifest.host}"
|
101
|
+
container.ip = "127.0.0.1"
|
102
|
+
container.port = port
|
103
|
+
containers.create(container)
|
104
|
+
else
|
105
|
+
container.port = port
|
106
|
+
containers.update(container)
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
system("cd /var/harbr/#{manifest.name}/next && bundle install")
|
112
|
+
|
113
|
+
|
114
|
+
puts `lsof -i :#{port} | awk 'NR!=1 {print $2}' | xargs kill -9`
|
115
|
+
system("sv restart next.#{manifest.name}")
|
116
|
+
|
117
|
+
puts "Started container: next.#{manifest.name}"
|
118
|
+
create_traefik_config(containers.all)
|
119
|
+
end
|
120
|
+
|
121
|
+
def perform(container, version)
|
122
|
+
puts "Running tasks for container: 'next.#{container}', Version: '#{version}'"
|
123
|
+
manifest = load_manifest(container, version)
|
124
|
+
puts "Manifest: #{manifest}"
|
125
|
+
run_container(manifest)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/lib/harbr/version.rb
CHANGED
data/lib/harbr.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.0.
|
4
|
+
version: 0.0.70
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: listen
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/harbr.rb
|
135
135
|
- lib/harbr/container.rb
|
136
136
|
- lib/harbr/job.rb
|
137
|
+
- lib/harbr/next/job.rb
|
137
138
|
- lib/harbr/version.rb
|
138
139
|
- sig/harbr.rbs
|
139
140
|
homepage: https://github.com/delaneyburke/harbr
|