kamal 1.6.0 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kamal/cli/accessory.rb +5 -3
- data/lib/kamal/cli/app/boot.rb +2 -2
- data/lib/kamal/cli/app.rb +7 -4
- data/lib/kamal/cli/build.rb +13 -10
- data/lib/kamal/cli/healthcheck/poller.rb +2 -2
- data/lib/kamal/cli/main.rb +15 -2
- data/lib/kamal/cli/registry.rb +9 -10
- data/lib/kamal/cli/templates/sample_hooks/docker-setup.sample +1 -1
- data/lib/kamal/cli/traefik.rb +5 -3
- data/lib/kamal/cli.rb +1 -1
- data/lib/kamal/commands/accessory.rb +4 -4
- data/lib/kamal/commands/app/logging.rb +4 -4
- data/lib/kamal/commands/builder/base.rb +13 -0
- data/lib/kamal/commands/builder/multiarch/remote.rb +10 -0
- data/lib/kamal/commands/builder/multiarch.rb +4 -0
- data/lib/kamal/commands/builder/native/cached.rb +10 -1
- data/lib/kamal/commands/builder/native/remote.rb +8 -0
- data/lib/kamal/commands/builder.rb +17 -11
- data/lib/kamal/commands/registry.rb +4 -13
- data/lib/kamal/commands/traefik.rb +8 -47
- data/lib/kamal/configuration/accessory.rb +30 -41
- data/lib/kamal/configuration/boot.rb +9 -4
- data/lib/kamal/configuration/builder.rb +33 -33
- data/lib/kamal/configuration/docs/accessory.yml +90 -0
- data/lib/kamal/configuration/docs/boot.yml +19 -0
- data/lib/kamal/configuration/docs/builder.yml +107 -0
- data/lib/kamal/configuration/docs/configuration.yml +157 -0
- data/lib/kamal/configuration/docs/env.yml +72 -0
- data/lib/kamal/configuration/docs/healthcheck.yml +59 -0
- data/lib/kamal/configuration/docs/logging.yml +21 -0
- data/lib/kamal/configuration/docs/registry.yml +49 -0
- data/lib/kamal/configuration/docs/role.yml +52 -0
- data/lib/kamal/configuration/docs/servers.yml +27 -0
- data/lib/kamal/configuration/docs/ssh.yml +46 -0
- data/lib/kamal/configuration/docs/sshkit.yml +23 -0
- data/lib/kamal/configuration/docs/traefik.yml +62 -0
- data/lib/kamal/configuration/env/tag.rb +1 -1
- data/lib/kamal/configuration/env.rb +10 -14
- data/lib/kamal/configuration/healthcheck.rb +63 -0
- data/lib/kamal/configuration/logging.rb +33 -0
- data/lib/kamal/configuration/registry.rb +31 -0
- data/lib/kamal/configuration/role.rb +53 -65
- data/lib/kamal/configuration/servers.rb +18 -0
- data/lib/kamal/configuration/ssh.rb +11 -8
- data/lib/kamal/configuration/sshkit.rb +9 -7
- data/lib/kamal/configuration/traefik.rb +60 -0
- data/lib/kamal/configuration/validation.rb +27 -0
- data/lib/kamal/configuration/validator/accessory.rb +9 -0
- data/lib/kamal/configuration/validator/alias.rb +19 -0
- data/lib/kamal/configuration/validator/builder.rb +9 -0
- data/lib/kamal/configuration/validator/env.rb +54 -0
- data/lib/kamal/configuration/validator/registry.rb +25 -0
- data/lib/kamal/configuration/validator/role.rb +11 -0
- data/lib/kamal/configuration/validator/servers.rb +7 -0
- data/lib/kamal/configuration/validator.rb +140 -0
- data/lib/kamal/configuration.rb +41 -66
- data/lib/kamal/version.rb +1 -1
- data/lib/kamal.rb +2 -0
- metadata +50 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a33d6d0c371102cfe47ba0b15f51059aa1d955667edbfbad137d7a5a56865893
|
4
|
+
data.tar.gz: 065db28e7bfcd285142aa493b4c7cb70a706dfdd58ec504e6f9e4884c35320e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73a6ce6d0d408024c96b84656958847044c477a9447a12d6861af7a8589f354060b4465100a1873aefa9b4141831751867de7b5181bb71e0353940291712b18d
|
7
|
+
data.tar.gz: 5c3deef19e9759abf5dc7b11a04799c53372097b32055e95543fd68a444e79056c48507646c7c1dfbc6c098a45655983d9791237a68a1c944f3c86ec7361990b
|
data/lib/kamal/cli/accessory.rb
CHANGED
@@ -149,23 +149,25 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|
149
149
|
option :since, aliases: "-s", desc: "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)"
|
150
150
|
option :lines, type: :numeric, aliases: "-n", desc: "Number of log lines to pull from each server"
|
151
151
|
option :grep, aliases: "-g", desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
152
|
+
option :grep_options, aliases: "-o", desc: "Additional options supplied to grep"
|
152
153
|
option :follow, aliases: "-f", desc: "Follow logs on primary server (or specific host set by --hosts)"
|
153
154
|
def logs(name)
|
154
155
|
with_accessory(name) do |accessory, hosts|
|
155
156
|
grep = options[:grep]
|
157
|
+
grep_options = options[:grep_options]
|
156
158
|
|
157
159
|
if options[:follow]
|
158
160
|
run_locally do
|
159
161
|
info "Following logs on #{hosts}..."
|
160
|
-
info accessory.follow_logs(grep: grep)
|
161
|
-
exec accessory.follow_logs(grep: grep)
|
162
|
+
info accessory.follow_logs(grep: grep, grep_options: grep_options)
|
163
|
+
exec accessory.follow_logs(grep: grep, grep_options: grep_options)
|
162
164
|
end
|
163
165
|
else
|
164
166
|
since = options[:since]
|
165
167
|
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
|
166
168
|
|
167
169
|
on(hosts) do
|
168
|
-
puts capture_with_info(*accessory.logs(since: since, lines: lines, grep: grep))
|
170
|
+
puts capture_with_info(*accessory.logs(since: since, lines: lines, grep: grep, grep_options: grep_options))
|
169
171
|
end
|
170
172
|
end
|
171
173
|
end
|
data/lib/kamal/cli/app/boot.rb
CHANGED
@@ -72,7 +72,7 @@ class Kamal::Cli::App::Boot
|
|
72
72
|
|
73
73
|
def release_barrier
|
74
74
|
if barrier.open
|
75
|
-
info "First #{KAMAL.primary_role} container is healthy on #{host}, booting other roles"
|
75
|
+
info "First #{KAMAL.primary_role} container is healthy on #{host}, booting any other roles"
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -87,7 +87,7 @@ class Kamal::Cli::App::Boot
|
|
87
87
|
|
88
88
|
def close_barrier
|
89
89
|
if barrier.close
|
90
|
-
info "First #{KAMAL.primary_role} container is unhealthy on #{host}, not booting other roles"
|
90
|
+
info "First #{KAMAL.primary_role} container is unhealthy on #{host}, not booting any other roles"
|
91
91
|
error capture_with_info(*app.logs(version: version))
|
92
92
|
error capture_with_info(*app.container_health_log(version: version))
|
93
93
|
end
|
data/lib/kamal/cli/app.rb
CHANGED
@@ -14,7 +14,7 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Primary hosts and roles are returned first, so they can open the barrier
|
17
|
-
barrier = Kamal::Cli::Healthcheck::Barrier.new
|
17
|
+
barrier = Kamal::Cli::Healthcheck::Barrier.new
|
18
18
|
|
19
19
|
on(KAMAL.hosts, **KAMAL.boot_strategy) do |host|
|
20
20
|
KAMAL.roles_on(host).each do |role|
|
@@ -166,12 +166,15 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
|
166
166
|
option :since, aliases: "-s", desc: "Show lines since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)"
|
167
167
|
option :lines, type: :numeric, aliases: "-n", desc: "Number of lines to show from each server"
|
168
168
|
option :grep, aliases: "-g", desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
169
|
+
option :grep_options, aliases: "-o", desc: "Additional options supplied to grep"
|
169
170
|
option :follow, aliases: "-f", desc: "Follow log on primary server (or specific host set by --hosts)"
|
170
171
|
def logs
|
171
172
|
# FIXME: Catch when app containers aren't running
|
172
173
|
|
173
174
|
grep = options[:grep]
|
175
|
+
grep_options = options[:grep_options]
|
174
176
|
since = options[:since]
|
177
|
+
|
175
178
|
if options[:follow]
|
176
179
|
lines = options[:lines].presence || ((since || grep) ? nil : 10) # Default to 10 lines if since or grep isn't set
|
177
180
|
|
@@ -182,8 +185,8 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
|
182
185
|
role = KAMAL.roles_on(KAMAL.primary_host).first
|
183
186
|
|
184
187
|
app = KAMAL.app(role: role, host: host)
|
185
|
-
info app.follow_logs(host: KAMAL.primary_host, lines: lines, grep: grep)
|
186
|
-
exec app.follow_logs(host: KAMAL.primary_host, lines: lines, grep: grep)
|
188
|
+
info app.follow_logs(host: KAMAL.primary_host, lines: lines, grep: grep, grep_options: grep_options)
|
189
|
+
exec app.follow_logs(host: KAMAL.primary_host, lines: lines, grep: grep, grep_options: grep_options)
|
187
190
|
end
|
188
191
|
else
|
189
192
|
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
|
@@ -193,7 +196,7 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
|
193
196
|
|
194
197
|
roles.each do |role|
|
195
198
|
begin
|
196
|
-
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).logs(since: since, lines: lines, grep: grep))
|
199
|
+
puts_by_host host, capture_with_info(*KAMAL.app(role: role, host: host).logs(since: since, lines: lines, grep: grep, grep_options: grep_options))
|
197
200
|
rescue SSHKit::Command::Failed
|
198
201
|
puts_by_host host, "Nothing found"
|
199
202
|
end
|
data/lib/kamal/cli/build.rb
CHANGED
@@ -35,22 +35,25 @@ class Kamal::Cli::Build < Kamal::Cli::Base
|
|
35
35
|
|
36
36
|
run_locally do
|
37
37
|
begin
|
38
|
-
KAMAL.
|
39
|
-
|
38
|
+
context_hosts = capture_with_info(*KAMAL.builder.context_hosts).split("\n")
|
39
|
+
|
40
|
+
if context_hosts != KAMAL.builder.config_context_hosts
|
41
|
+
warn "Context hosts have changed, so re-creating builder, was: #{context_hosts.join(", ")}], now: #{KAMAL.builder.config_context_hosts.join(", ")}"
|
42
|
+
cli.remove
|
43
|
+
cli.create
|
40
44
|
end
|
41
45
|
rescue SSHKit::Command::Failed => e
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if cli.create
|
46
|
-
KAMAL.with_verbosity(:debug) do
|
47
|
-
Dir.chdir(KAMAL.config.builder.build_directory) { execute *push }
|
48
|
-
end
|
49
|
-
end
|
46
|
+
warn "Missing compatible builder, so creating a new one first"
|
47
|
+
if e.message =~ /(context not found|no builder)/
|
48
|
+
cli.create
|
50
49
|
else
|
51
50
|
raise
|
52
51
|
end
|
53
52
|
end
|
53
|
+
|
54
|
+
KAMAL.with_verbosity(:debug) do
|
55
|
+
Dir.chdir(KAMAL.config.builder.build_directory) { execute *push }
|
56
|
+
end
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
@@ -6,7 +6,7 @@ module Kamal::Cli::Healthcheck::Poller
|
|
6
6
|
|
7
7
|
def wait_for_healthy(pause_after_ready: false, &block)
|
8
8
|
attempt = 1
|
9
|
-
max_attempts = KAMAL.config.healthcheck
|
9
|
+
max_attempts = KAMAL.config.healthcheck.max_attempts
|
10
10
|
|
11
11
|
begin
|
12
12
|
case status = block.call
|
@@ -33,7 +33,7 @@ module Kamal::Cli::Healthcheck::Poller
|
|
33
33
|
|
34
34
|
def wait_for_unhealthy(pause_after_ready: false, &block)
|
35
35
|
attempt = 1
|
36
|
-
max_attempts = KAMAL.config.healthcheck
|
36
|
+
max_attempts = KAMAL.config.healthcheck.max_attempts
|
37
37
|
|
38
38
|
begin
|
39
39
|
case status = block.call
|
data/lib/kamal/cli/main.rb
CHANGED
@@ -11,6 +11,7 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|
11
11
|
|
12
12
|
say "Evaluate and push env files...", :magenta
|
13
13
|
invoke "kamal:cli:main:envify", [], invoke_options
|
14
|
+
invoke "kamal:cli:env:push", [], invoke_options
|
14
15
|
|
15
16
|
invoke "kamal:cli:accessory:boot", [ "all" ], invoke_options
|
16
17
|
deploy
|
@@ -25,7 +26,7 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|
25
26
|
invoke_options = deploy_options
|
26
27
|
|
27
28
|
say "Log into image registry...", :magenta
|
28
|
-
invoke "kamal:cli:registry:login", [], invoke_options
|
29
|
+
invoke "kamal:cli:registry:login", [], invoke_options.merge(skip_local: options[:skip_push])
|
29
30
|
|
30
31
|
if options[:skip_push]
|
31
32
|
say "Pull app image...", :magenta
|
@@ -126,6 +127,18 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|
126
127
|
end
|
127
128
|
end
|
128
129
|
|
130
|
+
desc "docs", "Show Kamal documentation for configuration setting"
|
131
|
+
def docs(section = nil)
|
132
|
+
case section
|
133
|
+
when NilClass
|
134
|
+
puts Kamal::Configuration.validation_doc
|
135
|
+
else
|
136
|
+
puts Kamal::Configuration.const_get(section.titlecase.to_sym).validation_doc
|
137
|
+
end
|
138
|
+
rescue NameError
|
139
|
+
puts "No documentation found for #{section}"
|
140
|
+
end
|
141
|
+
|
129
142
|
desc "init", "Create config stub in config/deploy.yml and env stub in .env"
|
130
143
|
option :bundle, type: :boolean, default: false, desc: "Add Kamal to the Gemfile and create a bin/kamal binstub"
|
131
144
|
def init
|
@@ -197,7 +210,7 @@ class Kamal::Cli::Main < Kamal::Cli::Base
|
|
197
210
|
invoke "kamal:cli:traefik:remove", [], options.without(:confirmed)
|
198
211
|
invoke "kamal:cli:app:remove", [], options.without(:confirmed)
|
199
212
|
invoke "kamal:cli:accessory:remove", [ "all" ], options
|
200
|
-
invoke "kamal:cli:registry:logout", [], options.without(:confirmed)
|
213
|
+
invoke "kamal:cli:registry:logout", [], options.without(:confirmed).merge(skip_local: true)
|
201
214
|
end
|
202
215
|
end
|
203
216
|
end
|
data/lib/kamal/cli/registry.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
class Kamal::Cli::Registry < Kamal::Cli::Base
|
2
2
|
desc "login", "Log in to registry locally and remotely"
|
3
|
+
option :skip_local, aliases: "-L", type: :boolean, default: false, desc: "Skip local login"
|
4
|
+
option :skip_remote, aliases: "-R", type: :boolean, default: false, desc: "Skip remote login"
|
3
5
|
def login
|
4
|
-
run_locally { execute *KAMAL.registry.login }
|
5
|
-
on(KAMAL.hosts) { execute *KAMAL.registry.login }
|
6
|
-
# FIXME: This rescue needed?
|
7
|
-
rescue ArgumentError => e
|
8
|
-
puts e.message
|
6
|
+
run_locally { execute *KAMAL.registry.login } unless options[:skip_local]
|
7
|
+
on(KAMAL.hosts) { execute *KAMAL.registry.login } unless options[:skip_remote]
|
9
8
|
end
|
10
9
|
|
11
|
-
desc "logout", "Log out of registry remotely"
|
10
|
+
desc "logout", "Log out of registry locally and remotely"
|
11
|
+
option :skip_local, aliases: "-L", type: :boolean, default: false, desc: "Skip local login"
|
12
|
+
option :skip_remote, aliases: "-R", type: :boolean, default: false, desc: "Skip remote login"
|
12
13
|
def logout
|
13
|
-
|
14
|
-
|
15
|
-
rescue ArgumentError => e
|
16
|
-
puts e.message
|
14
|
+
run_locally { execute *KAMAL.registry.logout } unless options[:skip_local]
|
15
|
+
on(KAMAL.hosts) { execute *KAMAL.registry.logout } unless options[:skip_remote]
|
17
16
|
end
|
18
17
|
end
|
data/lib/kamal/cli/traefik.rb
CHANGED
@@ -69,22 +69,24 @@ class Kamal::Cli::Traefik < Kamal::Cli::Base
|
|
69
69
|
option :since, aliases: "-s", desc: "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)"
|
70
70
|
option :lines, type: :numeric, aliases: "-n", desc: "Number of log lines to pull from each server"
|
71
71
|
option :grep, aliases: "-g", desc: "Show lines with grep match only (use this to fetch specific requests by id)"
|
72
|
+
option :grep_options, aliases: "-o", desc: "Additional options supplied to grep"
|
72
73
|
option :follow, aliases: "-f", desc: "Follow logs on primary server (or specific host set by --hosts)"
|
73
74
|
def logs
|
74
75
|
grep = options[:grep]
|
76
|
+
grep_options = options[:grep_options]
|
75
77
|
|
76
78
|
if options[:follow]
|
77
79
|
run_locally do
|
78
80
|
info "Following logs on #{KAMAL.primary_host}..."
|
79
|
-
info KAMAL.traefik.follow_logs(host: KAMAL.primary_host, grep: grep)
|
80
|
-
exec KAMAL.traefik.follow_logs(host: KAMAL.primary_host, grep: grep)
|
81
|
+
info KAMAL.traefik.follow_logs(host: KAMAL.primary_host, grep: grep, grep_options: grep_options)
|
82
|
+
exec KAMAL.traefik.follow_logs(host: KAMAL.primary_host, grep: grep, grep_options: grep_options)
|
81
83
|
end
|
82
84
|
else
|
83
85
|
since = options[:since]
|
84
86
|
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
|
85
87
|
|
86
88
|
on(KAMAL.traefik_hosts) do |host|
|
87
|
-
puts_by_host host, capture(*KAMAL.traefik.logs(since: since, lines: lines, grep: grep)), type: "Traefik"
|
89
|
+
puts_by_host host, capture(*KAMAL.traefik.logs(since: since, lines: lines, grep: grep, grep_options: grep_options)), type: "Traefik"
|
88
90
|
end
|
89
91
|
end
|
90
92
|
end
|
data/lib/kamal/cli.rb
CHANGED
@@ -36,17 +36,17 @@ class Kamal::Commands::Accessory < Kamal::Commands::Base
|
|
36
36
|
end
|
37
37
|
|
38
38
|
|
39
|
-
def logs(since: nil, lines: nil, grep: nil)
|
39
|
+
def logs(since: nil, lines: nil, grep: nil, grep_options: nil)
|
40
40
|
pipe \
|
41
41
|
docker(:logs, service_name, (" --since #{since}" if since), (" --tail #{lines}" if lines), "--timestamps", "2>&1"),
|
42
|
-
("grep '#{grep}'" if grep)
|
42
|
+
("grep '#{grep}'#{" #{grep_options}" if grep_options}" if grep)
|
43
43
|
end
|
44
44
|
|
45
|
-
def follow_logs(grep: nil)
|
45
|
+
def follow_logs(grep: nil, grep_options: nil)
|
46
46
|
run_over_ssh \
|
47
47
|
pipe \
|
48
48
|
docker(:logs, service_name, "--timestamps", "--tail", "10", "--follow", "2>&1"),
|
49
|
-
(%(grep "#{grep}") if grep)
|
49
|
+
(%(grep "#{grep}"#{" #{grep_options}" if grep_options}) if grep)
|
50
50
|
end
|
51
51
|
|
52
52
|
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module Kamal::Commands::App::Logging
|
2
|
-
def logs(version: nil, since: nil, lines: nil, grep: nil)
|
2
|
+
def logs(version: nil, since: nil, lines: nil, grep: nil, grep_options: nil)
|
3
3
|
pipe \
|
4
4
|
version ? container_id_for_version(version) : current_running_container_id,
|
5
5
|
"xargs docker logs#{" --since #{since}" if since}#{" --tail #{lines}" if lines} 2>&1",
|
6
|
-
("grep '#{grep}'" if grep)
|
6
|
+
("grep '#{grep}'#{" #{grep_options}" if grep_options}" if grep)
|
7
7
|
end
|
8
8
|
|
9
|
-
def follow_logs(host:, lines: nil, grep: nil)
|
9
|
+
def follow_logs(host:, lines: nil, grep: nil, grep_options: nil)
|
10
10
|
run_over_ssh \
|
11
11
|
pipe(
|
12
12
|
current_running_container_id,
|
13
13
|
"xargs docker logs --timestamps#{" --tail #{lines}" if lines} --follow 2>&1",
|
14
|
-
(%(grep "#{grep}") if grep)
|
14
|
+
(%(grep "#{grep}"#{" #{grep_options}" if grep_options}) if grep)
|
15
15
|
),
|
16
16
|
host: host
|
17
17
|
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
3
3
|
class BuilderError < StandardError; end
|
4
4
|
|
5
|
+
ENDPOINT_DOCKER_HOST_INSPECT = "'{{.Endpoints.docker.Host}}'"
|
6
|
+
|
5
7
|
delegate :argumentize, to: Kamal::Utils
|
6
8
|
delegate :args, :secrets, :dockerfile, :target, :local_arch, :local_host, :remote_arch, :remote_host, :cache_from, :cache_to, :ssh, to: :builder_config
|
7
9
|
|
@@ -30,6 +32,13 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
|
30
32
|
)
|
31
33
|
end
|
32
34
|
|
35
|
+
def context_hosts
|
36
|
+
:true
|
37
|
+
end
|
38
|
+
|
39
|
+
def config_context_hosts
|
40
|
+
[]
|
41
|
+
end
|
33
42
|
|
34
43
|
private
|
35
44
|
def build_tags
|
@@ -74,4 +83,8 @@ class Kamal::Commands::Builder::Base < Kamal::Commands::Base
|
|
74
83
|
def builder_config
|
75
84
|
config.builder
|
76
85
|
end
|
86
|
+
|
87
|
+
def context_host(builder_name)
|
88
|
+
docker :context, :inspect, builder_name, "--format", ENDPOINT_DOCKER_HOST_INSPECT
|
89
|
+
end
|
77
90
|
end
|
@@ -12,6 +12,16 @@ class Kamal::Commands::Builder::Multiarch::Remote < Kamal::Commands::Builder::Mu
|
|
12
12
|
super
|
13
13
|
end
|
14
14
|
|
15
|
+
def context_hosts
|
16
|
+
chain \
|
17
|
+
context_host(builder_name_with_arch(local_arch)),
|
18
|
+
context_host(builder_name_with_arch(remote_arch))
|
19
|
+
end
|
20
|
+
|
21
|
+
def config_context_hosts
|
22
|
+
[ local_host, remote_host ].compact
|
23
|
+
end
|
24
|
+
|
15
25
|
private
|
16
26
|
def builder_name
|
17
27
|
super + "-remote"
|
@@ -22,6 +22,10 @@ class Kamal::Commands::Builder::Multiarch < Kamal::Commands::Builder::Base
|
|
22
22
|
build_context
|
23
23
|
end
|
24
24
|
|
25
|
+
def context_hosts
|
26
|
+
docker :buildx, :inspect, builder_name, "> /dev/null"
|
27
|
+
end
|
28
|
+
|
25
29
|
private
|
26
30
|
def builder_name
|
27
31
|
"kamal-#{config.service}-multiarch"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Kamal::Commands::Builder::Native::Cached < Kamal::Commands::Builder::Native
|
2
2
|
def create
|
3
|
-
docker :buildx, :create, "--use", "--driver=docker-container"
|
3
|
+
docker :buildx, :create, "--name", builder_name, "--use", "--driver=docker-container"
|
4
4
|
end
|
5
5
|
|
6
6
|
def remove
|
@@ -13,4 +13,13 @@ class Kamal::Commands::Builder::Native::Cached < Kamal::Commands::Builder::Nativ
|
|
13
13
|
*build_options,
|
14
14
|
build_context
|
15
15
|
end
|
16
|
+
|
17
|
+
def context_hosts
|
18
|
+
docker :buildx, :inspect, builder_name, "> /dev/null"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def builder_name
|
23
|
+
"kamal-#{config.service}-native-cached"
|
24
|
+
end
|
16
25
|
end
|
@@ -26,6 +26,14 @@ class Kamal::Commands::Builder::Native::Remote < Kamal::Commands::Builder::Nativ
|
|
26
26
|
build_context
|
27
27
|
end
|
28
28
|
|
29
|
+
def context_hosts
|
30
|
+
context_host(builder_name_with_arch)
|
31
|
+
end
|
32
|
+
|
33
|
+
def config_context_hosts
|
34
|
+
[ remote_host ]
|
35
|
+
end
|
36
|
+
|
29
37
|
|
30
38
|
private
|
31
39
|
def builder_name
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require "active_support/core_ext/string/filters"
|
2
2
|
|
3
3
|
class Kamal::Commands::Builder < Kamal::Commands::Base
|
4
|
-
delegate :create, :remove, :push, :clean, :pull, :info, :
|
4
|
+
delegate :create, :remove, :push, :clean, :pull, :info, :context_hosts, :config_context_hosts, :validate_image,
|
5
|
+
to: :target
|
5
6
|
|
6
7
|
include Clone
|
7
8
|
|
@@ -10,17 +11,22 @@ class Kamal::Commands::Builder < Kamal::Commands::Base
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def target
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
if config.builder.multiarch?
|
15
|
+
if config.builder.remote?
|
16
|
+
if config.builder.local?
|
17
|
+
multiarch_remote
|
18
|
+
else
|
19
|
+
native_remote
|
20
|
+
end
|
21
|
+
else
|
22
|
+
multiarch
|
23
|
+
end
|
22
24
|
else
|
23
|
-
|
25
|
+
if config.builder.cached?
|
26
|
+
native_cached
|
27
|
+
else
|
28
|
+
native
|
29
|
+
end
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
@@ -3,21 +3,12 @@ class Kamal::Commands::Registry < Kamal::Commands::Base
|
|
3
3
|
|
4
4
|
def login
|
5
5
|
docker :login,
|
6
|
-
registry
|
7
|
-
"-u", sensitive(Kamal::Utils.escape_shell_value(
|
8
|
-
"-p", sensitive(Kamal::Utils.escape_shell_value(
|
6
|
+
registry.server,
|
7
|
+
"-u", sensitive(Kamal::Utils.escape_shell_value(registry.username)),
|
8
|
+
"-p", sensitive(Kamal::Utils.escape_shell_value(registry.password))
|
9
9
|
end
|
10
10
|
|
11
11
|
def logout
|
12
|
-
docker :logout, registry
|
12
|
+
docker :logout, registry.server
|
13
13
|
end
|
14
|
-
|
15
|
-
private
|
16
|
-
def lookup(key)
|
17
|
-
if registry[key].is_a?(Array)
|
18
|
-
ENV.fetch(registry[key].first).dup
|
19
|
-
else
|
20
|
-
registry[key]
|
21
|
-
end
|
22
|
-
end
|
23
14
|
end
|
@@ -1,19 +1,6 @@
|
|
1
1
|
class Kamal::Commands::Traefik < Kamal::Commands::Base
|
2
2
|
delegate :argumentize, :optionize, to: Kamal::Utils
|
3
|
-
|
4
|
-
DEFAULT_IMAGE = "traefik:v2.10"
|
5
|
-
CONTAINER_PORT = 80
|
6
|
-
DEFAULT_ARGS = {
|
7
|
-
"log.level" => "DEBUG"
|
8
|
-
}
|
9
|
-
DEFAULT_LABELS = {
|
10
|
-
# These ensure we serve a 502 rather than a 404 if no containers are available
|
11
|
-
"traefik.http.routers.catchall.entryPoints" => "http",
|
12
|
-
"traefik.http.routers.catchall.rule" => "PathPrefix(`/`)",
|
13
|
-
"traefik.http.routers.catchall.service" => "unavailable",
|
14
|
-
"traefik.http.routers.catchall.priority" => 1,
|
15
|
-
"traefik.http.services.unavailable.loadbalancer.server.port" => "0"
|
16
|
-
}
|
3
|
+
delegate :port, :publish?, :labels, :env, :image, :options, :args, to: :"config.traefik"
|
17
4
|
|
18
5
|
def run
|
19
6
|
docker :run, "--name traefik",
|
@@ -46,16 +33,16 @@ class Kamal::Commands::Traefik < Kamal::Commands::Base
|
|
46
33
|
docker :ps, "--filter", "name=^traefik$"
|
47
34
|
end
|
48
35
|
|
49
|
-
def logs(since: nil, lines: nil, grep: nil)
|
36
|
+
def logs(since: nil, lines: nil, grep: nil, grep_options: nil)
|
50
37
|
pipe \
|
51
38
|
docker(:logs, "traefik", (" --since #{since}" if since), (" --tail #{lines}" if lines), "--timestamps", "2>&1"),
|
52
|
-
("grep '#{grep}'" if grep)
|
39
|
+
("grep '#{grep}'#{" #{grep_options}" if grep_options}" if grep)
|
53
40
|
end
|
54
41
|
|
55
|
-
def follow_logs(host:, grep: nil)
|
42
|
+
def follow_logs(host:, grep: nil, grep_options: nil)
|
56
43
|
run_over_ssh pipe(
|
57
44
|
docker(:logs, "traefik", "--timestamps", "--tail", "10", "--follow", "2>&1"),
|
58
|
-
(%(grep "#{grep}") if grep)
|
45
|
+
(%(grep "#{grep}"#{" #{grep_options}" if grep_options}) if grep)
|
59
46
|
).join(" "), host: host
|
60
47
|
end
|
61
48
|
|
@@ -67,16 +54,6 @@ class Kamal::Commands::Traefik < Kamal::Commands::Base
|
|
67
54
|
docker :image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=Traefik"
|
68
55
|
end
|
69
56
|
|
70
|
-
def port
|
71
|
-
"#{host_port}:#{CONTAINER_PORT}"
|
72
|
-
end
|
73
|
-
|
74
|
-
def env
|
75
|
-
Kamal::Configuration::Env.from_config \
|
76
|
-
config: config.traefik.fetch("env", {}),
|
77
|
-
secrets_file: File.join(config.host_env_directory, "traefik", "traefik.env")
|
78
|
-
end
|
79
|
-
|
80
57
|
def make_env_directory
|
81
58
|
make_directory(env.secrets_directory)
|
82
59
|
end
|
@@ -87,7 +64,7 @@ class Kamal::Commands::Traefik < Kamal::Commands::Base
|
|
87
64
|
|
88
65
|
private
|
89
66
|
def publish_args
|
90
|
-
argumentize "--publish", port
|
67
|
+
argumentize "--publish", port if publish?
|
91
68
|
end
|
92
69
|
|
93
70
|
def label_args
|
@@ -98,27 +75,11 @@ class Kamal::Commands::Traefik < Kamal::Commands::Base
|
|
98
75
|
env.args
|
99
76
|
end
|
100
77
|
|
101
|
-
def labels
|
102
|
-
DEFAULT_LABELS.merge(config.traefik["labels"] || {})
|
103
|
-
end
|
104
|
-
|
105
|
-
def image
|
106
|
-
config.traefik.fetch("image") { DEFAULT_IMAGE }
|
107
|
-
end
|
108
|
-
|
109
78
|
def docker_options_args
|
110
|
-
optionize(
|
79
|
+
optionize(options)
|
111
80
|
end
|
112
81
|
|
113
82
|
def cmd_option_args
|
114
|
-
|
115
|
-
optionize DEFAULT_ARGS.merge(args), with: "="
|
116
|
-
else
|
117
|
-
optionize DEFAULT_ARGS, with: "="
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def host_port
|
122
|
-
config.traefik["host_port"] || CONTAINER_PORT
|
83
|
+
optionize args, with: "="
|
123
84
|
end
|
124
85
|
end
|