Add audit broadcasts
This commit is contained in:
@@ -59,9 +59,14 @@ module Mrsk::Cli
|
||||
def print_runtime
|
||||
started_at = Time.now
|
||||
yield
|
||||
return Time.now - started_at
|
||||
ensure
|
||||
runtime = Time.now - started_at
|
||||
puts " Finished all in #{sprintf("%.1f seconds", runtime)}"
|
||||
end
|
||||
|
||||
def audit_broadcast(line)
|
||||
run_locally { execute *MRSK.auditor.broadcast(line), verbosity: :debug }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
|
||||
desc "deploy", "Deploy the app to servers"
|
||||
def deploy
|
||||
print_runtime do
|
||||
runtime = print_runtime do
|
||||
say "Ensure Docker is installed...", :magenta
|
||||
invoke "mrsk:cli:server:bootstrap"
|
||||
|
||||
@@ -28,16 +28,20 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
say "Prune old containers and images...", :magenta
|
||||
invoke "mrsk:cli:prune:all"
|
||||
end
|
||||
|
||||
audit_broadcast "Deployed in #{runtime.to_i} seconds"
|
||||
end
|
||||
|
||||
desc "redeploy", "Deploy new version of the app to servers (without bootstrapping servers, starting Traefik, pruning, and registry login)"
|
||||
def redeploy
|
||||
print_runtime do
|
||||
runtime = print_runtime do
|
||||
say "Build and push app image...", :magenta
|
||||
invoke "mrsk:cli:build:deliver"
|
||||
|
||||
invoke "mrsk:cli:app:boot"
|
||||
end
|
||||
|
||||
audit_broadcast "Redeployed in #{runtime.to_i} seconds"
|
||||
end
|
||||
|
||||
desc "rollback [VERSION]", "Rollback the app to VERSION"
|
||||
@@ -51,6 +55,8 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
||||
execute *MRSK.app.stop, raise_on_non_zero_exit: false
|
||||
execute *MRSK.app.start
|
||||
end
|
||||
|
||||
audit_broadcast "Rolled back to version #{version}"
|
||||
end
|
||||
|
||||
desc "details", "Display details about Traefik and app containers"
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
require "active_support/core_ext/time/conversions"
|
||||
|
||||
class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
||||
# Runs remotely
|
||||
def record(line)
|
||||
append \
|
||||
[ :echo, tagged_line(line) ],
|
||||
audit_log_file
|
||||
end
|
||||
|
||||
# Runs locally
|
||||
def broadcast(line)
|
||||
if broadcast_cmd = config.audit_broadcast_cmd
|
||||
pipe \
|
||||
[ :echo, tagged_line(line) ],
|
||||
broadcast_cmd
|
||||
end
|
||||
end
|
||||
|
||||
def reveal
|
||||
[ :tail, "-n", 50, audit_log_file ]
|
||||
end
|
||||
@@ -21,14 +31,14 @@ class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
||||
end
|
||||
|
||||
def tags
|
||||
"[#{timestamp}] [#{performer}]"
|
||||
"[#{recorded_at}] [#{performer}]"
|
||||
end
|
||||
|
||||
def performer
|
||||
`whoami`.strip
|
||||
@performer ||= `whoami`.strip
|
||||
end
|
||||
|
||||
def timestamp
|
||||
def recorded_at
|
||||
Time.now.to_fs(:db)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -126,6 +126,10 @@ class Mrsk::Configuration
|
||||
{ user: ssh_user, proxy: ssh_proxy, auth_methods: [ "publickey" ] }.compact
|
||||
end
|
||||
|
||||
def audit_broadcast_cmd
|
||||
raw_config.audit_broadcast_cmd
|
||||
end
|
||||
|
||||
|
||||
def valid?
|
||||
ensure_required_keys_present && ensure_env_available
|
||||
|
||||
Reference in New Issue
Block a user