Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a require_destination setting #451

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/kamal/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class Kamal::Configuration
delegate :service, :image, :servers, :env, :labels, :registry, :stop_wait_time, :hooks_path, to: :raw_config, allow_nil: true
delegate :argumentize, :optionize, to: Kamal::Utils

attr_accessor :destination
attr_accessor :raw_config
attr_reader :destination, :raw_config

class << self
def create_from(config_file:, destination: nil, version: nil)
Expand Down Expand Up @@ -120,6 +119,10 @@ def service_with_version
"#{service}-#{version}"
end

def require_destination?
raw_config.require_destination
end


def volume_args
if raw_config.volumes.present?
Expand Down Expand Up @@ -161,7 +164,7 @@ def minimum_version
end

def valid?
ensure_required_keys_present && ensure_valid_kamal_version
ensure_destination_if_required && ensure_required_keys_present && ensure_valid_kamal_version
end


Expand Down Expand Up @@ -243,6 +246,14 @@ def ensure_valid_kamal_version
true
end

def ensure_destination_if_required
if require_destination? && destination.nil?
raise ArgumentError, "You must specify a destination"
end

true
end


def role_names
raw_config.servers.is_a?(Array) ? [ "web" ] : raw_config.servers.keys.sort
Expand Down
12 changes: 12 additions & 0 deletions test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ class ConfigurationTest < ActiveSupport::TestCase
end
end

test "destination required" do
dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_required_dest.yml", __dir__))

assert_raises(ArgumentError) do
config = Kamal::Configuration.create_from config_file: dest_config_file
end

assert_nothing_raised do
config = Kamal::Configuration.create_from config_file: dest_config_file, destination: "world"
end
end

test "to_h" do
expected_config = \
{ :roles=>["web"],
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/deploy_for_required_dest.world.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
servers:
- 1.1.1.1
- 1.1.1.2
env:
REDIS_URL: redis://x/y
7 changes: 7 additions & 0 deletions test/fixtures/deploy_for_required_dest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
service: app
image: dhh/app
registry:
server: registry.digitalocean.com
username: <%= "my-user" %>
password: <%= "my-password" %>
require_destination: true
Loading