Merge branch 'main' into cleanup-excessive-containers-running
* main: (24 commits) Bump version for 0.11.0 Labels can be added to Traefik Make rollbacks role-aware fix typo role to roles Explained the latest modifications of Traefik container labels Remove .idea folder Updated README.md with new healthcheck.max_attempts option Fix test case: console output message was not updated to display the current/total attempts Require net-ssh ~> 7.0 for SHA-2 support Improved deploy lock acquisition Excess CR Style Simpler Make it explicit, focus on Ubuntu More explicit Not that --bundle is a Rails 7+ option Update README.md Update README.md Improved: configurable max_attempts for healthcheck Traefik service name to be derived from role and destination ...
This commit is contained in:
@@ -6,8 +6,6 @@ module Mrsk::Cli
|
||||
class Base < Thor
|
||||
include SSHKit::DSL
|
||||
|
||||
class LockError < StandardError; end
|
||||
|
||||
def self.exit_on_failure?() true end
|
||||
|
||||
class_option :verbose, type: :boolean, aliases: "-v", desc: "Detailed logging"
|
||||
@@ -82,8 +80,11 @@ module Mrsk::Cli
|
||||
acquire_lock
|
||||
|
||||
yield
|
||||
ensure
|
||||
|
||||
release_lock
|
||||
rescue
|
||||
error " \e[31mDeploy lock was not released\e[0m" if MRSK.lock_count > 0
|
||||
raise
|
||||
end
|
||||
|
||||
def acquire_lock
|
||||
@@ -95,9 +96,10 @@ module Mrsk::Cli
|
||||
rescue SSHKit::Runner::ExecuteError => e
|
||||
if e.message =~ /cannot create directory/
|
||||
invoke "mrsk:cli:lock:status", []
|
||||
raise LockError, "Deploy lock found"
|
||||
else
|
||||
raise e
|
||||
end
|
||||
|
||||
raise LockError, "Deploy lock found"
|
||||
end
|
||||
|
||||
def release_lock
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
||||
MAX_ATTEMPTS = 7
|
||||
|
||||
class HealthcheckError < StandardError; end
|
||||
|
||||
@@ -13,6 +12,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
||||
|
||||
target = "Health check against #{MRSK.config.healthcheck["path"]}"
|
||||
attempt = 1
|
||||
max_attempts = MRSK.config.healthcheck["max_attempts"]
|
||||
|
||||
begin
|
||||
status = capture_with_info(*MRSK.healthcheck.curl)
|
||||
@@ -23,8 +23,8 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
||||
raise HealthcheckError, "#{target} failed with status #{status}"
|
||||
end
|
||||
rescue SSHKit::Command::Failed
|
||||
if attempt <= MAX_ATTEMPTS
|
||||
info "#{target} failed to respond, retrying in #{attempt}s..."
|
||||
if attempt <= max_attempts
|
||||
info "#{target} failed to respond, retrying in #{attempt}s (attempt #{attempt}/#{max_attempts})..."
|
||||
sleep attempt
|
||||
attempt += 1
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class Mrsk::Cli::Lock < Mrsk::Cli::Base
|
||||
message = options[:message]
|
||||
handle_missing_lock do
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.acquire(message, MRSK.config.version) }
|
||||
say "Set the deploy lock"
|
||||
say "Acquired the deploy lock"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,7 +20,7 @@ class Mrsk::Cli::Lock < Mrsk::Cli::Base
|
||||
def release
|
||||
handle_missing_lock do
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.release }
|
||||
say "Removed the deploy lock"
|
||||
say "Released the deploy lock"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -83,21 +83,26 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
with_lock do
|
||||
MRSK.config.version = version
|
||||
|
||||
if container_name_available?(MRSK.config.service_with_version)
|
||||
if container_available?(version)
|
||||
say "Start version #{version}, then wait #{MRSK.config.readiness_delay}s for app to boot before stopping the old version...", :magenta
|
||||
|
||||
cli = self
|
||||
old_version = nil
|
||||
|
||||
on(MRSK.hosts) do |host|
|
||||
old_version = capture_with_info(*MRSK.app.current_running_version).strip.presence
|
||||
roles = MRSK.roles_on(host)
|
||||
|
||||
execute *MRSK.app.start
|
||||
roles.each do |role|
|
||||
app = MRSK.app(role: role)
|
||||
old_version = capture_with_info(*app.current_running_version).strip.presence
|
||||
|
||||
if old_version
|
||||
sleep MRSK.config.readiness_delay
|
||||
execute *app.start
|
||||
|
||||
execute *MRSK.app.stop(version: old_version), raise_on_non_zero_exit: false
|
||||
if old_version
|
||||
sleep MRSK.config.readiness_delay
|
||||
|
||||
execute *app.stop(version: old_version), raise_on_non_zero_exit: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -220,10 +225,15 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
subcommand "lock", Mrsk::Cli::Lock
|
||||
|
||||
private
|
||||
def container_name_available?(container_name, host: MRSK.primary_host)
|
||||
container_names = nil
|
||||
on(host) { container_names = capture_with_info(*MRSK.app.list_container_names).split("\n") }
|
||||
Array(container_names).include?(container_name)
|
||||
def container_available?(version, host: MRSK.primary_host)
|
||||
available = nil
|
||||
|
||||
on(host) do
|
||||
first_role = MRSK.roles_on(host).first
|
||||
available = capture_with_info(*MRSK.app(role: first_role).container_id_for_version(version)).present?
|
||||
end
|
||||
|
||||
available
|
||||
end
|
||||
|
||||
def deploy_options
|
||||
|
||||
@@ -2,7 +2,10 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
|
||||
desc "boot", "Boot Traefik on servers"
|
||||
def boot
|
||||
with_lock do
|
||||
on(MRSK.traefik_hosts) { execute *MRSK.traefik.run, raise_on_non_zero_exit: false }
|
||||
on(MRSK.traefik_hosts) do
|
||||
execute *MRSK.registry.login
|
||||
execute *MRSK.traefik.run, raise_on_non_zero_exit: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user