diff --git a/lib/kamal/cli/main.rb b/lib/kamal/cli/main.rb index b1f54abab..4e3880442 100644 --- a/lib/kamal/cli/main.rb +++ b/lib/kamal/cli/main.rb @@ -6,6 +6,8 @@ def setup say "Ensure Docker is installed...", :magenta invoke "kamal:cli:server:bootstrap" + run_hook "docker-setup" + say "Push env files...", :magenta invoke "kamal:cli:env:push" 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/main_test.rb b/test/cli/main_test.rb index a19ff90e7..9df6b4b39 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -2,12 +2,17 @@ class CliMainTest < CliTestCase test "setup" do + invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false } + Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:server:bootstrap") Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:env:push") Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:boot", [ "all" ]) Kamal::Cli::Main.any_instance.expects(:deploy) + hook_variables = { version: 999, service_version: "app@999", hosts: "1.1.1.1,1.1.1.2", command: "setup" } - run_command("setup") + run_command("setup").tap do |output| + assert_hook_ran "docker-setup", output, **hook_variables + end end test "deploy" do 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 100644 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