basecamp / kamal

Deploy web apps anywhere.
https://kamal-deploy.org
MIT License
10.6k stars 407 forks source link

Setting additional ENV variables cannot be used with namespaced rake tasks #800

Closed aliismayilov closed 4 months ago

aliismayilov commented 4 months ago

Not sure if it's an issue with thor gem parsing the arguments or with kamal, but the following command doesn't work:

$ ./bin/kamal app exec -e 'STATEMENT_TIMEOUT:0' 'bin/rails db:vacuum'
ERROR: "kamal app exec" was called with arguments ["STATEMENT_TIMEOUT=0", "bin/rails db:vacuum"]
Usage: "kamal app exec [CMD]"

While the following work:

$ ./bin/kamal app exec -e 'STATEMENT_TIMEOUT:0' 'bin/rails about'
Get most recent version available as an image...

$ ./bin/kamal app exec 'bin/rails db:vacuum'
Get most recent version available as an image...

Setting additional ENV variables was recently implemented: https://github.com/basecamp/kamal/pull/751

djmb commented 4 months ago

The correct format is:

./bin/kamal app exec -e='STATEMENT_TIMEOUT:0' 'bin/rails db:vacuum'
aliismayilov commented 2 months ago

The correct format is:

./bin/kamal app exec -e='STATEMENT_TIMEOUT:0' 'bin/rails db:vacuum'

Sorry @djmb for late reply, but even with the latest kamal running locally, none of the following work:

❯ kamal app exec -e='STATEMENT_TIMEOUT:0' 'bin/rails db:vacuum'
ERROR: "kamal app exec" was called with no arguments
Usage: "kamal app exec [CMD]"
❯ kamal app exec --env='STATEMENT_TIMEOUT:0' 'bin/rails db:vacuum'
ERROR: "kamal app exec" was called with no arguments
Usage: "kamal app exec [CMD]"
❯ kamal app exec -e 'STATEMENT_TIMEOUT:0' 'bin/rails db:vacuum'
ERROR: "kamal app exec" was called with no arguments
Usage: "kamal app exec [CMD]"
aliismayilov commented 2 months ago

I can confirm that the problem is in thor gem.

Reproducible small example:

#!/usr/bin/env ruby

require "thor"

class Kamal < Thor
  def self.exit_on_failure? = true

  desc "exec command", "an exec task"
  method_option :env, type: :hash
  def exec(command)
    puts "these are the options: #{options}"
    puts "this is the command: #{command}"
  end
end

Kamal.start

# ./kamal.rb exec --env='STATEMENT_TIMEOUT:0' 'bin/rails db:vacuum' => fails
# ./kamal.rb exec 'bin/rails db:vacuum' --env='STATEMENT_TIMEOUT:0' => works
# ./kamal.rb exec --env='STATEMENT_TIMEOUT:0' 'bin/rails vacuum' => works
# ./kamal.rb exec 'bin/rails vacuum' --env='STATEMENT_TIMEOUT:0' => works

I'll try to see if I can get to submit a PR to the upstream.

TLDR: Use ./bin/kamal app exec 'bin/rails db:vacuum' -e 'STATEMENT_TIMEOUT:0'