From f6662c7a8fcad3c70fe774872e73915d3be8c1f8 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Mon, 25 Sep 2023 15:23:01 +0100 Subject: [PATCH] Remove the env check The env check is not needded anymore as all the commands rely on the env files having already been created remotely. The only place the env is needed is when running `kamal env push` and that will still raise an apropriate error. --- lib/kamal/cli/base.rb | 2 -- lib/kamal/configuration.rb | 7 ------- test/cli/main_test.rb | 14 +++++++++++--- test/configuration_test.rb | 8 -------- test/integration/main_test.rb | 5 +++++ 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/kamal/cli/base.rb b/lib/kamal/cli/base.rb index 8bbdf198..10925e79 100644 --- a/lib/kamal/cli/base.rb +++ b/lib/kamal/cli/base.rb @@ -75,8 +75,6 @@ module Kamal::Cli def mutating return yield if KAMAL.holding_lock? - KAMAL.config.ensure_env_available - run_hook "pre-connect" ensure_run_directory diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index 31b1b754..fc881c06 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -204,13 +204,6 @@ class Kamal::Configuration ensure_destination_if_required && ensure_required_keys_present && ensure_valid_kamal_version end - # Will raise KeyError if any secret ENVs are missing - def ensure_env_available - roles.collect(&:env_file).each(&:to_s) - - true - end - def to_h { roles: role_names, diff --git a/test/cli/main_test.rb b/test/cli/main_test.rb index fe174653..ffc9d097 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -124,9 +124,17 @@ class CliMainTest < CliTestCase end test "deploy with missing secrets" do - assert_raises(KeyError) do - run_command("deploy", config_file: "deploy_with_secrets") - end + invoke_options = { "config_file" => "test/fixtures/deploy_with_secrets.yml", "version" => "999", "skip_hooks" => false } + + Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options) + Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options) + Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:boot", [], invoke_options) + Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options) + Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options.merge(stop: true)) + Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options) + Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options) + + run_command("deploy", config_file: "deploy_with_secrets") end test "redeploy" do diff --git a/test/configuration_test.rb b/test/configuration_test.rb index eeb92938..5b9f4cc9 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -128,14 +128,6 @@ class ConfigurationTest < ActiveSupport::TestCase assert_equal "healthcheck-app", @config.healthcheck_service end - test "env with missing secret" do - assert_raises(KeyError) do - config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!({ - env: { "secret" => [ "PASSWORD" ] } - }) }).ensure_env_available - end - end - test "valid config" do assert @config.valid? assert @config_with_roles.valid? diff --git a/test/integration/main_test.rb b/test/integration/main_test.rb index df595a0a..1171c3de 100644 --- a/test/integration/main_test.rb +++ b/test/integration/main_test.rb @@ -5,6 +5,7 @@ class MainTest < IntegrationTest kamal :envify assert_local_env_file "SECRET_TOKEN=1234" assert_remote_env_file "SECRET_TOKEN=1234\nCLEAR_TOKEN=4321" + remove_local_env_file first_version = latest_app_version @@ -64,6 +65,10 @@ class MainTest < IntegrationTest assert_equal contents, deployer_exec("cat .env", capture: true) end + def remove_local_env_file + deployer_exec("rm .env") + end + def assert_remote_env_file(contents) assert_equal contents, docker_compose("exec vm1 cat /root/.kamal/env/roles/app-web.env", capture: true) end