kamal 1.4.0 → 1.5.0

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kamal/cli/accessory.rb +3 -2
  3. data/lib/kamal/cli/app/boot.rb +67 -0
  4. data/lib/kamal/cli/app/prepare_assets.rb +24 -0
  5. data/lib/kamal/cli/app.rb +20 -61
  6. data/lib/kamal/cli/base.rb +21 -7
  7. data/lib/kamal/cli/env.rb +3 -3
  8. data/lib/kamal/cli/main.rb +1 -1
  9. data/lib/kamal/cli/templates/deploy.yml +1 -1
  10. data/lib/kamal/cli/templates/sample_hooks/docker-setup.sample +0 -0
  11. data/lib/kamal/cli/traefik.rb +15 -12
  12. data/lib/kamal/commander/specifics.rb +49 -0
  13. data/lib/kamal/commander.rb +9 -33
  14. data/lib/kamal/commands/accessory.rb +2 -2
  15. data/lib/kamal/commands/app/assets.rb +4 -4
  16. data/lib/kamal/commands/app/cord.rb +2 -2
  17. data/lib/kamal/commands/app/execution.rb +8 -6
  18. data/lib/kamal/commands/app/images.rb +1 -1
  19. data/lib/kamal/commands/app.rb +29 -8
  20. data/lib/kamal/commands/auditor.rb +1 -1
  21. data/lib/kamal/commands/base.rb +5 -1
  22. data/lib/kamal/commands/builder/base.rb +14 -4
  23. data/lib/kamal/commands/builder/multiarch.rb +9 -9
  24. data/lib/kamal/commands/builder/native/cached.rb +7 -6
  25. data/lib/kamal/commands/builder/native/remote.rb +9 -9
  26. data/lib/kamal/commands/builder/native.rb +8 -7
  27. data/lib/kamal/commands/healthcheck.rb +0 -1
  28. data/lib/kamal/commands/hook.rb +1 -1
  29. data/lib/kamal/commands/lock.rb +19 -9
  30. data/lib/kamal/commands/prune.rb +2 -2
  31. data/lib/kamal/commands/server.rb +1 -1
  32. data/lib/kamal/commands/traefik.rb +8 -14
  33. data/lib/kamal/configuration/accessory.rb +9 -19
  34. data/lib/kamal/configuration/boot.rb +1 -1
  35. data/lib/kamal/configuration/builder.rb +7 -3
  36. data/lib/kamal/configuration/env.rb +40 -0
  37. data/lib/kamal/configuration/role.rb +12 -42
  38. data/lib/kamal/configuration.rb +20 -8
  39. data/lib/kamal/env_file.rb +12 -15
  40. data/lib/kamal/utils.rb +7 -3
  41. data/lib/kamal/version.rb +1 -1
  42. data/lib/kamal.rb +1 -1
  43. metadata +6 -2
@@ -6,7 +6,7 @@ require "erb"
6
6
  require "net/ssh/proxy/jump"
7
7
 
8
8
  class Kamal::Configuration
9
- delegate :service, :image, :servers, :env, :labels, :registry, :stop_wait_time, :hooks_path, :logging, to: :raw_config, allow_nil: true
9
+ delegate :service, :image, :servers, :labels, :registry, :stop_wait_time, :hooks_path, :logging, to: :raw_config, allow_nil: true
10
10
  delegate :argumentize, :optionize, to: Kamal::Utils
11
11
 
12
12
  attr_reader :destination, :raw_config
@@ -88,7 +88,7 @@ class Kamal::Configuration
88
88
 
89
89
 
90
90
  def all_hosts
91
- roles.flat_map(&:hosts).uniq
91
+ (roles + accessories).flat_map(&:hosts).uniq
92
92
  end
93
93
 
94
94
  def primary_host
@@ -128,7 +128,11 @@ class Kamal::Configuration
128
128
  end
129
129
 
130
130
  def latest_image
131
- "#{repository}:latest"
131
+ "#{repository}:#{latest_tag}"
132
+ end
133
+
134
+ def latest_tag
135
+ [ "latest", *destination ].join("-")
132
136
  end
133
137
 
134
138
  def service_with_version
@@ -216,12 +220,17 @@ class Kamal::Configuration
216
220
  raw_config.hooks_path || ".kamal/hooks"
217
221
  end
218
222
 
223
+ def asset_path
224
+ raw_config.asset_path
225
+ end
226
+
227
+
219
228
  def host_env_directory
220
- "#{run_directory}/env"
229
+ File.join(run_directory, "env")
221
230
  end
222
231
 
223
- def asset_path
224
- raw_config.asset_path
232
+ def env
233
+ raw_config.env || {}
225
234
  end
226
235
 
227
236
 
@@ -292,7 +301,7 @@ class Kamal::Configuration
292
301
  end
293
302
 
294
303
  def ensure_valid_service_name
295
- raise ArgumentError, "Service name can only include alphanumeric characters, hyphens, and underscores" unless raw_config[:service] =~ /^[a-z0-9_-]+$/
304
+ raise ArgumentError, "Service name can only include alphanumeric characters, hyphens, and underscores" unless raw_config[:service] =~ /^[a-z0-9_-]+$/i
296
305
 
297
306
  true
298
307
  end
@@ -319,7 +328,10 @@ class Kamal::Configuration
319
328
  def git_version
320
329
  @git_version ||=
321
330
  if Kamal::Git.used?
322
- [ Kamal::Git.revision, Kamal::Git.uncommitted_changes.present? ? "_uncommitted_#{SecureRandom.hex(8)}" : "" ].join
331
+ if Kamal::Git.uncommitted_changes.present? && !builder.git_archive?
332
+ uncommitted_suffix = "_uncommitted_#{SecureRandom.hex(8)}"
333
+ end
334
+ [ Kamal::Git.revision, uncommitted_suffix ].compact.join
323
335
  else
324
336
  raise "Can't use commit hash as version, no git repository found in #{Dir.pwd}"
325
337
  end
@@ -3,21 +3,11 @@ class Kamal::EnvFile
3
3
  def initialize(env)
4
4
  @env = env
5
5
  end
6
-
6
+
7
7
  def to_s
8
8
  env_file = StringIO.new.tap do |contents|
9
- if (secrets = @env["secret"]).present?
10
- @env.fetch("secret", @env)&.each do |key|
11
- contents << docker_env_file_line(key, ENV.fetch(key))
12
- end
13
-
14
- @env["clear"]&.each do |key, value|
15
- contents << docker_env_file_line(key, value)
16
- end
17
- else
18
- @env.fetch("clear", @env)&.each do |key, value|
19
- contents << docker_env_file_line(key, value)
20
- end
9
+ @env.each do |key, value|
10
+ contents << docker_env_file_line(key, value)
21
11
  end
22
12
  end.string
23
13
 
@@ -26,14 +16,21 @@ class Kamal::EnvFile
26
16
  end
27
17
 
28
18
  alias to_str to_s
29
-
19
+
30
20
  private
31
21
  def docker_env_file_line(key, value)
32
- "#{key.to_s}=#{escape_docker_env_file_value(value)}\n"
22
+ "#{key}=#{escape_docker_env_file_value(value)}\n"
33
23
  end
34
24
 
35
25
  # Escape a value to make it safe to dump in a docker file.
36
26
  def escape_docker_env_file_value(value)
27
+ # keep non-ascii(UTF-8) characters as it is
28
+ value.to_s.scan(/[\x00-\x7F]+|[^\x00-\x7F]+/).map do |part|
29
+ part.ascii_only? ? escape_docker_env_file_ascii_value(part) : part
30
+ end.join
31
+ end
32
+
33
+ def escape_docker_env_file_ascii_value(value)
37
34
  # Doublequotes are treated literally in docker env files
38
35
  # so remove leading and trailing ones and unescape any others
39
36
  value.to_s.dump[1..-2].gsub(/\\"/, "\"")
data/lib/kamal/utils.rb CHANGED
@@ -9,7 +9,7 @@ module Kamal::Utils
9
9
  if value.present?
10
10
  attr = "#{key}=#{escape_shell_value(value)}"
11
11
  attr = self.sensitive(attr, redaction: "#{key}=[REDACTED]") if sensitive
12
- [ argument, attr]
12
+ [ argument, attr ]
13
13
  else
14
14
  [ argument, key ]
15
15
  end
@@ -29,7 +29,7 @@ module Kamal::Utils
29
29
 
30
30
  # Flattens a one-to-many structure into an array of two-element arrays each containing a key-value pair
31
31
  def flatten_args(args)
32
- args.flat_map { |key, value| value.try(:map) { |entry| [key, entry] } || [ [ key, value ] ] }
32
+ args.flat_map { |key, value| value.try(:map) { |entry| [ key, entry ] } || [ [ key, value ] ] }
33
33
  end
34
34
 
35
35
  # Marks sensitive values for redaction in logs and human-visible output.
@@ -66,7 +66,7 @@ module Kamal::Utils
66
66
  Array(filters).select do |filter|
67
67
  matches += Array(items).select do |item|
68
68
  # Only allow * for a wildcard
69
- pattern = Regexp.escape(filter).gsub('\*', '.*')
69
+ pattern = Regexp.escape(filter).gsub('\*', ".*")
70
70
  # items are roles or hosts
71
71
  (item.respond_to?(:name) ? item.name : item).match(/^#{pattern}$/)
72
72
  end
@@ -74,4 +74,8 @@ module Kamal::Utils
74
74
 
75
75
  matches
76
76
  end
77
+
78
+ def stable_sort!(elements, &block)
79
+ elements.sort_by!.with_index { |element, index| [ block.call(element), index ] }
80
+ end
77
81
  end
data/lib/kamal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kamal
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
data/lib/kamal.rb CHANGED
@@ -5,6 +5,6 @@ require "active_support"
5
5
  require "zeitwerk"
6
6
 
7
7
  loader = Zeitwerk::Loader.for_gem
8
- loader.ignore("#{__dir__}/kamal/sshkit_with_ext.rb")
8
+ loader.ignore(File.join(__dir__, "kamal", "sshkit_with_ext.rb"))
9
9
  loader.setup
10
10
  loader.eager_load # We need all commands loaded.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-20 00:00:00.000000000 Z
11
+ date: 2024-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -206,6 +206,8 @@ files:
206
206
  - lib/kamal/cli.rb
207
207
  - lib/kamal/cli/accessory.rb
208
208
  - lib/kamal/cli/app.rb
209
+ - lib/kamal/cli/app/boot.rb
210
+ - lib/kamal/cli/app/prepare_assets.rb
209
211
  - lib/kamal/cli/base.rb
210
212
  - lib/kamal/cli/build.rb
211
213
  - lib/kamal/cli/env.rb
@@ -227,6 +229,7 @@ files:
227
229
  - lib/kamal/cli/templates/template.env
228
230
  - lib/kamal/cli/traefik.rb
229
231
  - lib/kamal/commander.rb
232
+ - lib/kamal/commander/specifics.rb
230
233
  - lib/kamal/commands.rb
231
234
  - lib/kamal/commands/accessory.rb
232
235
  - lib/kamal/commands/app.rb
@@ -257,6 +260,7 @@ files:
257
260
  - lib/kamal/configuration/accessory.rb
258
261
  - lib/kamal/configuration/boot.rb
259
262
  - lib/kamal/configuration/builder.rb
263
+ - lib/kamal/configuration/env.rb
260
264
  - lib/kamal/configuration/role.rb
261
265
  - lib/kamal/configuration/ssh.rb
262
266
  - lib/kamal/configuration/sshkit.rb