Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/kamal/cli/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def run_hook(hook, **extra_details)
end

with_env KAMAL.hook.env(**details, **extra_details) do
prepend_kamal_bin_to_path
KAMAL.with_verbosity(hook_verbosity) do
run_locally do
execute *KAMAL.hook.run(hook)
Expand Down Expand Up @@ -219,6 +220,12 @@ def with_env(env)
ENV.update(current_env)
end

def prepend_kamal_bin_to_path
kamal_bin = File.expand_path(".kamal/bin")
ENV["PATH"] = "#{kamal_bin}#{File::PATH_SEPARATOR}#{ENV["PATH"]}" \
if Dir.exist?(kamal_bin)
end

def ensure_docker_installed
run_locally do
begin
Expand Down
47 changes: 47 additions & 0 deletions test/cli/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,53 @@ class CliMainTest < CliTestCase
end
end

test ".kamal/bin is prepended to PATH by prepend_kamal_bin_to_path" do
Dir.mktmpdir do |tmpdir|
Dir.chdir(tmpdir) do
FileUtils.mkdir_p(".kamal/bin")

cli = Kamal::Cli::Base.allocate
original_path = ENV["PATH"]
kamal_bin = File.expand_path(".kamal/bin")

cli.send(:prepend_kamal_bin_to_path)
assert ENV["PATH"].start_with?("#{kamal_bin}#{File::PATH_SEPARATOR}"),
"Expected PATH to start with #{kamal_bin}, got: #{ENV["PATH"]}"

ENV["PATH"] = original_path
end
end
end

test ".kamal/bin is not added to PATH when directory is absent" do
Dir.mktmpdir do |tmpdir|
Dir.chdir(tmpdir) do
cli = Kamal::Cli::Base.allocate
original_path = ENV["PATH"]

cli.send(:prepend_kamal_bin_to_path)
assert_equal original_path, ENV["PATH"],
"PATH should be unchanged when .kamal/bin does not exist"
end
end
end

test "with_env does not prepend .kamal/bin to PATH" do
Dir.mktmpdir do |tmpdir|
Dir.chdir(tmpdir) do
FileUtils.mkdir_p(".kamal/bin")

cli = Kamal::Cli::Base.allocate
original_path = ENV["PATH"]

cli.send(:with_env, { "FOO" => "bar" }) do
assert_equal original_path, ENV["PATH"],
"with_env should not modify PATH"
end
end
end
end

test "upgrade rolling" do
invoke_options = { "config_file" => "test/fixtures/deploy_with_accessories.yml", "skip_hooks" => false, "confirmed" => true, "rolling" => false }
Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:upgrade", [], invoke_options).times(4)
Expand Down