sightbox/generate-dokploy-compose.sh

57 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Regenerates docker-compose.dokploy.yml from docker-compose.yml.
#
# Why this exists: Dokploy's own compose validator doesn't support the
# top-level `include:` directive docker-compose.yml relies on to pull in
# frappe_docker's compose files without duplicating them (confirmed against
# a real deploy — "validating ...: (root) Additional property include is
# not allowed" — and matches two open, unresolved Dokploy feature requests:
# https://github.com/Dokploy/dokploy/issues/3116 (include support) and
# https://github.com/Dokploy/dokploy/issues/1727 (multiple compose files).
# Neither is implemented as of writing, so Dokploy needs one flat file with
# no `include:` — this script produces exactly that.
#
# --no-interpolate is the deliberate, load-bearing flag here: it resolves
# and flattens `include:` (merging in every frappe_docker file it
# references) while leaving every ${VAR} reference as a literal string
# instead of substituting today's local values into the committed file.
# Without it, this file would bake in whatever's in the machine's .env at
# generation time — including things like FRAPPE_IMAGE_PLATFORM=linux/arm64
# on an Apple Silicon dev machine — permanently, defeating the entire point
# of Dokploy's own Environment tab controlling these per deployment.
#
# --no-path-resolution is equally load-bearing: without it, Compose
# resolves every relative path (`./backend`, `./bettersightbox-index.html`,
# `./backend/tenants.json`, `./backend/.env`) to an *absolute* path on
# whatever machine generates the file — confirmed by generating this once
# without the flag and finding the generating machine's own home directory
# baked into backend-billing's build context. The flag keeps them relative,
# which is what actually works once Dokploy clones this repo to its own,
# different path on the VPS.
#
# Usage: ./generate-dokploy-compose.sh
# Run this any time docker-compose.yml changes, or any time frappe_docker
# is repointed at a different pinned commit (see .gitmodules) — this file
# is generated output, never hand-edited.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
OUT="docker-compose.dokploy.yml"
{
echo "# GENERATED FILE — do not edit by hand."
echo "# Produced by ./generate-dokploy-compose.sh from docker-compose.yml + the"
echo "# frappe_docker files it includes. Regenerate after changing either."
echo "# This is what Dokploy's Compose Path should point to — not"
echo "# docker-compose.yml itself, which Dokploy's validator rejects (see"
echo "# this script's own header comment for why)."
echo "#"
docker compose -f docker-compose.yml config --no-interpolate --no-path-resolution
} > "$OUT"
echo "Wrote ${OUT}."
echo "Set Dokploy's Compose Path to ./${OUT}, not ./docker-compose.yml, and redeploy."