MRSK hooks
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`
This commit is contained in:
@@ -17,6 +17,8 @@ services:
|
||||
privileged: true
|
||||
build:
|
||||
context: docker/deployer
|
||||
environment:
|
||||
- TEST_ID=${TEST_ID}
|
||||
volumes:
|
||||
- ../..:/mrsk
|
||||
- shared:/shared
|
||||
|
||||
3
test/integration/docker/deployer/app/.mrsk/hooks/post-push
Executable file
3
test/integration/docker/deployer/app/.mrsk/hooks/post-push
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
echo "Built and pushed!"
|
||||
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/post-push
|
||||
3
test/integration/docker/deployer/app/.mrsk/hooks/pre-build
Executable file
3
test/integration/docker/deployer/app/.mrsk/hooks/pre-build
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
echo "About to build and push..."
|
||||
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-build
|
||||
@@ -3,6 +3,7 @@ require "test_helper"
|
||||
|
||||
class IntegrationTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
ENV["TEST_ID"] = SecureRandom.hex
|
||||
docker_compose "up --build -d"
|
||||
wait_for_healthy
|
||||
setup_deployer
|
||||
@@ -14,7 +15,7 @@ class IntegrationTest < ActiveSupport::TestCase
|
||||
|
||||
private
|
||||
def docker_compose(*commands, capture: false, raise_on_error: true)
|
||||
command = "docker compose #{commands.join(" ")}"
|
||||
command = "TEST_ID=#{ENV["TEST_ID"]} docker compose #{commands.join(" ")}"
|
||||
succeeded = false
|
||||
if capture
|
||||
result = stdouted { succeeded = system("cd test/integration && #{command}") }
|
||||
@@ -82,6 +83,13 @@ class IntegrationTest < ActiveSupport::TestCase
|
||||
assert_equal version, response.body.strip
|
||||
end
|
||||
|
||||
def assert_hooks_ran
|
||||
[ "pre-build", "post-push" ].each do |hook|
|
||||
file = "/tmp/#{ENV["TEST_ID"]}/#{hook}"
|
||||
assert_match /File: #{file}/, deployer_exec("stat #{file}", capture: true)
|
||||
end
|
||||
end
|
||||
|
||||
def wait_for_healthy(timeout: 20)
|
||||
timeout_at = Time.now + timeout
|
||||
while docker_compose("ps -a | tail -n +2 | grep -v '(healthy)' | wc -l", capture: true) != "0"
|
||||
|
||||
@@ -8,6 +8,8 @@ class MainTest < IntegrationTest
|
||||
|
||||
mrsk :deploy
|
||||
|
||||
assert_hooks_ran
|
||||
|
||||
assert_app_is_up version: first_version
|
||||
|
||||
second_version = update_app_rev
|
||||
|
||||
Reference in New Issue
Block a user