diff --git a/lib/kamal/cli/app.rb b/lib/kamal/cli/app.rb index d28de3c4..ac2b9e40 100644 --- a/lib/kamal/cli/app.rb +++ b/lib/kamal/cli/app.rb @@ -2,32 +2,30 @@ 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 + 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 - # Assets are prepared in a separate step to ensure they are on all hosts before booting - on(KAMAL.hosts) do - KAMAL.roles_on(host).each do |role| - Kamal::Cli::App::PrepareAssets.new(host, role, self).run - end + # Assets are prepared in a separate step to ensure they are on all hosts before booting + on(KAMAL.hosts) do + KAMAL.roles_on(host).each do |role| + Kamal::Cli::App::PrepareAssets.new(host, role, self).run end + end - #  Primary hosts and roles are returned first, so they can open the barrier - barrier = Kamal::Cli::Healthcheck::Barrier.new if KAMAL.roles.many? + # Primary hosts and roles are returned first, so they can open the barrier + barrier = Kamal::Cli::Healthcheck::Barrier.new if KAMAL.roles.many? - on(KAMAL.hosts, **KAMAL.boot_strategy) do |host| - KAMAL.roles_on(host).each do |role| - Kamal::Cli::App::Boot.new(host, role, self, version, barrier).run - end + on(KAMAL.hosts, **KAMAL.boot_strategy) do |host| + KAMAL.roles_on(host).each do |role| + Kamal::Cli::App::Boot.new(host, role, self, version, barrier).run end + end - #  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 - end + # 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 end end end diff --git a/lib/kamal/cli/base.rb b/lib/kamal/cli/base.rb index 1cee5484..d363a8ee 100644 --- a/lib/kamal/cli/base.rb +++ b/lib/kamal/cli/base.rb @@ -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 } diff --git a/lib/kamal/commander.rb b/lib/kamal/commander.rb index e7c5d21f..9937cb69 100644 --- a/lib/kamal/commander.rb +++ b/lib/kamal/commander.rb @@ -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) diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb index 7a2a266e..643f8d85 100644 --- a/test/cli/app_test.rb +++ b/test/cli/app_test.rb @@ -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