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