mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-13 05:15:21 +02:00
Share the self-signed Caddy CA/cert across worktrees (#211)
Each worktree previously bind-mounted its own frankenphp/data, so Caddy minted a fresh CA and cert per checkout and just trust-cert had to be re-run every time. Anchor CADDY_DATA_DIR at the shared .git common dir instead, so all worktrees of the same clone reuse one CA.
This commit is contained in:
@@ -4,11 +4,18 @@ set dotenv-filename := ".env.local"
|
|||||||
|
|
||||||
# Generate a per-worktree COMPOSE_PROJECT_NAME, IMAGES_PREFIX and free host ports in .env.local,
|
# Generate a per-worktree COMPOSE_PROJECT_NAME, IMAGES_PREFIX and free host ports in .env.local,
|
||||||
# so multiple worktrees/checkouts of this repo can run `just up` at the same time without their
|
# so multiple worktrees/checkouts of this repo can run `just up` at the same time without their
|
||||||
# containers, volumes, images or ports colliding. Safe to re-run; no-ops if already configured.
|
# containers, volumes, images or ports colliding. Also points CADDY_DATA_DIR at a location shared
|
||||||
|
# by all worktrees of the same clone, so they reuse one self-signed CA/cert instead of generating
|
||||||
|
# their own. Safe to re-run; no-ops if already configured.
|
||||||
init:
|
init:
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
if [ -f .env.local ] && grep -q '^COMPOSE_PROJECT_NAME=' .env.local; then
|
if [ -f .env.local ] && grep -q '^COMPOSE_PROJECT_NAME=' .env.local; then
|
||||||
|
if ! grep -q '^CADDY_DATA_DIR=' .env.local; then
|
||||||
|
git_common_dir=$(git rev-parse --path-format=absolute --git-common-dir)
|
||||||
|
echo "CADDY_DATA_DIR=${git_common_dir}/tvdt-caddy-data" >> .env.local
|
||||||
|
echo "Backfilled CADDY_DATA_DIR into existing .env.local."
|
||||||
|
fi
|
||||||
echo ".env.local already configured for this worktree, skipping (delete it to regenerate)."
|
echo ".env.local already configured for this worktree, skipping (delete it to regenerate)."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@@ -39,6 +46,11 @@ init:
|
|||||||
postgres_port=$(free_port 5430 5529)
|
postgres_port=$(free_port 5430 5529)
|
||||||
mailpit_port=$(free_port 8025 8124)
|
mailpit_port=$(free_port 8025 8124)
|
||||||
spotlight_port=$(free_port 8969 9068)
|
spotlight_port=$(free_port 8969 9068)
|
||||||
|
# .git is shared by all worktrees of the same clone, so anchoring the Caddy data dir
|
||||||
|
# (self-signed CA + TLS certs) there instead of under the worktree lets every worktree
|
||||||
|
# reuse the same CA, avoiding a fresh cert (and a fresh `just trust-cert`) per checkout.
|
||||||
|
git_common_dir=$(git rev-parse --path-format=absolute --git-common-dir)
|
||||||
|
caddy_data_dir="${git_common_dir}/tvdt-caddy-data"
|
||||||
{
|
{
|
||||||
echo "COMPOSE_PROJECT_NAME=${project}"
|
echo "COMPOSE_PROJECT_NAME=${project}"
|
||||||
echo "IMAGES_PREFIX=${project}-"
|
echo "IMAGES_PREFIX=${project}-"
|
||||||
@@ -47,6 +59,7 @@ init:
|
|||||||
echo "POSTGRES_PORT=${postgres_port}"
|
echo "POSTGRES_PORT=${postgres_port}"
|
||||||
echo "MAILPIT_PORT=${mailpit_port}"
|
echo "MAILPIT_PORT=${mailpit_port}"
|
||||||
echo "SPOTLIGHT_PORT=${spotlight_port}"
|
echo "SPOTLIGHT_PORT=${spotlight_port}"
|
||||||
|
echo "CADDY_DATA_DIR=${caddy_data_dir}"
|
||||||
} >> .env.local
|
} >> .env.local
|
||||||
echo "Generated .env.local for this worktree:"
|
echo "Generated .env.local for this worktree:"
|
||||||
cat .env.local
|
cat .env.local
|
||||||
@@ -138,8 +151,13 @@ install-hooks:
|
|||||||
chmod +x .githooks/pre-commit
|
chmod +x .githooks/pre-commit
|
||||||
@echo "Pre-commit hook installed."
|
@echo "Pre-commit hook installed."
|
||||||
|
|
||||||
trust-cert:
|
trust-cert: init
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
set -a
|
||||||
|
source .env.local
|
||||||
|
set +a
|
||||||
sudo security add-trusted-cer -d \
|
sudo security add-trusted-cer -d \
|
||||||
-r trustRoot \
|
-r trustRoot \
|
||||||
-k "$HOME/Library/Keychains/login.keychain" \
|
-k "$HOME/Library/Keychains/login.keychain" \
|
||||||
./frankenphp/data/caddy/pki/authorities/local/root.crt
|
"${CADDY_DATA_DIR:-./frankenphp/data}/caddy/pki/authorities/local/root.crt"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ services:
|
|||||||
- ~/.composer/cache:/root/.composer/cache
|
- ~/.composer/cache:/root/.composer/cache
|
||||||
- ./frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
|
- ./frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
|
||||||
- ./frankenphp/conf.d/20-app.dev.ini:/usr/local/etc/php/app.conf.d/20-app.dev.ini:ro
|
- ./frankenphp/conf.d/20-app.dev.ini:/usr/local/etc/php/app.conf.d/20-app.dev.ini:ro
|
||||||
- ./frankenphp/data:/data
|
- ${CADDY_DATA_DIR:-./frankenphp/data}:/data
|
||||||
- sass:/app/var/sass
|
- sass:/app/var/sass
|
||||||
environment:
|
environment:
|
||||||
MERCURE_EXTRA_DIRECTIVES: demo
|
MERCURE_EXTRA_DIRECTIVES: demo
|
||||||
|
|||||||
Reference in New Issue
Block a user