Skip to content

Commit ace00d7

Browse files
committed
Use service if image is blank and registry is local
1 parent 6f6e7e4 commit ace00d7

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/kamal/configuration.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
require "net/ssh/proxy/jump"
77

88
class Kamal::Configuration
9-
delegate :service, :image, :labels, :hooks_path, to: :raw_config, allow_nil: true
9+
delegate :service, :labels, :hooks_path, to: :raw_config, allow_nil: true
1010
delegate :argumentize, :optionize, to: Kamal::Utils
1111

1212
attr_reader :destination, :raw_config, :secrets
@@ -149,6 +149,13 @@ def proxy_hosts
149149
proxy_roles.flat_map(&:hosts).uniq
150150
end
151151

152+
def image
153+
name = raw_config&.image.presence
154+
name ||= raw_config&.service if registry.local?
155+
156+
name
157+
end
158+
152159
def repository
153160
[ registry.server, image ].compact.join("/")
154161
end
@@ -306,10 +313,12 @@ def ensure_destination_if_required
306313
end
307314

308315
def ensure_required_keys_present
309-
%i[ service image registry servers ].each do |key|
316+
%i[ service registry servers ].each do |key|
310317
raise Kamal::ConfigurationError, "Missing required configuration for #{key}" unless raw_config[key].present?
311318
end
312319

320+
raise Kamal::ConfigurationError, "Missing required configuration for image" if image.blank?
321+
313322
unless role(primary_role_name).present?
314323
raise Kamal::ConfigurationError, "The primary_role #{primary_role_name} isn't defined"
315324
end

test/configuration_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ class ConfigurationTest < ActiveSupport::TestCase
4343
end
4444
end
4545

46+
test "image uses service name if registry is local" do
47+
assert_equal "app", Kamal::Configuration.new(@deploy.tap {
48+
_1[:registry] = { "server" => "localhost:5000" }
49+
_1.delete(:image)
50+
}).image
51+
end
52+
53+
test "image uses image if registry is local" do
54+
assert_equal "dhh/app", Kamal::Configuration.new(@deploy.tap {
55+
_1[:registry] = { "server" => "localhost:5000" }
56+
}).image
57+
end
58+
4659
test "service name valid" do
4760
assert_nothing_raised do
4861
Kamal::Configuration.new(@deploy.tap { _1[:service] = "hey-app1_primary" })

0 commit comments

Comments
 (0)