Inherit locks

We'll set the KAMAL_LOCK environment when calling run hooks. If set to
true we have the lock and the hook will not need to acquire it again if
it runs kamal commands.

Fixes: https://github.com/basecamp/kamal/issues/1517
This commit is contained in:
Donal McBreen
2025-04-22 09:00:22 +01:00
parent aa57462c1b
commit 04568dea2f
3 changed files with 43 additions and 4 deletions

View File

@@ -133,7 +133,13 @@ module Kamal::Cli
def run_hook(hook, **extra_details)
if !options[:skip_hooks] && KAMAL.hook.hook_exists?(hook)
details = { hosts: KAMAL.hosts.join(","), roles: KAMAL.specific_roles&.join(","), command: command, subcommand: subcommand }.compact
details = {
hosts: KAMAL.hosts.join(","),
roles: KAMAL.specific_roles&.join(","),
lock: KAMAL.holding_lock?.to_s,
command: command,
subcommand: subcommand
}.compact
say "Running the #{hook} hook...", :magenta
with_env KAMAL.hook.env(**details, **extra_details) do

View File

@@ -13,7 +13,7 @@ class Kamal::Commander
def reset
self.verbosity = :info
self.holding_lock = false
self.holding_lock = ENV["KAMAL_LOCK"] == "true"
self.connected = false
@specifics = @specific_roles = @specific_hosts = nil
@config = @config_kwargs = nil