kamal 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8429a6060103f16d9aadb517e77fbb32fc6c6d2e6b9b3cf2989c8a9309e0067
4
- data.tar.gz: e997f3c5765639c4b14aad08a81344c5af182904e3d80f4867792ed55a9fc25b
3
+ metadata.gz: adf6f739fb85822d7a74b5eac6bdfc373bc842a92acb9dcf9fd5f7e076fe8524
4
+ data.tar.gz: b2c30a95ee553009a7719760b2f2cb1f8e810bce61800819bf9b66aee3304b3e
5
5
  SHA512:
6
- metadata.gz: 575353b6ea9e9d429a6c6e6b89013fd36f0b371b4edbffbf3ab33f707a9637191872d7463fb670dbe45f9a36bc7a1792335fa9c0709e31d2339b1549c4da32ff
7
- data.tar.gz: 6a71437092b0ce21cce12a6d127098e2aba2a0b18846026b6df1c9bb1d33f60d27da3ac1c3b553490a2f4daa76a7ae2e725b4f2ee7918d4cc808bc29b556e8f3
6
+ metadata.gz: b376df173efb5f00c4624b5da611caf0607f294a868b54eb318ff653755934750c19a74139ab978fa9842759812edb69c8d5384e79bd93989e58d121d2cc4ac9
7
+ data.tar.gz: 289e20a34e4cdbd3b274dd20c8224c4b6ddabe179495a6812b5b2b6a879f612c5f198111925cd3d438c4aaca73de24b32430b8e1ac8fc16b038797d07859b24f
@@ -0,0 +1,127 @@
1
+ class Kamal::Commands::App < Kamal::Commands::Base
2
+ include Assets, Containers, Cord, Execution, Images, Logging
3
+
4
+ ACTIVE_DOCKER_STATUSES = [ :running, :restarting ]
5
+
6
+ attr_reader :role
7
+
8
+ def initialize(config, role: nil)
9
+ super(config)
10
+ @role = role
11
+ end
12
+
13
+ def run(hostname: nil)
14
+ docker :run,
15
+ "--detach",
16
+ "--restart unless-stopped",
17
+ "--name", container_name,
18
+ *([ "--hostname", hostname ] if hostname),
19
+ "-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"",
20
+ "-e", "KAMAL_VERSION=\"#{config.version}\"",
21
+ *role.env_args,
22
+ *role.health_check_args,
23
+ *role.logging_args,
24
+ *config.volume_args,
25
+ *role.asset_volume_args,
26
+ *role.label_args,
27
+ *role.option_args,
28
+ config.absolute_image,
29
+ role.cmd
30
+ end
31
+
32
+ def start
33
+ docker :start, container_name
34
+ end
35
+
36
+ def status(version:)
37
+ pipe container_id_for_version(version), xargs(docker(:inspect, "--format", DOCKER_HEALTH_STATUS_FORMAT))
38
+ end
39
+
40
+ def stop(version: nil)
41
+ pipe \
42
+ version ? container_id_for_version(version) : current_running_container_id,
43
+ xargs(config.stop_wait_time ? docker(:stop, "-t", config.stop_wait_time) : docker(:stop))
44
+ end
45
+
46
+ def info
47
+ docker :ps, *filter_args
48
+ end
49
+
50
+
51
+ def current_running_container_id
52
+ current_running_container(format: "--quiet")
53
+ end
54
+
55
+ def container_id_for_version(version, only_running: false)
56
+ container_id_for(container_name: container_name(version), only_running: only_running)
57
+ end
58
+
59
+ <<<<<<< HEAD
60
+ def current_running_version
61
+ pipe \
62
+ current_running_container(format: "--format '{{.Names}}'"),
63
+ extract_version_from_name
64
+ =======
65
+ def current_running_version(prefix: nil)
66
+ list_versions("--latest", statuses: ACTIVE_DOCKER_STATUSES)
67
+ >>>>>>> 4dc8aca (Rename roles)
68
+ end
69
+
70
+ def list_versions(*docker_args, statuses: nil)
71
+ pipe \
72
+ docker(:ps, *filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'),
73
+ extract_version_from_name
74
+ end
75
+
76
+
77
+ def make_env_directory
78
+ make_directory role.env.secrets_directory
79
+ end
80
+
81
+ def remove_env_file
82
+ [ :rm, "-f", role.env.secrets_file ]
83
+ end
84
+
85
+
86
+ private
87
+ def container_name(version = nil)
88
+ [ role.container_prefix, version || config.version ].compact.join("-")
89
+ end
90
+
91
+ def latest_image_id
92
+ docker :image, :ls, *argumentize("--filter", "reference=#{config.latest_image}"), "--format", "'{{.ID}}'"
93
+ end
94
+
95
+ def current_running_container(format:)
96
+ pipe \
97
+ shell(chain(latest_image_container(format: format), latest_container(format: format))),
98
+ [ :head, "-1" ]
99
+ end
100
+
101
+ def latest_image_container(format:)
102
+ latest_container format: format, filters: [ "ancestor=$(#{latest_image_id.join(" ")})" ]
103
+ end
104
+
105
+ def latest_container(format:, filters: nil)
106
+ docker :ps, "--latest", *format, *filter_args(statuses: ACTIVE_DOCKER_STATUSES), argumentize("--filter", filters)
107
+ end
108
+
109
+ def filter_args(statuses: nil)
110
+ argumentize "--filter", filters(statuses: statuses)
111
+ end
112
+
113
+ def extract_version_from_name
114
+ # Extract SHA from "service-role-dest-SHA"
115
+ %(while read line; do echo ${line##{role.container_prefix}-}; done)
116
+ end
117
+
118
+ def filters(statuses: nil)
119
+ [ "label=service=#{config.service}" ].tap do |filters|
120
+ filters << "label=destination=#{config.destination}" if config.destination
121
+ filters << "label=role=#{role}" if role
122
+ statuses&.each do |status|
123
+ filters << "status=#{status}"
124
+ end
125
+ end
126
+ end
127
+ end
@@ -18,7 +18,7 @@ module Kamal::Commands
18
18
  elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command)
19
19
  cmd << " -o ProxyCommand='#{config.ssh.proxy.command_line_template}'"
20
20
  end
21
- cmd << " -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ")}'"
21
+ cmd << " -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'"
22
22
  end
23
23
  end
24
24
 
data/lib/kamal/utils.rb CHANGED
@@ -66,13 +66,12 @@ 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('\*', ".*")
70
69
  # items are roles or hosts
71
- (item.respond_to?(:name) ? item.name : item).match(/^#{pattern}$/)
70
+ File.fnmatch(filter, item.to_s, File::FNM_EXTGLOB)
72
71
  end
73
72
  end
74
73
 
75
- matches
74
+ matches.uniq
76
75
  end
77
76
 
78
77
  def stable_sort!(elements, &block)
data/lib/kamal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kamal
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  end
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.5.0
4
+ version: 1.5.1
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-04-25 00:00:00.000000000 Z
11
+ date: 2024-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -233,6 +233,7 @@ files:
233
233
  - lib/kamal/commands.rb
234
234
  - lib/kamal/commands/accessory.rb
235
235
  - lib/kamal/commands/app.rb
236
+ - lib/kamal/commands/app.rb.orig
236
237
  - lib/kamal/commands/app/assets.rb
237
238
  - lib/kamal/commands/app/containers.rb
238
239
  - lib/kamal/commands/app/cord.rb