dash 4.0.1 → 4.0.2

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: 8651f7a91510814ccfa26283d3aef0f364caa5c99419a76ee6cdb15820680148
4
- data.tar.gz: aef6a718f6f4d1427d6e20f73e3096eed8436426e32b6c6ea0a40f52e3588261
3
+ metadata.gz: d2fca4cca966b5e857e1d537799367c1493701a1e18e48a691c53dddac6b2c36
4
+ data.tar.gz: 2627d3e285ddbee1da9b4bc0705c38fb3825345f554b3b7e8f85598810c0b354
5
5
  SHA512:
6
- metadata.gz: da7a30a00bf6f622aeeb13889670133285a202c5c4481a7b83cc8d980624db48a0c5d8007e0efaf723489d4ea20672999dc8791e5ff4240b6f4fa65ba54a7380
7
- data.tar.gz: cdcf6391c305f5e84125687bb6f4174729a7c09819a08a5c8a26bd8de2fd5b10933606387f581187c94151574c2607d803689e3d97c2cffa00beab9e26375f09
6
+ metadata.gz: d40d1805b3f3b1ed9f0a79bf53a6d96709ea7c3693cc0d8319791e92b10c345aaa2743ef8fdbc568cf9b79de5b37659fb2fbbb75b7d4fac0f111322bc2f807c2
7
+ data.tar.gz: 2972113fc39cd3dcbdd6476d91634e29f757989ca4c84e9dbd1dac6443f6169b967a3f3c9b9c5d7ed9913d212e18d8239c1cd142981a7a14f90dea56769fca1b
@@ -76,6 +76,10 @@ class Dash::Cli::Proxy < Dash::Cli::Base
76
76
  info "Starting loadbalancer on #{host}..."
77
77
  execute *DASH.registry.login
78
78
 
79
+ # Bring a pre-rename volume across before the container can be created
80
+ # against an empty one. A no-op once it has been.
81
+ execute *DASH.loadbalancer.copy_legacy_config_volume
82
+
79
83
  # The load balancer terminates TLS and owns the cache, so its host
80
84
  # needs the proxy secrets (acme credentials, cache store) just like
81
85
  # the proxy hosts do.
@@ -126,6 +126,34 @@ module Dash::Commands
126
126
  [ :sh, "-c", "'#{command.flatten.join(" ").gsub("'", "'\\\\''")}'" ]
127
127
  end
128
128
 
129
+ # Adopts a pre-rename docker volume: creates `volume` from `legacy` if, and
130
+ # only if, `volume` is absent and `legacy` is present. A host with neither
131
+ # exits 0. The first word must be a program, never `!` — see
132
+ # Dash::Commands::Proxy#copy_legacy_config_volume.
133
+ def copy_legacy_volume(legacy:, volume:, image:)
134
+ any \
135
+ volume_exists(volume),
136
+ negate(volume_exists(legacy)),
137
+ [ "(", *combine(docker(:volume, :create, volume), copy_between_volumes(legacy, volume, image: image)), ")" ]
138
+ end
139
+
140
+ def negate(command)
141
+ [ "!", *command ]
142
+ end
143
+
144
+ def volume_exists(name)
145
+ docker :volume, :inspect, name, ">", "/dev/null", "2>&1"
146
+ end
147
+
148
+ def copy_between_volumes(from, to, image:)
149
+ docker \
150
+ :run, "--rm", "--user", "root", "--entrypoint", "sh",
151
+ "--volume", "#{from}:/from",
152
+ "--volume", "#{to}:/to",
153
+ image,
154
+ "-c", "'cp -a /from/. /to/'"
155
+ end
156
+
129
157
  def docker(*args)
130
158
  args.compact.unshift :docker
131
159
  end
@@ -37,6 +37,16 @@ class Dash::Commands::Loadbalancer < Dash::Commands::Base
37
37
  combine start, run, by: "||"
38
38
  end
39
39
 
40
+ # A dedicated load balancer host went through the 4.0 rename with nothing
41
+ # adopting its `kamal-loadbalancer-config` volume: the per-host proxies got
42
+ # Dash::Cli::Proxy::LegacyRename, the load balancer got a fresh empty volume
43
+ # and lost its routing table, dynamic domains and ACME cache. On a shared
44
+ # proxy host the volume is the proxy's own and LegacyRename already copied
45
+ # it, so this is a no-op there.
46
+ def copy_legacy_config_volume
47
+ copy_legacy_volume(legacy: legacy_config_volume_name, volume: config_volume_name, image: loadbalancer_config.run.image)
48
+ end
49
+
40
50
  def deploy(targets: [])
41
51
  docker :exec, container_name, "dash-proxy", "deploy", loadbalancer_config.config.service,
42
52
  *loadbalancer_config.deploy_command_args(targets: targets)
@@ -196,11 +206,15 @@ class Dash::Commands::Loadbalancer < Dash::Commands::Base
196
206
  # load balancer and a shared proxy host never fight over the same volume.
197
207
  # (The apps-config mount comes with run_args, via the proxy's run surface.)
198
208
  def config_volume
199
- if on_proxy_host?
200
- [ "--volume", "dash-proxy-config:/home/dash-proxy/.config/dash-proxy" ]
201
- else
202
- [ "--volume", "dash-loadbalancer-config:/home/dash-proxy/.config/dash-proxy" ]
203
- end
209
+ [ "--volume", "#{config_volume_name}:/home/dash-proxy/.config/dash-proxy" ]
210
+ end
211
+
212
+ def config_volume_name
213
+ on_proxy_host? ? Dash::Configuration::Proxy::CONFIG_VOLUME : Dash::Configuration::Proxy::LOADBALANCER_CONFIG_VOLUME
214
+ end
215
+
216
+ def legacy_config_volume_name
217
+ on_proxy_host? ? Dash::Configuration::Proxy::LEGACY_CONFIG_VOLUME : Dash::Configuration::Proxy::LEGACY_LOADBALANCER_CONFIG_VOLUME
204
218
  end
205
219
 
206
220
  # The certificate store lives in whichever config volume this loadbalancer
@@ -51,21 +51,18 @@ class Dash::Commands::Proxy < Dash::Commands::Base
51
51
  # boot sequence, and its ubuntu base has sh and cp. `--user root` because the
52
52
  # image's own user cannot write the destination volume; `cp -a` preserves the
53
53
  # uid, which the rename leaves at 1001.
54
- # The guard is negated and leads the chain, with `|| true` last, because
55
- # shell `&&` and `||` share precedence and associate left: written as
56
- # `exists || legacy_exists && create && copy` it would parse as
57
- # `((exists || legacy_exists) && create) && copy` and re-copy the legacy
58
- # volume over live state on every deploy. Leading with `! exists` makes the
59
- # whole chain a single left-associative AND, which short-circuits correctly.
54
+ #
55
+ # Shape: `exists || ! legacy_exists || ( create && copy )`. The chain has to
56
+ # start with a real program: SSHKit prefixes the first word with
57
+ # `/usr/bin/env`, and `env !` is "No such file or directory" (exit 127), not
58
+ # shell negation. 4.0.0 led with `! docker volume inspect …`, so the whole
59
+ # chain failed silently into `|| true`, the proxy booted onto a volume docker
60
+ # created empty, and every host lost its routing table and ACME cache on the
61
+ # first deploy. The subshell groups create-and-copy because `&&` and `||`
62
+ # share precedence and associate left — without it a host that already has
63
+ # the new volume would still run the copy over live state.
60
64
  def copy_legacy_config_volume(volume: Dash::Configuration::Proxy::CONFIG_VOLUME, legacy: Dash::Configuration::Proxy::LEGACY_CONFIG_VOLUME)
61
- any \
62
- combine(
63
- negate(volume_exists(volume)),
64
- volume_exists(legacy),
65
- docker(:volume, :create, volume),
66
- copy_between_volumes(legacy, volume)
67
- ),
68
- [ :true ]
65
+ copy_legacy_volume(legacy: legacy, volume: volume, image: proxy_image)
69
66
  end
70
67
 
71
68
  # Stops and removes a pre-rename proxy container so the renamed one can claim
@@ -326,27 +323,10 @@ class Dash::Commands::Proxy < Dash::Commands::Base
326
323
  [ "--label", "#{CONFIG_DIGEST_LABEL}=#{digest}" ] if digest
327
324
  end
328
325
 
329
- def negate(command)
330
- [ "!", *command ]
331
- end
332
-
333
- def volume_exists(name)
334
- docker :volume, :inspect, name, ">", "/dev/null", "2>&1"
335
- end
336
-
337
326
  def container_exists(name)
338
327
  docker :container, :inspect, name, ">", "/dev/null", "2>&1"
339
328
  end
340
329
 
341
- def copy_between_volumes(from, to)
342
- docker \
343
- :run, "--rm", "--user", "root", "--entrypoint", "sh",
344
- "--volume", "#{from}:/from",
345
- "--volume", "#{to}:/to",
346
- proxy_image,
347
- "-c", "'cp -a /from/. /to/'"
348
- end
349
-
350
330
  # The image the volume copy borrows. The proxy this gem is pinned to is
351
331
  # already pulled by the time the copy runs, and `rake release` gates on
352
332
  # MINIMUM_VERSION being published, so this is always resolvable — unlike
data/lib/dash/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dash
2
- VERSION = "4.0.1"
2
+ VERSION = "4.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dash
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson