harbr 0.1.19 → 0.1.21
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 +4 -4
- data/exe/harbr +22 -27
- data/lib/harbr/job.rb +17 -32
- data/lib/harbr/next/job.rb +28 -44
- 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: c4ca6570daeb86eb833723ce24c8efde8d457af059b8c15f801aea62c134bfd5
|
|
4
|
+
data.tar.gz: 4c9fd5523d6f73d14871ac5bbf8b6ca7b659e31513fa0654649eee19045546bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 28161c6842f7c0b904b8863a2d122ffb0c0a934a72f5778f29f20f882757b8ed876f28dc686a136225107b1feedb911ebbee5dac39c15adf2567424d62d08f47
|
|
7
|
+
data.tar.gz: e2996597d6be9bccc59471f04e791b4b721717965bde619882b593be4b76f2b554c5d466f5d485984c4cf5a7a40254d028e06cf5903365a61bc7622340d8c199
|
data/exe/harbr
CHANGED
|
@@ -110,37 +110,36 @@ class HarbrCLI < Thor
|
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
desc "destroy", "Destroy a container and remove all traces"
|
|
113
|
-
def destroy(
|
|
114
|
-
puts "Destroying container: #{
|
|
115
|
-
puts `sv stop #{container_name}`
|
|
113
|
+
def destroy(name)
|
|
114
|
+
puts "Destroying container: #{name}"
|
|
116
115
|
|
|
117
116
|
container_repo = Harbr::Container::Repository.new
|
|
118
|
-
container = container_repo.find_by_name(container_name)
|
|
119
|
-
if container
|
|
120
|
-
puts `port release #{container.port}`
|
|
121
|
-
create_traefik_config(container_repo.all)
|
|
122
117
|
|
|
123
|
-
|
|
118
|
+
[name, "next.#{name}"].each do |container_name|
|
|
119
|
+
container = container_repo.find_by_name(container_name)
|
|
120
|
+
|
|
124
121
|
`rm -rf /etc/service/#{container_name}`
|
|
125
122
|
`rm -rf /etc/sv/harbr/#{container_name}`
|
|
126
|
-
`rm -rf /var/log/harbr/#{container_name}`
|
|
127
123
|
|
|
128
|
-
`lsof -i :#{container.port} | awk 'NR!=1 {print $2}' | xargs kill`
|
|
129
124
|
container_repo.delete(container)
|
|
130
|
-
|
|
131
125
|
puts "Container #{container_name} destroyed successfully."
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
puts "Container #{container_name} not found."
|
|
126
|
+
`port release #{container.port}`
|
|
127
|
+
puts "released port #{container.port} successfully."
|
|
135
128
|
end
|
|
129
|
+
|
|
130
|
+
`rm -rf /var/harbr/containers/#{name}`
|
|
131
|
+
`rm -rf /var/log/harbr/#{name}`
|
|
132
|
+
|
|
133
|
+
create_traefik_config(container_repo.all)
|
|
134
|
+
|
|
136
135
|
end
|
|
137
136
|
|
|
138
137
|
desc "logs", "Show logs"
|
|
139
138
|
def logs
|
|
140
|
-
|
|
139
|
+
exec "tail -f /var/log/harbr/current"
|
|
141
140
|
end
|
|
142
141
|
|
|
143
|
-
desc "peek CONTAINER", "Peek in a given container"
|
|
142
|
+
desc "peek CONTAINER", "Peek in a given container"
|
|
144
143
|
def peek(container)
|
|
145
144
|
container_repo = Harbr::Container::Repository.new
|
|
146
145
|
container = container_repo.find_by_name(container)
|
|
@@ -151,7 +150,6 @@ desc "peek CONTAINER", "Peek in a given container"
|
|
|
151
150
|
end
|
|
152
151
|
end
|
|
153
152
|
|
|
154
|
-
|
|
155
153
|
desc "setup", "Set up Harbr environment"
|
|
156
154
|
def setup
|
|
157
155
|
# Check and create /var/harbr directory
|
|
@@ -173,19 +171,17 @@ desc "peek CONTAINER", "Peek in a given container"
|
|
|
173
171
|
|
|
174
172
|
desc "deploy", "deploy a container to production"
|
|
175
173
|
def deploy(name)
|
|
176
|
-
|
|
177
174
|
Dir.chdir("/var/harbr/containers/#{name}/") do
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
/(?<current>. * -> (?<path>.*))/ =~ `ls -l /var/harbr/containers/#{name}/current`
|
|
176
|
+
|
|
181
177
|
`rm -r rollback`
|
|
182
178
|
`ln -sf #{$2} rollback`
|
|
183
179
|
|
|
184
|
-
/(?<next>. * -> (?<path>.*))
|
|
180
|
+
/(?<next>. * -> (?<path>.*))/ =~ `ls -l /var/harbr/containers/#{name}/next`
|
|
185
181
|
`rm -r current`
|
|
186
182
|
`ln -sf #{$2} current`
|
|
187
183
|
`sv restart #{name}`
|
|
188
|
-
end
|
|
184
|
+
end
|
|
189
185
|
end
|
|
190
186
|
|
|
191
187
|
desc "rollback", "rollback last deploy"
|
|
@@ -193,15 +189,14 @@ desc "peek CONTAINER", "Peek in a given container"
|
|
|
193
189
|
Dir.chdir("/var/harbr/containers/#{name}") do
|
|
194
190
|
if File.exist?("rollback")
|
|
195
191
|
Dir.chdir("/var/harbr/containers/#{name}/") do
|
|
196
|
-
/(?<current>. * -> (?<path>.*))
|
|
192
|
+
/(?<current>. * -> (?<path>.*))/ =~ `ls -l /var/harbr/containers/#{name}/rollback`
|
|
197
193
|
`rm -r current`
|
|
198
194
|
`ln -sf #{$2} current`
|
|
199
195
|
`sv restart #{name}`
|
|
200
|
-
end
|
|
196
|
+
end
|
|
201
197
|
puts "rollback successful"
|
|
202
198
|
end
|
|
203
|
-
end
|
|
204
|
-
|
|
199
|
+
end
|
|
205
200
|
end
|
|
206
201
|
desc "monitor", "Monitor /var/harbr/comtainers for new container versions"
|
|
207
202
|
def monitor
|
data/lib/harbr/job.rb
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "harbr"
|
|
2
2
|
module Harbr
|
|
3
3
|
class Job
|
|
4
4
|
include SuckerPunch::Job
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
def get_container_name(path)
|
|
7
7
|
File.basename(path)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
def create_traefik_config(containers)
|
|
12
11
|
config = {
|
|
13
12
|
"http" => {
|
|
@@ -24,7 +23,7 @@ module Harbr
|
|
|
24
23
|
|
|
25
24
|
containers.each do |container|
|
|
26
25
|
container.ip = "127.0.0.1"
|
|
27
|
-
name = container.name.
|
|
26
|
+
name = container.name.tr(".", "-")
|
|
28
27
|
|
|
29
28
|
# Create the router with TLS enabled and specific format
|
|
30
29
|
router_key = "#{name}-router-secure"
|
|
@@ -50,15 +49,14 @@ module Harbr
|
|
|
50
49
|
puts "Traefik configuration written to /etc/traefik/harbr.toml"
|
|
51
50
|
end
|
|
52
51
|
|
|
53
|
-
def collate_containers(name,host,port)
|
|
54
|
-
|
|
52
|
+
def collate_containers(name, host, port)
|
|
55
53
|
containers = Harbr::Container::Repository.new
|
|
56
54
|
container = containers.find_by_header(host)
|
|
57
55
|
|
|
58
56
|
if container.nil?
|
|
59
57
|
container = Harbr::Container.new
|
|
60
58
|
container.name = name
|
|
61
|
-
container.host_header =host
|
|
59
|
+
container.host_header = host
|
|
62
60
|
container.ip = "127.0.0.1"
|
|
63
61
|
container.port = port
|
|
64
62
|
containers.create(container)
|
|
@@ -69,9 +67,7 @@ module Harbr
|
|
|
69
67
|
containers.all
|
|
70
68
|
end
|
|
71
69
|
|
|
72
|
-
|
|
73
70
|
module Runit
|
|
74
|
-
|
|
75
71
|
class Run
|
|
76
72
|
def initialize(container, port)
|
|
77
73
|
@container_name = container
|
|
@@ -80,10 +76,10 @@ module Harbr
|
|
|
80
76
|
|
|
81
77
|
def to_s
|
|
82
78
|
script_template = <<~SCRIPT
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
#!/bin/sh
|
|
80
|
+
exec 2>&1
|
|
81
|
+
cd /var/harbr/containers/#{@container_name}/current
|
|
82
|
+
exec ./exe/run #{@port} live
|
|
87
83
|
SCRIPT
|
|
88
84
|
end
|
|
89
85
|
|
|
@@ -92,7 +88,6 @@ module Harbr
|
|
|
92
88
|
end
|
|
93
89
|
end
|
|
94
90
|
|
|
95
|
-
|
|
96
91
|
class Finish
|
|
97
92
|
def initialize(port)
|
|
98
93
|
@port = port
|
|
@@ -100,9 +95,9 @@ module Harbr
|
|
|
100
95
|
|
|
101
96
|
def to_s
|
|
102
97
|
script_template = <<~SCRIPT
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
#!/bin/sh
|
|
99
|
+
sleep 3
|
|
100
|
+
`lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
|
|
106
101
|
SCRIPT
|
|
107
102
|
end
|
|
108
103
|
end
|
|
@@ -114,19 +109,15 @@ module Harbr
|
|
|
114
109
|
|
|
115
110
|
def to_s
|
|
116
111
|
script_template = <<~SCRIPT
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
#!/bin/sh
|
|
113
|
+
exec svlogd -tt /var/log/harbr/#{@container_name}
|
|
119
114
|
SCRIPT
|
|
120
115
|
end
|
|
121
|
-
|
|
122
116
|
end
|
|
123
|
-
|
|
124
117
|
end
|
|
125
118
|
|
|
126
119
|
def write_to_file(path, contents)
|
|
127
|
-
File.
|
|
128
|
-
file.write(contents)
|
|
129
|
-
end
|
|
120
|
+
File.write(path, contents)
|
|
130
121
|
end
|
|
131
122
|
|
|
132
123
|
def load_manifest(container, version)
|
|
@@ -136,16 +127,13 @@ module Harbr
|
|
|
136
127
|
OpenStruct.new(manifest_data)
|
|
137
128
|
end
|
|
138
129
|
|
|
139
|
-
def perform(name,version)
|
|
140
|
-
|
|
130
|
+
def perform(name, version)
|
|
141
131
|
Dir.chdir "/var/harbr/containers/#{name}/versions/#{version}" do
|
|
142
|
-
|
|
143
132
|
`bundle config set --local path 'vendor/bundle'`
|
|
144
133
|
manifest = load_manifest(name, version)
|
|
145
134
|
port = `port assign #{manifest.port}`.strip
|
|
146
135
|
system "sv stop #{name}" if File.exist?("/etc/service/#{name}")
|
|
147
|
-
system
|
|
148
|
-
|
|
136
|
+
system "bundle install"
|
|
149
137
|
|
|
150
138
|
`mkdir -p /etc/sv/harbr/#{name}`
|
|
151
139
|
`mkdir -p /etc/sv/harbr/#{name}/log`
|
|
@@ -166,9 +154,6 @@ module Harbr
|
|
|
166
154
|
create_traefik_config(containers)
|
|
167
155
|
puts "process #{version} of #{name}"
|
|
168
156
|
end
|
|
169
|
-
|
|
170
157
|
end
|
|
171
|
-
|
|
172
158
|
end
|
|
173
|
-
|
|
174
159
|
end
|
data/lib/harbr/next/job.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
1
|
+
require "yaml"
|
|
2
|
+
require "ostruct"
|
|
3
|
+
require "sucker_punch"
|
|
4
4
|
|
|
5
|
-
require
|
|
5
|
+
require "harbr"
|
|
6
6
|
module Harbr
|
|
7
7
|
module Next
|
|
8
8
|
class Job
|
|
@@ -28,7 +28,7 @@ module Harbr
|
|
|
28
28
|
|
|
29
29
|
containers.each do |container|
|
|
30
30
|
container.ip = "127.0.0.1"
|
|
31
|
-
name = container.name.
|
|
31
|
+
name = container.name.tr(".", "-")
|
|
32
32
|
|
|
33
33
|
# Create the router with TLS enabled and specific format
|
|
34
34
|
router_key = "#{name}-router-secure"
|
|
@@ -54,17 +54,14 @@ module Harbr
|
|
|
54
54
|
puts "Traefik configuration written to /etc/traefik/harbr.toml"
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def collate_containers(name,host,port)
|
|
60
|
-
|
|
57
|
+
def collate_containers(name, host, port)
|
|
61
58
|
containers = Harbr::Container::Repository.new
|
|
62
59
|
container = containers.find_by_header(host)
|
|
63
60
|
|
|
64
61
|
if container.nil?
|
|
65
62
|
container = Harbr::Container.new
|
|
66
63
|
container.name = name
|
|
67
|
-
container.host_header =host
|
|
64
|
+
container.host_header = host
|
|
68
65
|
container.ip = "127.0.0.1"
|
|
69
66
|
container.port = port
|
|
70
67
|
containers.create(container)
|
|
@@ -75,9 +72,7 @@ module Harbr
|
|
|
75
72
|
containers.all
|
|
76
73
|
end
|
|
77
74
|
|
|
78
|
-
|
|
79
75
|
module Runit
|
|
80
|
-
|
|
81
76
|
class Run
|
|
82
77
|
def initialize(container, port)
|
|
83
78
|
@container_name = container
|
|
@@ -86,10 +81,10 @@ module Harbr
|
|
|
86
81
|
|
|
87
82
|
def to_s
|
|
88
83
|
script_template = <<~SCRIPT
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
#!/bin/sh
|
|
85
|
+
exec 2>&1
|
|
86
|
+
cd /var/harbr/#{@container_name}/current
|
|
87
|
+
exec ./exe/run #{@port} live
|
|
93
88
|
SCRIPT
|
|
94
89
|
end
|
|
95
90
|
|
|
@@ -98,7 +93,6 @@ module Harbr
|
|
|
98
93
|
end
|
|
99
94
|
end
|
|
100
95
|
|
|
101
|
-
|
|
102
96
|
class Finish
|
|
103
97
|
def initialize(port)
|
|
104
98
|
@port = port
|
|
@@ -106,9 +100,9 @@ module Harbr
|
|
|
106
100
|
|
|
107
101
|
def to_s
|
|
108
102
|
script_template = <<~SCRIPT
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
#!/bin/sh
|
|
104
|
+
sleep 3
|
|
105
|
+
`lsof -i :#{@port} | awk 'NR!=1 {print $2}' | xargs kill`
|
|
112
106
|
SCRIPT
|
|
113
107
|
end
|
|
114
108
|
end
|
|
@@ -120,15 +114,13 @@ module Harbr
|
|
|
120
114
|
|
|
121
115
|
def to_s
|
|
122
116
|
script_template = <<~SCRIPT
|
|
123
|
-
|
|
124
|
-
|
|
117
|
+
#!/bin/sh
|
|
118
|
+
exec svlogd -tt /var/log/harbr/#{@container_name}/next/
|
|
125
119
|
SCRIPT
|
|
126
120
|
end
|
|
127
|
-
|
|
128
121
|
end
|
|
129
122
|
|
|
130
123
|
module Next
|
|
131
|
-
|
|
132
124
|
class Run
|
|
133
125
|
def initialize(container, port)
|
|
134
126
|
@container_name = container
|
|
@@ -137,10 +129,10 @@ module Harbr
|
|
|
137
129
|
|
|
138
130
|
def to_s
|
|
139
131
|
script_template = <<~SCRIPT
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
132
|
+
#!/bin/sh
|
|
133
|
+
exec 2>&1
|
|
134
|
+
cd /var/harbr/containers/#{@container_name}/next
|
|
135
|
+
exec ./exe/run #{@port} next
|
|
144
136
|
SCRIPT
|
|
145
137
|
end
|
|
146
138
|
end
|
|
@@ -152,19 +144,16 @@ module Harbr
|
|
|
152
144
|
|
|
153
145
|
def to_s
|
|
154
146
|
script_template = <<~SCRIPT
|
|
155
|
-
|
|
156
|
-
|
|
147
|
+
#!/bin/sh
|
|
148
|
+
exec svlogd -tt /var/log/harbr/#{@container_name}/next/
|
|
157
149
|
SCRIPT
|
|
158
150
|
end
|
|
159
151
|
end
|
|
160
|
-
|
|
161
152
|
end
|
|
162
153
|
end
|
|
163
154
|
|
|
164
155
|
def write_to_file(path, contents)
|
|
165
|
-
File.
|
|
166
|
-
file.write(contents)
|
|
167
|
-
end
|
|
156
|
+
File.write(path, contents)
|
|
168
157
|
end
|
|
169
158
|
|
|
170
159
|
def load_manifest(container, version)
|
|
@@ -177,21 +166,20 @@ module Harbr
|
|
|
177
166
|
def perform(name, version)
|
|
178
167
|
`bundle config set --local path 'vendor/bundle'`
|
|
179
168
|
|
|
180
|
-
manifest = load_manifest(name,version)
|
|
169
|
+
manifest = load_manifest(name, version)
|
|
181
170
|
current_path = "/var/harbr/containers/#{name}/versions/#{version}"
|
|
182
171
|
|
|
183
172
|
port = `port assign next.#{manifest.port}`.strip
|
|
184
173
|
|
|
185
174
|
Dir.chdir current_path do
|
|
186
|
-
|
|
187
175
|
system "sv stop next.#{name}"
|
|
188
|
-
system "bundle install"
|
|
176
|
+
system "bundle install"
|
|
189
177
|
|
|
190
178
|
`mkdir -p /etc/sv/harbr/#{name}/next`
|
|
191
179
|
`mkdir -p /etc/sv/harbr/#{name}/next/log`
|
|
192
180
|
`mkdir -p /var/log/harbr/#{name}/next/log`
|
|
193
181
|
|
|
194
|
-
write_to_file "/etc/sv/harbr/#{name}/next/run", Runit::Next::Run.new(name,port).to_s
|
|
182
|
+
write_to_file "/etc/sv/harbr/#{name}/next/run", Runit::Next::Run.new(name, port).to_s
|
|
195
183
|
write_to_file "/etc/sv/harbr/#{name}/next/finish", Runit::Finish.new(port).to_s
|
|
196
184
|
write_to_file "/etc/sv/harbr/#{name}/next/log/run", Runit::Next::Log.new(name).to_s
|
|
197
185
|
|
|
@@ -199,7 +187,6 @@ module Harbr
|
|
|
199
187
|
`chmod +x /etc/sv/harbr/#{name}/next/log/run`
|
|
200
188
|
`chmod +x /etc/sv/harbr/#{name}/next/finish`
|
|
201
189
|
|
|
202
|
-
|
|
203
190
|
system "rm /etc/service/next.#{name}"
|
|
204
191
|
system "rm /var/harbr/containers/#{name}/next"
|
|
205
192
|
|
|
@@ -212,14 +199,11 @@ module Harbr
|
|
|
212
199
|
system "sv restart next.#{name}"
|
|
213
200
|
end
|
|
214
201
|
|
|
215
|
-
containers = collate_containers("next.#{name}","next.#{manifest.host}",port)
|
|
202
|
+
containers = collate_containers("next.#{name}", "next.#{manifest.host}", port)
|
|
216
203
|
create_traefik_config(containers)
|
|
217
204
|
|
|
218
|
-
puts "process #{version} of #{name}"
|
|
219
|
-
|
|
205
|
+
puts "process #{version} of #{name}"
|
|
220
206
|
end
|
|
221
|
-
|
|
222
207
|
end
|
|
223
|
-
|
|
224
208
|
end
|
|
225
209
|
end
|
data/lib/harbr/version.rb
CHANGED