diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index dd7970cd..5b5878c3 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -234,7 +234,7 @@ class Kamal::Configuration end def env_tags - raw_config.env_tags.collect { |name, config| Kamal::Configuration::Env::Tag.new(name, config: config) } + raw_config.env["tags"].collect { |name, config| Kamal::Configuration::Env::Tag.new(name, config: config) } end def env_tag(name) diff --git a/lib/kamal/configuration/env.rb b/lib/kamal/configuration/env.rb index f9b8cd66..a7833849 100644 --- a/lib/kamal/configuration/env.rb +++ b/lib/kamal/configuration/env.rb @@ -4,7 +4,7 @@ class Kamal::Configuration::Env def self.from_config(config:, secrets_file: nil) secrets_keys = config.fetch("secret", []) - clear = config.fetch("clear", config.key?("secret") ? {} : config) + clear = config.fetch("clear", config.key?("secret") || config.key?("tags") ? {} : config) new clear: clear, secrets_keys: secrets_keys, secrets_file: secrets_file end diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index af7c6251..2f9dc57f 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -82,7 +82,7 @@ class CommandsAppTest < ActiveSupport::TestCase test "run with tags" do @config[:servers] = [ { "1.1.1.1" => "tag1" } ] - @config[:env_tags] = { "tag1" => { "ENV1" => "value1" } } + @config[:env]["tags"] = { "tag1" => { "ENV1" => "value1" } } assert_equal \ "docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --env ENV1=\"value1\" --health-cmd \"(curl -f http://localhost:3000/up || exit 1) && (stat /tmp/kamal-cord/cord > /dev/null || exit 1)\" --health-interval \"1s\" --volume $(pwd)/.kamal/cords/app-web-12345678901234567890123456789012:/tmp/kamal-cord --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label destination --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.app-web.priority=\"2\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", @@ -194,7 +194,7 @@ class CommandsAppTest < ActiveSupport::TestCase test "execute in new container with tags" do @config[:servers] = [ { "1.1.1.1" => "tag1" } ] - @config[:env_tags] = { "tag1" => { "ENV1" => "value1" } } + @config[:env]["tags"] = { "tag1" => { "ENV1" => "value1" } } assert_equal \ "docker run --rm --env-file .kamal/env/roles/app-web.env --env ENV1=\"value1\" dhh/app:999 bin/rails db:setup", @@ -227,7 +227,7 @@ class CommandsAppTest < ActiveSupport::TestCase test "execute in new container over ssh with tags" do @config[:servers] = [ { "1.1.1.1" => "tag1" } ] - @config[:env_tags] = { "tag1" => { "ENV1" => "value1" } } + @config[:env]["tags"] = { "tag1" => { "ENV1" => "value1" } } assert_equal "ssh -t root@1.1.1.1 -p 22 'docker run -it --rm --env-file .kamal/env/roles/app-web.env --env ENV1=\"value1\" dhh/app:999 bin/rails c'", new_command.execute_in_new_container_over_ssh("bin/rails", "c", env: {}) diff --git a/test/commands/healthcheck_test.rb b/test/commands/healthcheck_test.rb index 5c605175..829aa0b2 100644 --- a/test/commands/healthcheck_test.rb +++ b/test/commands/healthcheck_test.rb @@ -48,7 +48,8 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase test "run with tags" do @config[:servers] = [ { "1.1.1.1" => "tag1" } ] - @config[:env_tags] = { "tag1" => { "ENV1" => "value1" } } + @config[:env] = {} + @config[:env]["tags"] = { "tag1" => { "ENV1" => "value1" } } assert_equal \ "docker run --detach --name healthcheck-app-123 --publish 3999:3000 --label service=healthcheck-app -e KAMAL_CONTAINER_NAME=\"healthcheck-app\" --env-file .kamal/env/roles/app-web.env --env ENV1=\"value1\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" dhh/app:123", diff --git a/test/configuration/env/tags_test.rb b/test/configuration/env/tags_test.rb index 380cb5cd..c36b6057 100644 --- a/test/configuration/env/tags_test.rb +++ b/test/configuration/env/tags_test.rb @@ -5,11 +5,13 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase @deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ { "1.1.1.1" => "odd" }, { "1.1.1.2" => "even" }, { "1.1.1.3" => [ "odd", "three" ] } ], - env: { "REDIS_URL" => "redis://x/y", "THREE" => "false" }, - env_tags: { - "odd" => { "TYPE" => "odd" }, - "even" => { "TYPE" => "even" }, - "three" => { "THREE" => "true" } + env: { + "clear" => { "REDIS_URL" => "redis://x/y", "THREE" => "false" }, + "tags" => { + "odd" => { "TYPE" => "odd" }, + "even" => { "TYPE" => "even" }, + "three" => { "THREE" => "true" } + } } } @@ -27,9 +29,11 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase } } }, - env_tags: { - "odd" => { "TYPE" => "odd" }, - "oddjob" => { "TYPE" => "oddjob" } + env: { + "tags" => { + "odd" => { "TYPE" => "odd" }, + "oddjob" => { "TYPE" => "oddjob" } + } } }) @@ -60,9 +64,11 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ { "1.1.1.1" => [ "first", "second" ] } ], - env_tags: { - "first" => { "TYPE" => "first" }, - "second" => { "TYPE" => "second" } + env: { + "tags" => { + "first" => { "TYPE" => "first" }, + "second" => { "TYPE" => "second" } + } } } @@ -76,8 +82,10 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ { "1.1.1.1" => "secrets" } ], - env_tags: { - "secrets" => { "secret" => [ "PASSWORD" ] } + env: { + "tags" => { + "secrets" => { "secret" => [ "PASSWORD" ] } + } } } @@ -91,8 +99,10 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase deploy = { service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ { "1.1.1.1" => "clearly" } ], - env_tags: { - "clearly" => { "clear" => { "FOO" => "bar" } } + env: { + "tags" => { + "clearly" => { "clear" => { "FOO" => "bar" } } + } } } diff --git a/test/fixtures/deploy_with_env_tags.yml b/test/fixtures/deploy_with_env_tags.yml index 4acc839c..f0a24760 100644 --- a/test/fixtures/deploy_with_env_tags.yml +++ b/test/fixtures/deploy_with_env_tags.yml @@ -15,13 +15,12 @@ env: clear: TEST: "root" EXPERIMENT: "disabled" -env_tags: - site1: - SITE: site1 - site2: - SITE: site2 - experimental: - env: + tags: + site1: + SITE: site1 + site2: + SITE: site2 + experimental: EXPERIMENT: "enabled" registry: diff --git a/test/integration/docker/deployer/app/config/deploy.yml b/test/integration/docker/deployer/app/config/deploy.yml index aed676cc..38113737 100644 --- a/test/integration/docker/deployer/app/config/deploy.yml +++ b/test/integration/docker/deployer/app/config/deploy.yml @@ -10,12 +10,12 @@ env: HOST_TOKEN: "${HOST_TOKEN}" secret: - SECRET_TOKEN -env_tags: - tag1: - CLEAR_TAG: tagged - tag2: - secret: - - SECRET_TAG + tags: + tag1: + CLEAR_TAG: tagged + tag2: + secret: + - SECRET_TAG asset_path: /usr/share/nginx/html/versions registry: