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`
62 lines
1.5 KiB
Ruby
62 lines
1.5 KiB
Ruby
module Mrsk::Commands
|
|
class Base
|
|
delegate :sensitive, :argumentize, to: Mrsk::Utils
|
|
|
|
DOCKER_HEALTH_STATUS_FORMAT = "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'"
|
|
DOCKER_HEALTH_LOG_FORMAT = "'{{json .State.Health}}'"
|
|
|
|
attr_accessor :config
|
|
|
|
def initialize(config)
|
|
@config = config
|
|
end
|
|
|
|
def run_over_ssh(*command, host:)
|
|
"ssh".tap do |cmd|
|
|
cmd << " -J #{config.ssh_proxy.jump_proxies}" if config.ssh_proxy
|
|
cmd << " -t #{config.ssh_user}@#{host} '#{command.join(" ")}'"
|
|
end
|
|
end
|
|
|
|
def container_id_for(container_name:, only_running: false)
|
|
docker :container, :ls, *("--all" unless only_running), "--filter", "name=^#{container_name}$", "--quiet"
|
|
end
|
|
|
|
private
|
|
def combine(*commands, by: "&&")
|
|
commands
|
|
.compact
|
|
.collect { |command| Array(command) + [ by ] }.flatten # Join commands
|
|
.tap { |commands| commands.pop } # Remove trailing combiner
|
|
end
|
|
|
|
def chain(*commands)
|
|
combine *commands, by: ";"
|
|
end
|
|
|
|
def pipe(*commands)
|
|
combine *commands, by: "|"
|
|
end
|
|
|
|
def append(*commands)
|
|
combine *commands, by: ">>"
|
|
end
|
|
|
|
def write(*commands)
|
|
combine *commands, by: ">"
|
|
end
|
|
|
|
def xargs(command)
|
|
[ :xargs, command ].flatten
|
|
end
|
|
|
|
def docker(*args)
|
|
args.compact.unshift :docker
|
|
end
|
|
|
|
def tags(**details)
|
|
Mrsk::Tags.from_config(config, **details)
|
|
end
|
|
end
|
|
end
|