Adds hooks to MRSK. Currently just two hooks, pre-build and post-push. We could break the build and push into two separate commands if we found the need for post-build and/or pre-push hooks. Hooks are stored in `.mrsk/hooks`. Running `mrsk init` will now create that folder and add sample hook scripts. Hooks returning non-zero exit codes will abort the current command. Further potential work here: - We could replace the audit broadcast command with a post-deploy/post-rollback hook or similar - Maybe provide pre-command/post-command hooks that run after every mrsk invocation - Also look for hooks in `~/.mrsk/hooks`
37 lines
847 B
Ruby
37 lines
847 B
Ruby
class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
|
attr_reader :details
|
|
|
|
def initialize(config, **details)
|
|
super(config)
|
|
@details = details
|
|
end
|
|
|
|
# Runs remotely
|
|
def record(line, **details)
|
|
append \
|
|
[ :echo, audit_tags(**details).except(:version).to_s, line ],
|
|
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
|
|
|
|
private
|
|
def audit_log_file
|
|
[ "mrsk", config.service, config.destination, "audit.log" ].compact.join("-")
|
|
end
|
|
|
|
def audit_tags(**details)
|
|
tags(**self.details, **details)
|
|
end
|
|
end
|