diff --git a/lib/kamal/cli/app.rb b/lib/kamal/cli/app.rb index 74b7b4df..69a15709 100644 --- a/lib/kamal/cli/app.rb +++ b/lib/kamal/cli/app.rb @@ -97,6 +97,10 @@ def details def exec(*cmd) cmd = Kamal::Utils.join_commands(cmd) env = options[:env] + unless options[:reuse] + say "Log into image registry...", :magenta + invoke "kamal:cli:registry:login", [], {skip_local: true} + end case when options[:interactive] && options[:reuse] say "Get current version of running container...", :magenta unless options[:version] diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb index 5e76179c..da33a8e3 100644 --- a/test/cli/app_test.rb +++ b/test/cli/app_test.rb @@ -299,6 +299,17 @@ class CliAppTest < CliTestCase end end + test "exec logs into the container registry remotely for new containers" do + run_command("exec", "ruby -v").tap do |output| + assert_no_match /docker login -u \[REDACTED\] -p \[REDACTED\] as .*@localhost/, output + assert_match /docker login -u \[REDACTED\] -p \[REDACTED\] on 1.1.1.\d/, output + end + # Login is never required if reuse + run_command("exec", "-i", "--reuse", "ruby -v").tap do |output| + assert_no_match /docker login -u \[REDACTED\] -p \[REDACTED\] on 1.1.1.\d/, output + end + end + test "containers" do run_command("containers").tap do |output| assert_match "docker container ls --all --filter label=service=app", output