Include role options when executing commands
This commit is contained in:
@@ -76,11 +76,14 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute_in_new_container(*command, interactive: false)
|
def execute_in_new_container(*command, interactive: false)
|
||||||
|
role = config.role(self.role)
|
||||||
|
|
||||||
docker :run,
|
docker :run,
|
||||||
("-it" if interactive),
|
("-it" if interactive),
|
||||||
"--rm",
|
"--rm",
|
||||||
*config.env_args,
|
*config.env_args,
|
||||||
*config.volume_args,
|
*config.volume_args,
|
||||||
|
*role&.option_args,
|
||||||
config.absolute_image,
|
config.absolute_image,
|
||||||
*command
|
*command
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -171,6 +171,13 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
new_command.execute_in_new_container("bin/rails", "db:setup").join(" ")
|
new_command.execute_in_new_container("bin/rails", "db:setup").join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "execute in new container with custom options" do
|
||||||
|
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere", "cap-add" => true } } }
|
||||||
|
assert_equal \
|
||||||
|
"docker run --rm -e RAILS_MASTER_KEY=\"456\" --mount \"somewhere\" --cap-add dhh/app:999 bin/rails db:setup",
|
||||||
|
new_command.execute_in_new_container("bin/rails", "db:setup").join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
test "execute in existing container" do
|
test "execute in existing container" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker exec app-web-999 bin/rails db:setup",
|
"docker exec app-web-999 bin/rails db:setup",
|
||||||
@@ -182,6 +189,12 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "execute in new container with custom options over ssh" do
|
||||||
|
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere", "cap-add" => true } } }
|
||||||
|
assert_match %r|docker run -it --rm -e RAILS_MASTER_KEY=\"456\" --mount \"somewhere\" --cap-add dhh/app:999 bin/rails c|,
|
||||||
|
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||||
|
end
|
||||||
|
|
||||||
test "execute in existing container over ssh" do
|
test "execute in existing container over ssh" do
|
||||||
assert_match %r|docker exec -it app-web-999 bin/rails c|,
|
assert_match %r|docker exec -it app-web-999 bin/rails c|,
|
||||||
new_command.execute_in_existing_container_over_ssh("bin/rails", "c", host: "app-1")
|
new_command.execute_in_existing_container_over_ssh("bin/rails", "c", host: "app-1")
|
||||||
|
|||||||
Reference in New Issue
Block a user