Add KAMAL_ROLES to hook env variables

And add an integration test to check the env vars are set.
This commit is contained in:
Donal McBreen
2025-04-21 09:45:23 +01:00
parent cd9d01b016
commit f768fab481
4 changed files with 18 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
#!/bin/sh
echo "About to lock..."
env
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-connect

View File

@@ -9,8 +9,12 @@ class MainTest < IntegrationTest
kamal :deploy
assert_app_is_up version: first_version
assert_hooks_ran "pre-connect", "pre-build", "pre-deploy", "pre-app-boot", "post-app-boot", "post-deploy"
assert_envs version: first_version
output = kamal :app, :exec, "--verbose", "ls", "-r", "web", capture: true
assert_hook_env_variables output, version: first_version
second_version = update_app_rev
kamal :redeploy
@@ -191,4 +195,15 @@ class MainTest < IntegrationTest
assert container_ids(vm: vm).any?
end
end
def assert_hook_env_variables(output, version:)
assert_match "KAMAL_VERSION=#{version}", output
assert_match "KAMAL_SERVICE=app", output
assert_match "KAMAL_SERVICE_VERSION=app@#{version[0..6]}", output
assert_match "KAMAL_COMMAND=app", output
assert_match "KAMAL_PERFORMER=deployer@example.com", output
assert_match /KAMAL_RECORDED_AT=\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ/, output
assert_match "KAMAL_HOSTS=vm1,vm2", output
assert_match "KAMAL_ROLES=web", output
end
end