Skip to content

Commit

Permalink
Add docker-setup hook
Browse files Browse the repository at this point in the history
This allows the user to make any necessary configuration changes to
Docker before setting up any containers, allowing those configuration
changes to take effect from the outset.
  • Loading branch information
tsvallender committed Nov 14, 2023
1 parent da16144 commit fdaa3a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/kamal/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 7 additions & 0 deletions lib/kamal/cli/templates/sample_hooks/docker-setup.sample
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion test/cli/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
echo "Docker set up!"
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/docker-setup

0 comments on commit fdaa3a3

Please sign in to comment.