kamal icon indicating copy to clipboard operation
kamal copied to clipboard

`false` boolean proxy option errors out in in Kamal 2

Open jeromedalbert opened this issue 1 year ago • 1 comments

When configuring Kamal 2's deploy.yml with a false boolean option in the proxy section, kamal-proxy errors out during deploy.

Steps to repro

Deploy a Rails main app (8.0.0.alpha) with the following in config/deploy.yml:

proxy:
  ssl: false

Expected behavior

Deploy is successful.

Actual behavior

Deploy fails for the following step:

docker exec kamal-proxy kamal-proxy deploy myapp-web-production --target "44d4737d819c:80" --tls "false" --deploy-timeout "30s" --drain-timeout "30s" --buffer-requests --buffer-responses --log-request-header "Cache-Control" --log-request-header "Last-Modified" --log-request-header "User-Agent"

The error is: Error: accepts 1 arg(s), received 2.

Details

The error happens because --tls "false" (or --tls false) can't be parsed by kamal-proxy. It seems to be currently set up to only accept --tls alone, meaning that TLS is true. If you don't want TLS, it seems like --tls should be skipped altogether.

I don't know enough Go and Cobra to know whether kamal-proxy itself can (or should) be fixed to somehow understand --tls false.

Otherwise the fix would be on the Kamal side. Looks like lib/kamal/commands/app/proxy.rb calls deploy_command_args which optionizes the deploy_options. The way optionize is currently implemented for false booleans is incompatible with kamal-proxy's expected boolean options.

Workaround

Comment out ssl: false in config/deploy.yml.

jeromedalbert avatar Sep 20 '24 07:09 jeromedalbert

@jeromedalbert To ensure the Proxy works correctly, the flag has to be specified as --tls=true|false instead of --tls true|false. This behavior is mentioned on a GitHub issue on the Cobra repository https://github.com/spf13/cobra/issues/613.

Given this, it will probably have to be fixed on the Kamal, not the Proxy side.

Unfortunately, I’m not very familiar with Ruby, so I can’t provide more specific details in this context. However, since I encountered a similar issue with Go's Cobra, I wanted to share this insight in case it helps.

Stavrospanakakis avatar Sep 23 '24 15:09 Stavrospanakakis