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", "--restart unless-stopped",
"--name", config.service_with_version, "--name", config.service_with_version,
*rails_master_key_arg, *rails_master_key_arg,
*config.env_args, *role.env_args,
*role.label_args, *role.label_args,
config.absolute_image, config.absolute_image,
role.cmd role.cmd

View File

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

View File

@@ -7,7 +7,8 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
setup do setup do
@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", "1.1.1.2" ] servers: [ "1.1.1.1", "1.1.1.2" ],
env: { "REDIS_URL" => "redis://x/y" }
} }
@config = Mrsk::Configuration.new(@deploy) @config = Mrsk::Configuration.new(@deploy)
@@ -17,7 +18,11 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
"web" => [ "1.1.1.1", "1.1.1.2" ], "web" => [ "1.1.1.1", "1.1.1.2" ],
"workers" => { "workers" => {
"hosts" => [ "1.1.1.3", "1.1.1.4" ], "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`))'" } @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"] assert_equal "'Host(`example.com`) || (Host(`example.org`) && Path(`/traefik`))'", @config.role(:web).labels["traefik.http.routers.app.rule"]
end 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 end