Skip to content

Commit

Permalink
Include role options when executing commands
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoprietog committed Jul 24, 2023
1 parent 61b7dc9 commit cbd1802
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 cbd1802

Please sign in to comment.