Don't hold lock on error

This commit is contained in:
Donal McBreen
2024-04-03 12:45:11 +01:00
parent d2a719998a
commit 64f5955444
4 changed files with 24 additions and 42 deletions

View File

@@ -2,7 +2,6 @@ class Kamal::Cli::App < Kamal::Cli::Base
desc "boot", "Boot app on servers (or reboot app if already running)"
def boot
mutating do
hold_lock_on_error do
say "Get most recent version available as an image...", :magenta unless options[:version]
using_version(version_or_latest) do |version|
say "Start container with version #{version} using a #{KAMAL.config.readiness_delay}s readiness delay (or reboot if already running)...", :magenta
@@ -23,7 +22,7 @@ class Kamal::Cli::App < Kamal::Cli::Base
end
end
#  Tag once the app booted on all hosts
# Tag once the app booted on all hosts
on(KAMAL.hosts) do |host|
execute *KAMAL.auditor.record("Tagging #{KAMAL.config.absolute_image} as the latest image"), verbosity: :debug
execute *KAMAL.app.tag_latest_image
@@ -31,7 +30,6 @@ class Kamal::Cli::App < Kamal::Cli::Base
end
end
end
end
desc "start", "Start existing app container on servers"
def start

View File

@@ -91,12 +91,11 @@ module Kamal::Cli
begin
yield
rescue
if KAMAL.hold_lock_on_error?
error " \e[31mDeploy lock was not released\e[0m"
else
begin
release_lock
rescue => e
say "Error releasing the deploy lock: #{e.message}", :red
end
raise
end
@@ -141,16 +140,6 @@ module Kamal::Cli
end
end
def hold_lock_on_error
if KAMAL.hold_lock_on_error?
yield
else
KAMAL.hold_lock_on_error = true
yield
KAMAL.hold_lock_on_error = false
end
end
def run_hook(hook, **extra_details)
if !options[:skip_hooks] && KAMAL.hook.hook_exists?(hook)
details = { hosts: KAMAL.hosts.join(","), command: command, subcommand: subcommand }

View File

@@ -2,13 +2,12 @@ require "active_support/core_ext/enumerable"
require "active_support/core_ext/module/delegation"
class Kamal::Commander
attr_accessor :verbosity, :holding_lock, :hold_lock_on_error
attr_accessor :verbosity, :holding_lock
delegate :hosts, :roles, :primary_host, :primary_role, :roles_on, :traefik_hosts, :accessory_hosts, to: :specifics
def initialize
self.verbosity = :info
self.holding_lock = false
self.hold_lock_on_error = false
@specifics = nil
end
@@ -138,10 +137,6 @@ class Kamal::Commander
self.holding_lock
end
def hold_lock_on_error?
self.hold_lock_on_error
end
private
# Lazy setup of SSHKit
def configure_sshkit_with(config)

View File

@@ -54,14 +54,14 @@ class CliAppTest < CliTestCase
run_command("boot", config: :with_boot_strategy)
end
test "boot errors leave lock in place" do
test "boot errors don't leave lock in place" do
Kamal::Cli::App.any_instance.expects(:using_version).raises(RuntimeError)
assert_not KAMAL.holding_lock?
assert_raises(RuntimeError) do
stderred { run_command("boot") }
end
assert KAMAL.holding_lock?
assert_not KAMAL.holding_lock?
end
test "boot with assets" do