The hook is run before the environment is loaded or the config is parsed. This makes it a bit of a special case - it doesn't have the usual KAMAL_XYZ environment variables, as we haven't parsed the config. The use case for this is to do auth checking or setup. So for example we can confirm you are logged in to a secret manager, and then you can directly call it to load your secrets in the .kamal/.env file using .dotenv's [command substitution](https://github.com/bkeepers/dotenv?tab=readme-ov-file#command-substitution).
42 lines
1.0 KiB
Ruby
42 lines
1.0 KiB
Ruby
require "bundler/setup"
|
|
require "active_support/test_case"
|
|
require "active_support/testing/autorun"
|
|
require "active_support/testing/stream"
|
|
require "debug"
|
|
require "mocha/minitest" # using #stubs that can alter returns
|
|
require "minitest/autorun" # using #stub that take args
|
|
require "sshkit"
|
|
require "kamal"
|
|
|
|
ActiveSupport::LogSubscriber.logger = ActiveSupport::Logger.new(STDOUT) if ENV["VERBOSE"]
|
|
|
|
# Applies to remote commands only.
|
|
SSHKit.config.backend = SSHKit::Backend::Printer
|
|
|
|
# Ensure local commands use the printer backend too.
|
|
# See https://github.com/capistrano/sshkit/blob/master/lib/sshkit/dsl.rb#L9
|
|
module SSHKit
|
|
module DSL
|
|
def run_locally(&block)
|
|
SSHKit::Backend::Printer.new(SSHKit::Host.new(:local), &block).run
|
|
end
|
|
end
|
|
end
|
|
|
|
class ActiveSupport::TestCase
|
|
include ActiveSupport::Testing::Stream
|
|
|
|
setup do
|
|
Kamal::Cli::Base.ran_pre_init_hook = false
|
|
end
|
|
|
|
private
|
|
def stdouted
|
|
capture(:stdout) { yield }.strip
|
|
end
|
|
|
|
def stderred
|
|
capture(:stderr) { yield }.strip
|
|
end
|
|
end
|