Better lock messages
- Debug verbosity commands - Show lock status when we fail to acquire it - Include lock acquire/release in runtime
This commit is contained in:
@@ -99,26 +99,32 @@ module Mrsk::Cli
|
||||
end
|
||||
|
||||
def acquire_lock
|
||||
say "Acquiring the deploy lock"
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.acquire("Automatic deploy lock", MRSK.config.version) }
|
||||
raise_if_locked do
|
||||
say "Acquiring the deploy lock...", :magenta
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.acquire("Automatic deploy lock", MRSK.config.version), verbosity: :debug }
|
||||
end
|
||||
|
||||
MRSK.holding_lock = true
|
||||
end
|
||||
|
||||
def release_lock
|
||||
say "Releasing the deploy lock...", :magenta
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.release, verbosity: :debug }
|
||||
|
||||
MRSK.holding_lock = false
|
||||
end
|
||||
|
||||
def raise_if_locked
|
||||
yield
|
||||
rescue SSHKit::Runner::ExecuteError => e
|
||||
if e.message =~ /cannot create directory/
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.status }
|
||||
on(MRSK.primary_host) { puts capture_with_debug(*MRSK.lock.status) }
|
||||
raise LockError, "Deploy lock found"
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
def release_lock
|
||||
say "Releasing the deploy lock"
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.release }
|
||||
|
||||
MRSK.holding_lock = false
|
||||
end
|
||||
|
||||
def hold_lock_on_error
|
||||
if MRSK.hold_lock_on_error?
|
||||
yield
|
||||
|
||||
@@ -2,7 +2,7 @@ class Mrsk::Cli::Lock < Mrsk::Cli::Base
|
||||
desc "status", "Report lock status"
|
||||
def status
|
||||
handle_missing_lock do
|
||||
on(MRSK.primary_host) { puts capture_with_info(*MRSK.lock.status) }
|
||||
on(MRSK.primary_host) { puts capture_with_debug(*MRSK.lock.status) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,8 +10,8 @@ class Mrsk::Cli::Lock < Mrsk::Cli::Base
|
||||
option :message, aliases: "-m", type: :string, desc: "A lock mesasge", required: true
|
||||
def acquire
|
||||
message = options[:message]
|
||||
handle_missing_lock do
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.acquire(message, MRSK.config.version) }
|
||||
raise_if_locked do
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.acquire(message, MRSK.config.version), verbosity: :debug }
|
||||
say "Acquired the deploy lock"
|
||||
end
|
||||
end
|
||||
@@ -19,7 +19,7 @@ class Mrsk::Cli::Lock < Mrsk::Cli::Base
|
||||
desc "release", "Release the deploy lock"
|
||||
def release
|
||||
handle_missing_lock do
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.release }
|
||||
on(MRSK.primary_host) { execute *MRSK.lock.release, verbosity: :debug }
|
||||
say "Released the deploy lock"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
desc "setup", "Setup all accessories and deploy app to servers"
|
||||
def setup
|
||||
with_lock do
|
||||
print_runtime do
|
||||
print_runtime do
|
||||
with_lock do
|
||||
invoke "mrsk:cli:server:bootstrap"
|
||||
invoke "mrsk:cli:accessory:boot", [ "all" ]
|
||||
deploy
|
||||
@@ -13,10 +13,10 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
desc "deploy", "Deploy app to servers"
|
||||
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip image build and push"
|
||||
def deploy
|
||||
with_lock do
|
||||
invoke_options = deploy_options
|
||||
runtime = print_runtime do
|
||||
with_lock do
|
||||
invoke_options = deploy_options
|
||||
|
||||
runtime = print_runtime do
|
||||
say "Log into image registry...", :magenta
|
||||
invoke "mrsk:cli:registry:login", [], invoke_options
|
||||
|
||||
@@ -44,18 +44,18 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
say "Prune old containers and images...", :magenta
|
||||
invoke "mrsk:cli:prune:all", [], invoke_options
|
||||
end
|
||||
|
||||
audit_broadcast "Deployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
||||
end
|
||||
|
||||
audit_broadcast "Deployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
||||
end
|
||||
|
||||
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login"
|
||||
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip image build and push"
|
||||
def redeploy
|
||||
with_lock do
|
||||
invoke_options = deploy_options
|
||||
runtime = print_runtime do
|
||||
with_lock do
|
||||
invoke_options = deploy_options
|
||||
|
||||
runtime = print_runtime do
|
||||
if options[:skip_push]
|
||||
say "Pull app image...", :magenta
|
||||
invoke "mrsk:cli:build:pull", [], invoke_options
|
||||
@@ -74,9 +74,9 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
invoke "mrsk:cli:app:boot", [], invoke_options
|
||||
end
|
||||
end
|
||||
|
||||
audit_broadcast "Redeployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
||||
end
|
||||
|
||||
audit_broadcast "Redeployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
||||
end
|
||||
|
||||
desc "rollback [VERSION]", "Rollback app to VERSION"
|
||||
|
||||
@@ -8,6 +8,10 @@ class SSHKit::Backend::Abstract
|
||||
capture(*args, **kwargs, verbosity: Logger::INFO)
|
||||
end
|
||||
|
||||
def capture_with_debug(*args, **kwargs)
|
||||
capture(*args, **kwargs, verbosity: Logger::DEBUG)
|
||||
end
|
||||
|
||||
def capture_with_pretty_json(*args, **kwargs)
|
||||
JSON.pretty_generate(JSON.parse(capture(*args, **kwargs)))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user