diff --git a/lib/kamal/cli/server.rb b/lib/kamal/cli/server.rb index 6dcc6b02d..e4d270f35 100644 --- a/lib/kamal/cli/server.rb +++ b/lib/kamal/cli/server.rb @@ -19,5 +19,7 @@ def bootstrap if missing.any? raise "Docker is not installed on #{missing.join(", ")} and can't be automatically installed without having root access and the `curl` command available. Install Docker manually: https://docs.docker.com/engine/install/" end + + run_hook "docker-setup" end end diff --git a/lib/kamal/cli/templates/sample_hooks/docker-setup.sample b/lib/kamal/cli/templates/sample_hooks/docker-setup.sample new file mode 100644 index 000000000..fe68b9373 --- /dev/null +++ b/lib/kamal/cli/templates/sample_hooks/docker-setup.sample @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +# A sample docker-setup hook +# +# Sets up a Docker network which can then be used by the application’s containers + +ssh user@example.com docker network create kamal diff --git a/test/cli/server_test.rb b/test/cli/server_test.rb index 1c8a2607d..04cdc3121 100644 --- a/test/cli/server_test.rb +++ b/test/cli/server_test.rb @@ -23,10 +23,13 @@ class CliServerTest < CliTestCase SSHKit::Backend::Abstract.any_instance.expects(:execute).with('[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null', raise_on_non_zero_exit: false).returns(true).at_least_once SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:curl, "-fsSL", "https://get.docker.com", "|", :sh).at_least_once SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once + Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true) + SSHKit::Backend::Abstract.any_instance.expects(:execute).with(".kamal/hooks/docker-setup", anything).at_least_once run_command("bootstrap").tap do |output| ("1.1.1.1".."1.1.1.4").map do |host| assert_match "Missing Docker on #{host}. Installing…", output + assert_match "Running the docker-setup hook", output end end end diff --git a/test/integration/docker/deployer/app/.kamal/hooks/docker-setup b/test/integration/docker/deployer/app/.kamal/hooks/docker-setup new file mode 100755 index 000000000..2c218dc58 --- /dev/null +++ b/test/integration/docker/deployer/app/.kamal/hooks/docker-setup @@ -0,0 +1,3 @@ +#!/bin/sh +echo "Docker set up!" +mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/docker-setup