Allow role to set env
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user