Skip to content

Commit

Permalink
Use service if image is blank and registry is local
Browse files Browse the repository at this point in the history
  • Loading branch information
npezza93 committed Jan 25, 2025
1 parent 6f6e7e4 commit ace00d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/kamal/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require "net/ssh/proxy/jump"

class Kamal::Configuration
delegate :service, :image, :labels, :hooks_path, to: :raw_config, allow_nil: true
delegate :service, :labels, :hooks_path, to: :raw_config, allow_nil: true
delegate :argumentize, :optionize, to: Kamal::Utils

attr_reader :destination, :raw_config, :secrets
Expand Down Expand Up @@ -149,6 +149,13 @@ def proxy_hosts
proxy_roles.flat_map(&:hosts).uniq
end

def image
name = raw_config&.image.presence
name ||= raw_config&.service if registry.local?

name
end

def repository
[ registry.server, image ].compact.join("/")
end
Expand Down Expand Up @@ -306,10 +313,12 @@ def ensure_destination_if_required
end

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

raise Kamal::ConfigurationError, "Missing required configuration for image" if image.blank?

unless role(primary_role_name).present?
raise Kamal::ConfigurationError, "The primary_role #{primary_role_name} isn't defined"
end
Expand Down
13 changes: 13 additions & 0 deletions test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ class ConfigurationTest < ActiveSupport::TestCase
end
end

test "image uses service name if registry is local" do
assert_equal "app", Kamal::Configuration.new(@deploy.tap {
_1[:registry] = { "server" => "localhost:5000" }
_1.delete(:image)
}).image
end

test "image uses image if registry is local" do
assert_equal "dhh/app", Kamal::Configuration.new(@deploy.tap {
_1[:registry] = { "server" => "localhost:5000" }
}).image
end

test "service name valid" do
assert_nothing_raised do
Kamal::Configuration.new(@deploy.tap { _1[:service] = "hey-app1_primary" })
Expand Down

0 comments on commit ace00d7

Please sign in to comment.