Allow custom options per role
This commit is contained in:
@@ -10,9 +10,9 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
*role.env_args,
|
*role.env_args,
|
||||||
*config.volume_args,
|
*config.volume_args,
|
||||||
*role.label_args,
|
*role.label_args,
|
||||||
|
*role.option_args,
|
||||||
config.absolute_image,
|
config.absolute_image,
|
||||||
role.cmd,
|
role.cmd
|
||||||
*role.cmd_args
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Mrsk::Commands::Traefik < Mrsk::Commands::Base
|
class Mrsk::Commands::Traefik < Mrsk::Commands::Base
|
||||||
delegate :argumentize_for_cmd, to: Mrsk::Utils
|
delegate :optionize, to: Mrsk::Utils
|
||||||
|
|
||||||
CONTAINER_PORT = 80
|
CONTAINER_PORT = 80
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
|
|||||||
"traefik",
|
"traefik",
|
||||||
"--providers.docker",
|
"--providers.docker",
|
||||||
"--log.level=DEBUG",
|
"--log.level=DEBUG",
|
||||||
*cmd_args
|
*cmd_option_args
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
@@ -54,9 +54,9 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def cmd_args
|
def cmd_option_args
|
||||||
if args = config.raw_config.dig(:traefik, "args")
|
if args = config.raw_config.dig(:traefik, "args")
|
||||||
argumentize_for_cmd args
|
optionize args
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Mrsk::Configuration::Role
|
class Mrsk::Configuration::Role
|
||||||
delegate :argumentize, :argumentize_env_with_secrets, :argumentize_for_cmd, to: Mrsk::Utils
|
delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Mrsk::Utils
|
||||||
|
|
||||||
attr_accessor :name
|
attr_accessor :name
|
||||||
|
|
||||||
@@ -35,9 +35,9 @@ class Mrsk::Configuration::Role
|
|||||||
specializations["cmd"]
|
specializations["cmd"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def cmd_args
|
def option_args
|
||||||
if args = specializations["args"]
|
if args = specializations["options"]
|
||||||
argumentize_for_cmd args
|
optionize args
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ module Mrsk::Utils
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a list of shell-dashed arguments to be used to start a command.
|
# Returns a list of shell-dashed option arguments.
|
||||||
def argumentize_for_cmd(args)
|
def optionize(args)
|
||||||
args.collect { |(key, value)| [ "--#{key}", escape_shell_value(value) ] }.flatten
|
args.collect { |(key, value)| [ "--#{key}", escape_shell_value(value) ] }.flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
@app.run.join(" ")
|
@app.run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "run with cmd args" do
|
test "run with custom options" do
|
||||||
@config[:servers] = { "web" => [ "1.1.1.1" ], "jobs" => { "hosts" => [ "1.1.1.2" ], "cmd" => "bin/jobs", "args" => { "mount" => "somewhere" } } }
|
@config[:servers] = { "web" => [ "1.1.1.1" ], "jobs" => { "hosts" => [ "1.1.1.2" ], "cmd" => "bin/jobs", "options" => { "mount" => "somewhere" } } }
|
||||||
@app = Mrsk::Commands::App.new Mrsk::Configuration.new(@config).tap { |c| c.version = "999" }
|
@app = Mrsk::Commands::App.new Mrsk::Configuration.new(@config).tap { |c| c.version = "999" }
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --label service=\"app\" --label role=\"jobs\" dhh/app:999 bin/jobs --mount \"somewhere\"",
|
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --label service=\"app\" --label role=\"jobs\" --mount \"somewhere\" dhh/app:999 bin/jobs",
|
||||||
@app.run(role: :jobs).join(" ")
|
@app.run(role: :jobs).join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user