Add post-deploy and post-rollback hooks
These replace the custom audit_broadcast_cmd code. An additional env variable MRSK_RUNTIME is passed to them. The audit broadcast after booting an accessory has been removed.
This commit is contained in:
@@ -14,8 +14,6 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
||||
execute *MRSK.auditor.record("Booted #{name} accessory"), verbosity: :debug
|
||||
execute *accessory.run
|
||||
end
|
||||
|
||||
audit_broadcast "Booted accessory #{name}" unless options[:skip_broadcast]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -72,10 +72,6 @@ module Mrsk::Cli
|
||||
puts " Finished all in #{sprintf("%.1f seconds", runtime)}"
|
||||
end
|
||||
|
||||
def audit_broadcast(line)
|
||||
run_locally { execute *MRSK.auditor.broadcast(line), verbosity: :debug }
|
||||
end
|
||||
|
||||
def with_lock
|
||||
if MRSK.holding_lock?
|
||||
yield
|
||||
@@ -135,11 +131,11 @@ module Mrsk::Cli
|
||||
end
|
||||
end
|
||||
|
||||
def run_hook(hook)
|
||||
def run_hook(hook, **details)
|
||||
run_locally do
|
||||
if MRSK.hook.hook_exists?(hook)
|
||||
begin
|
||||
MRSK.with_verbosity(:debug) { execute(*MRSK.hook.run(hook)) }
|
||||
MRSK.with_verbosity(:debug) { execute(*MRSK.hook.run(hook, **details)) }
|
||||
rescue SSHKit::Command::Failed
|
||||
raise HookError.new("Hook `#{hook}` failed")
|
||||
end
|
||||
|
||||
@@ -44,7 +44,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
end
|
||||
end
|
||||
|
||||
audit_broadcast "Deployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
||||
run_hook "post-deploy", runtime: runtime.round
|
||||
end
|
||||
|
||||
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login"
|
||||
@@ -72,13 +72,15 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
end
|
||||
end
|
||||
|
||||
audit_broadcast "Redeployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
||||
run_hook "post-deploy", runtime: runtime.round
|
||||
end
|
||||
|
||||
desc "rollback [VERSION]", "Rollback app to VERSION"
|
||||
def rollback(version)
|
||||
with_lock do
|
||||
invoke_options = deploy_options
|
||||
rolled_back = false
|
||||
runtime = print_runtime do
|
||||
with_lock do
|
||||
invoke_options = deploy_options
|
||||
|
||||
MRSK.config.version = version
|
||||
old_version = nil
|
||||
@@ -86,7 +88,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
if container_available?(version)
|
||||
invoke "mrsk:cli:app:boot", [], invoke_options.merge(version: version)
|
||||
|
||||
audit_broadcast "Rolled back #{service_version(Mrsk::Utils.abbreviate_version(old_version))} to #{service_version}" unless options[:skip_broadcast]
|
||||
run_hook "post-deploy", runtime: runtime.round
|
||||
else
|
||||
say "The app version '#{version}' is not available as a container (use 'mrsk app containers' for available versions)", :red
|
||||
end
|
||||
@@ -180,13 +182,6 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
end
|
||||
end
|
||||
|
||||
desc "broadcast", "Broadcast an audit message"
|
||||
option :message, aliases: "-m", type: :string, desc: "Audit message", required: true
|
||||
def broadcast
|
||||
say "Broadcast: #{options[:message]}", :magenta
|
||||
audit_broadcast options[:message]
|
||||
end
|
||||
|
||||
desc "version", "Show MRSK version"
|
||||
def version
|
||||
puts Mrsk::VERSION
|
||||
|
||||
@@ -25,10 +25,6 @@ registry:
|
||||
# secret:
|
||||
# - RAILS_MASTER_KEY
|
||||
|
||||
# Call a broadcast command on deploys.
|
||||
# audit_broadcast_cmd:
|
||||
# bin/broadcast_to_bc
|
||||
|
||||
# Use a different ssh user than root
|
||||
# ssh:
|
||||
# user: app
|
||||
|
||||
18
lib/mrsk/cli/templates/sample_hooks/post-deploy.sample
Normal file
18
lib/mrsk/cli/templates/sample_hooks/post-deploy.sample
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
# A sample post-deploy hook
|
||||
#
|
||||
# Checks:
|
||||
# 1. We have a clean checkout
|
||||
# 2. A remote is configured
|
||||
# 3. The branch has been pushed to the remote
|
||||
# 4. The version we are deploying matches the remote
|
||||
#
|
||||
# These environment variables are available:
|
||||
# MRSK_RECORDED_AT
|
||||
# MRSK_PERFORMER
|
||||
# MRSK_VERSION
|
||||
# MRSK_DESTINATION (if set)
|
||||
# MRSK_RUNTIME
|
||||
|
||||
echo "$MRSK_PERFORMER deployed $MRSK_VERSION to $MRSK_DESTINATION in $MRSK_RUNTIME seconds"
|
||||
18
lib/mrsk/cli/templates/sample_hooks/post-rollback.sample
Normal file
18
lib/mrsk/cli/templates/sample_hooks/post-rollback.sample
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
# A sample post-rollback hook
|
||||
#
|
||||
# Checks:
|
||||
# 1. We have a clean checkout
|
||||
# 2. A remote is configured
|
||||
# 3. The branch has been pushed to the remote
|
||||
# 4. The version we are deploying matches the remote
|
||||
#
|
||||
# These environment variables are available:
|
||||
# MRSK_RECORDED_AT
|
||||
# MRSK_PERFORMER
|
||||
# MRSK_VERSION
|
||||
# MRSK_DESTINATION (if set)
|
||||
# MRSK_RUNTIME
|
||||
|
||||
echo "$MRSK_PERFORMER rolled back to $MRSK_VERSION on $MRSK_DESTINATION in $MRSK_RUNTIME seconds"
|
||||
@@ -13,14 +13,6 @@ class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
||||
audit_log_file
|
||||
end
|
||||
|
||||
# Runs locally
|
||||
def broadcast(line, **details)
|
||||
if broadcast_cmd = config.audit_broadcast_cmd
|
||||
tags = audit_tags(**details, event: line)
|
||||
[ broadcast_cmd, "'#{tags.except(:recorded_at, :event, :version)} #{line}'", env: tags.env ]
|
||||
end
|
||||
end
|
||||
|
||||
def reveal
|
||||
[ :tail, "-n", 50, audit_log_file ]
|
||||
end
|
||||
|
||||
@@ -157,10 +157,6 @@ class Mrsk::Configuration
|
||||
end
|
||||
|
||||
|
||||
def audit_broadcast_cmd
|
||||
raw_config.audit_broadcast_cmd
|
||||
end
|
||||
|
||||
def healthcheck
|
||||
{ "path" => "/up", "port" => 3000, "max_attempts" => 7 }.merge(raw_config.healthcheck || {})
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user