Move env_tags under env key

Instead of:

```
env:
  CLEAR_TAG: untagged
env_tags:
  tag1:
    CLEAR_TAG: tagged
```

We'll have:

```
env:
  clear:
    CLEAR_TAG: untagged
  tags:
    tag1:
      CLEAR_TAG: tagged
```
This commit is contained in:
Donal McBreen
2024-05-15 10:19:22 +01:00
parent f98380ef0c
commit f48c227768
7 changed files with 44 additions and 34 deletions

View File

@@ -234,7 +234,7 @@ class Kamal::Configuration
end end
def env_tags 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 end
def env_tag(name) def env_tag(name)

View File

@@ -4,7 +4,7 @@ class Kamal::Configuration::Env
def self.from_config(config:, secrets_file: nil) def self.from_config(config:, secrets_file: nil)
secrets_keys = config.fetch("secret", []) 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 new clear: clear, secrets_keys: secrets_keys, secrets_file: secrets_file
end end

View File

@@ -82,7 +82,7 @@ class CommandsAppTest < ActiveSupport::TestCase
test "run with tags" do test "run with tags" do
@config[:servers] = [ { "1.1.1.1" => "tag1" } ] @config[:servers] = [ { "1.1.1.1" => "tag1" } ]
@config[:env_tags] = { "tag1" => { "ENV1" => "value1" } } @config[:env]["tags"] = { "tag1" => { "ENV1" => "value1" } }
assert_equal \ 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", "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 test "execute in new container with tags" do
@config[:servers] = [ { "1.1.1.1" => "tag1" } ] @config[:servers] = [ { "1.1.1.1" => "tag1" } ]
@config[:env_tags] = { "tag1" => { "ENV1" => "value1" } } @config[:env]["tags"] = { "tag1" => { "ENV1" => "value1" } }
assert_equal \ assert_equal \
"docker run --rm --env-file .kamal/env/roles/app-web.env --env ENV1=\"value1\" dhh/app:999 bin/rails db:setup", "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 test "execute in new container over ssh with tags" do
@config[:servers] = [ { "1.1.1.1" => "tag1" } ] @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'", 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: {}) new_command.execute_in_new_container_over_ssh("bin/rails", "c", env: {})

View File

@@ -48,7 +48,8 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase
test "run with tags" do test "run with tags" do
@config[:servers] = [ { "1.1.1.1" => "tag1" } ] @config[:servers] = [ { "1.1.1.1" => "tag1" } ]
@config[:env_tags] = { "tag1" => { "ENV1" => "value1" } } @config[:env] = {}
@config[:env]["tags"] = { "tag1" => { "ENV1" => "value1" } }
assert_equal \ 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", "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",

View File

@@ -5,11 +5,13 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
@deploy = { @deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, 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" ] } ], 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: {
env_tags: { "clear" => { "REDIS_URL" => "redis://x/y", "THREE" => "false" },
"odd" => { "TYPE" => "odd" }, "tags" => {
"even" => { "TYPE" => "even" }, "odd" => { "TYPE" => "odd" },
"three" => { "THREE" => "true" } "even" => { "TYPE" => "even" },
"three" => { "THREE" => "true" }
}
} }
} }
@@ -27,9 +29,11 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
} }
} }
}, },
env_tags: { env: {
"odd" => { "TYPE" => "odd" }, "tags" => {
"oddjob" => { "TYPE" => "oddjob" } "odd" => { "TYPE" => "odd" },
"oddjob" => { "TYPE" => "oddjob" }
}
} }
}) })
@@ -60,9 +64,11 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
deploy = { deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ { "1.1.1.1" => [ "first", "second" ] } ], servers: [ { "1.1.1.1" => [ "first", "second" ] } ],
env_tags: { env: {
"first" => { "TYPE" => "first" }, "tags" => {
"second" => { "TYPE" => "second" } "first" => { "TYPE" => "first" },
"second" => { "TYPE" => "second" }
}
} }
} }
@@ -76,8 +82,10 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
deploy = { deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ { "1.1.1.1" => "secrets" } ], servers: [ { "1.1.1.1" => "secrets" } ],
env_tags: { env: {
"secrets" => { "secret" => [ "PASSWORD" ] } "tags" => {
"secrets" => { "secret" => [ "PASSWORD" ] }
}
} }
} }
@@ -91,8 +99,10 @@ class ConfigurationEnvTagsTest < ActiveSupport::TestCase
deploy = { deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ { "1.1.1.1" => "clearly" } ], servers: [ { "1.1.1.1" => "clearly" } ],
env_tags: { env: {
"clearly" => { "clear" => { "FOO" => "bar" } } "tags" => {
"clearly" => { "clear" => { "FOO" => "bar" } }
}
} }
} }

View File

@@ -15,13 +15,12 @@ env:
clear: clear:
TEST: "root" TEST: "root"
EXPERIMENT: "disabled" EXPERIMENT: "disabled"
env_tags: tags:
site1: site1:
SITE: site1 SITE: site1
site2: site2:
SITE: site2 SITE: site2
experimental: experimental:
env:
EXPERIMENT: "enabled" EXPERIMENT: "enabled"
registry: registry:

View File

@@ -10,12 +10,12 @@ env:
HOST_TOKEN: "${HOST_TOKEN}" HOST_TOKEN: "${HOST_TOKEN}"
secret: secret:
- SECRET_TOKEN - SECRET_TOKEN
env_tags: tags:
tag1: tag1:
CLEAR_TAG: tagged CLEAR_TAG: tagged
tag2: tag2:
secret: secret:
- SECRET_TAG - SECRET_TAG
asset_path: /usr/share/nginx/html/versions asset_path: /usr/share/nginx/html/versions
registry: registry: