Skip to content

Commit

Permalink
Merge pull request #389 from brunoprietog/include-role-options-when-e…
Browse files Browse the repository at this point in the history
…xecuting-commands

Include role options when executing commands
  • Loading branch information
dhh committed Jul 26, 2023
2 parents 752ff53 + cbd1802 commit 299b166
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/mrsk/commands/app.rb
Expand Up @@ -76,11 +76,14 @@ def execute_in_existing_container(*command, interactive: false)
end

def execute_in_new_container(*command, interactive: false)
role = config.role(self.role)

docker :run,
("-it" if interactive),
"--rm",
*config.env_args,
*config.volume_args,
*role&.option_args,
config.absolute_image,
*command
end
Expand Down
13 changes: 13 additions & 0 deletions test/commands/app_test.rb
Expand Up @@ -171,6 +171,13 @@ class CommandsAppTest < ActiveSupport::TestCase
new_command.execute_in_new_container("bin/rails", "db:setup").join(" ")
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
assert_equal \
"docker exec app-web-999 bin/rails db:setup",
Expand All @@ -182,6 +189,12 @@ class CommandsAppTest < ActiveSupport::TestCase
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
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
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")
Expand Down

0 comments on commit 299b166

Please sign in to comment.