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
|
end
|
||||||
|
|
||||||
def acquire_lock
|
def acquire_lock
|
||||||
say "Acquiring the deploy lock"
|
raise_if_locked do
|
||||||
on(MRSK.primary_host) { execute *MRSK.lock.acquire("Automatic deploy lock", MRSK.config.version) }
|
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
|
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
|
rescue SSHKit::Runner::ExecuteError => e
|
||||||
if e.message =~ /cannot create directory/
|
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"
|
raise LockError, "Deploy lock found"
|
||||||
else
|
else
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
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
|
def hold_lock_on_error
|
||||||
if MRSK.hold_lock_on_error?
|
if MRSK.hold_lock_on_error?
|
||||||
yield
|
yield
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class Mrsk::Cli::Lock < Mrsk::Cli::Base
|
|||||||
desc "status", "Report lock status"
|
desc "status", "Report lock status"
|
||||||
def status
|
def status
|
||||||
handle_missing_lock do
|
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
|
||||||
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
|
option :message, aliases: "-m", type: :string, desc: "A lock mesasge", required: true
|
||||||
def acquire
|
def acquire
|
||||||
message = options[:message]
|
message = options[:message]
|
||||||
handle_missing_lock do
|
raise_if_locked do
|
||||||
on(MRSK.primary_host) { execute *MRSK.lock.acquire(message, MRSK.config.version) }
|
on(MRSK.primary_host) { execute *MRSK.lock.acquire(message, MRSK.config.version), verbosity: :debug }
|
||||||
say "Acquired the deploy lock"
|
say "Acquired the deploy lock"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -19,7 +19,7 @@ class Mrsk::Cli::Lock < Mrsk::Cli::Base
|
|||||||
desc "release", "Release the deploy lock"
|
desc "release", "Release the deploy lock"
|
||||||
def release
|
def release
|
||||||
handle_missing_lock do
|
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"
|
say "Released the deploy lock"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
class Mrsk::Cli::Main < Mrsk::Cli::Base
|
class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||||
desc "setup", "Setup all accessories and deploy app to servers"
|
desc "setup", "Setup all accessories and deploy app to servers"
|
||||||
def setup
|
def setup
|
||||||
with_lock do
|
|
||||||
print_runtime do
|
print_runtime do
|
||||||
|
with_lock do
|
||||||
invoke "mrsk:cli:server:bootstrap"
|
invoke "mrsk:cli:server:bootstrap"
|
||||||
invoke "mrsk:cli:accessory:boot", [ "all" ]
|
invoke "mrsk:cli:accessory:boot", [ "all" ]
|
||||||
deploy
|
deploy
|
||||||
@@ -13,10 +13,10 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
desc "deploy", "Deploy app to servers"
|
desc "deploy", "Deploy app to servers"
|
||||||
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip image build and push"
|
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip image build and push"
|
||||||
def deploy
|
def deploy
|
||||||
|
runtime = print_runtime do
|
||||||
with_lock do
|
with_lock do
|
||||||
invoke_options = deploy_options
|
invoke_options = deploy_options
|
||||||
|
|
||||||
runtime = print_runtime do
|
|
||||||
say "Log into image registry...", :magenta
|
say "Log into image registry...", :magenta
|
||||||
invoke "mrsk:cli:registry:login", [], invoke_options
|
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
|
say "Prune old containers and images...", :magenta
|
||||||
invoke "mrsk:cli:prune:all", [], invoke_options
|
invoke "mrsk:cli:prune:all", [], invoke_options
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
audit_broadcast "Deployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
audit_broadcast "Deployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login"
|
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"
|
option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip image build and push"
|
||||||
def redeploy
|
def redeploy
|
||||||
|
runtime = print_runtime do
|
||||||
with_lock do
|
with_lock do
|
||||||
invoke_options = deploy_options
|
invoke_options = deploy_options
|
||||||
|
|
||||||
runtime = print_runtime do
|
|
||||||
if options[:skip_push]
|
if options[:skip_push]
|
||||||
say "Pull app image...", :magenta
|
say "Pull app image...", :magenta
|
||||||
invoke "mrsk:cli:build:pull", [], invoke_options
|
invoke "mrsk:cli:build:pull", [], invoke_options
|
||||||
@@ -74,10 +74,10 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
invoke "mrsk:cli:app:boot", [], invoke_options
|
invoke "mrsk:cli:app:boot", [], invoke_options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
audit_broadcast "Redeployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
audit_broadcast "Redeployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
desc "rollback [VERSION]", "Rollback app to VERSION"
|
desc "rollback [VERSION]", "Rollback app to VERSION"
|
||||||
def rollback(version)
|
def rollback(version)
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ class SSHKit::Backend::Abstract
|
|||||||
capture(*args, **kwargs, verbosity: Logger::INFO)
|
capture(*args, **kwargs, verbosity: Logger::INFO)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def capture_with_debug(*args, **kwargs)
|
||||||
|
capture(*args, **kwargs, verbosity: Logger::DEBUG)
|
||||||
|
end
|
||||||
|
|
||||||
def capture_with_pretty_json(*args, **kwargs)
|
def capture_with_pretty_json(*args, **kwargs)
|
||||||
JSON.pretty_generate(JSON.parse(capture(*args, **kwargs)))
|
JSON.pretty_generate(JSON.parse(capture(*args, **kwargs)))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class CliMainTest < CliTestCase
|
|||||||
.with { |*arg| arg[0..1] == [:mkdir, :mrsk_lock] }
|
.with { |*arg| arg[0..1] == [:mkdir, :mrsk_lock] }
|
||||||
.raises(RuntimeError, "mkdir: cannot create directory ‘mrsk_lock’: File exists")
|
.raises(RuntimeError, "mkdir: cannot create directory ‘mrsk_lock’: File exists")
|
||||||
|
|
||||||
SSHKit::Backend::Abstract.any_instance.expects(:execute)
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_debug)
|
||||||
.with(:stat, :mrsk_lock, ">", "/dev/null", "&&", :cat, "mrsk_lock/details", "|", :base64, "-d")
|
.with(:stat, :mrsk_lock, ">", "/dev/null", "&&", :cat, "mrsk_lock/details", "|", :base64, "-d")
|
||||||
|
|
||||||
assert_raises(Mrsk::Cli::LockError) do
|
assert_raises(Mrsk::Cli::LockError) do
|
||||||
|
|||||||
Reference in New Issue
Block a user