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 18, 2023
1 parent da16144 commit 4ffe216
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/kamal/cli/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
2 changes: 2 additions & 0 deletions test/cli/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ 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
hook_variables = { version: 999, service_version: "app@999", hosts: "1.1.1.1,1.1.1.2,1.1.1.3,1.1.1.4", command: "setup" }

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_hook_ran "docker-setup", output, **hook_variables
end
end
end
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 4ffe216

Please sign in to comment.