From cd02510d0fcaf93330dbff52b2fb30579e9d8a97 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Thu, 7 Sep 2023 15:20:50 +0100 Subject: [PATCH] Output one mount per line The go template was concatenating all the mounts into one line. It happened to work because the mount we are interested was always first. Fix it to output one mount per line instead. --- lib/kamal/commands/app.rb | 2 +- test/cli/app_test.rb | 2 +- test/cli/main_test.rb | 2 +- test/commands/app_test.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/kamal/commands/app.rb b/lib/kamal/commands/app.rb index 7fac2e17..3a8b0789 100644 --- a/lib/kamal/commands/app.rb +++ b/lib/kamal/commands/app.rb @@ -152,7 +152,7 @@ class Kamal::Commands::App < Kamal::Commands::Base def cord(version:) pipe \ - docker(:inspect, "-f '{{ range .Mounts }}{{ .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_container_directory}\" {print $1}'"] end diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb index d0e6268a..a1c08379 100644 --- a/test/cli/app_test.rb +++ b/test/cli/app_test.rb @@ -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 }}{{ .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) diff --git a/test/cli/main_test.rb b/test/cli/main_test.rb index 28ef97ff..6adbf7e1 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -193,7 +193,7 @@ class CliMainTest < CliTestCase end SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) - .with(:docker, :inspect, "-f '{{ range .Mounts }}{{ .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) diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index 7b769c6d..c2e020ec 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -332,7 +332,7 @@ class CommandsAppTest < ActiveSupport::TestCase end test "cord" do - assert_equal "docker inspect -f '{{ range .Mounts }}{{ .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