Skip to content

Commit

Permalink
Merge pull request #461 from basecamp/escape-newline-from-inspect-format
Browse files Browse the repository at this point in the history
Escape the newline in the inspect query
  • Loading branch information
djmb authored Sep 12, 2023
2 parents a367819 + fb0aeec commit 0e021e3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/kamal/commands/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def remove_env_file

def cord(version:)
pipe \
docker(:inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\n\" .Source .Destination}}{{ end }}'", container_name(version)),
docker(:inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", container_name(version)),
[:awk, "'$2 == \"#{role_config.cord_volume.container_path}\" {print $1}'"]
end

Expand Down
4 changes: 2 additions & 2 deletions test/cli/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CliAppTest < CliTestCase
.returns("123") # old version

SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\n\" .Source .Destination}}{{ end }}'", "app-web-123", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", :raise_on_non_zero_exit => false)
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", "app-web-123", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", :raise_on_non_zero_exit => false)
.returns("cordfile") # old version

SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
Expand Down Expand Up @@ -79,7 +79,7 @@ class CliAppTest < CliTestCase
.returns("123").twice # old version

SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\n\" .Source .Destination}}{{ end }}'", "app-web-123", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", :raise_on_non_zero_exit => false)
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", "app-web-123", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", :raise_on_non_zero_exit => false)
.returns("") # old version

run_command("boot", config: :with_assets).tap do |output|
Expand Down
2 changes: 1 addition & 1 deletion test/cli/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class CliMainTest < CliTestCase
end

SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\n\" .Source .Destination}}{{ end }}'", "app-web-version-to-rollback", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", :raise_on_non_zero_exit => false)
.with(:docker, :inspect, "-f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}'", "app-web-version-to-rollback", "|", :awk, "'$2 == \"/tmp/kamal-cord\" {print $1}'", :raise_on_non_zero_exit => false)
.returns("corddirectory").at_least_once # health check

SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
Expand Down
2 changes: 1 addition & 1 deletion test/commands/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class CommandsAppTest < ActiveSupport::TestCase
end

test "cord" do
assert_equal "docker inspect -f '{{ range .Mounts }}{{printf \"%s %s\n\" .Source .Destination}}{{ end }}' app-web-123 | awk '$2 == \"/tmp/kamal-cord\" {print $1}'", new_command.cord(version: 123).join(" ")
assert_equal "docker inspect -f '{{ range .Mounts }}{{printf \"%s %s\\n\" .Source .Destination}}{{ end }}' app-web-123 | awk '$2 == \"/tmp/kamal-cord\" {print $1}'", new_command.cord(version: 123).join(" ")
end

test "tie cord" do
Expand Down

0 comments on commit 0e021e3

Please sign in to comment.