Allow role to set env

This commit is contained in:
David Heinemeier Hansson
2023-01-20 13:26:27 +01:00
parent c4006ee373
commit 135fcdd9d3
3 changed files with 21 additions and 3 deletions

View File

@@ -9,7 +9,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
"--restart unless-stopped",
"--name", config.service_with_version,
*rails_master_key_arg,
*config.env_args,
*role.env_args,
*role.label_args,
config.absolute_image,
role.cmd

View File

@@ -23,6 +23,14 @@ class Mrsk::Configuration::Role
argumentize "--label", labels
end
def env
(config.env || {}).merge(specializations["env"] || {})
end
def env_args
argumentize "-e", env
end
def cmd
specializations["cmd"]
end

View File

@@ -7,7 +7,8 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
setup do
@deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
servers: [ "1.1.1.1", "1.1.1.2" ]
servers: [ "1.1.1.1", "1.1.1.2" ],
env: { "REDIS_URL" => "redis://x/y" }
}
@config = Mrsk::Configuration.new(@deploy)
@@ -17,7 +18,11 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
"web" => [ "1.1.1.1", "1.1.1.2" ],
"workers" => {
"hosts" => [ "1.1.1.3", "1.1.1.4" ],
"cmd" => "bin/jobs"
"cmd" => "bin/jobs",
"env" => {
"REDIS_URL" => "redis://a/b",
"WEB_CONCURRENCY" => 4
}
}
}
})
@@ -58,4 +63,9 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
@deploy[:labels] = { "traefik.http.routers.app.rule" => "'Host(`example.com`) || (Host(`example.org`) && Path(`/traefik`))'" }
assert_equal "'Host(`example.com`) || (Host(`example.org`) && Path(`/traefik`))'", @config.role(:web).labels["traefik.http.routers.app.rule"]
end
test "env overwritten by role" do
assert_equal "redis://a/b", @config_with_roles.role(:workers).env["REDIS_URL"]
assert_equal ["-e", "REDIS_URL=redis://a/b", "-e", "WEB_CONCURRENCY=4"], @config_with_roles.role(:workers).env_args
end
end