#!/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. # # A second, separate Dokploy validator limitation, also confirmed on a real # deploy: it rejects Compose's long-form `env_file` entries too — # `services.backend-billing.env_file.0 must be a string` — because # `docker compose config` always expands `env_file: [./backend/.env]` to # the long form (`- path: ./backend/.env` / `required: true`) in its output, # with no flag to suppress it (checked: --no-normalize doesn't affect this # either). The Python filter below collapses that structure back to the # plain string form, for every service, not just backend-billing — safe to # do broadly, since the short form already implies "must exist", the exact # behavior `required: true` spells out. Left alone: `depends_on`'s own, # unrelated `required:` field (a different Compose feature entirely, and # not something Dokploy's validator objects to), which this filter's regex # only matches directly beneath a `- path:` line, not there. # # 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 \ | python3 -c " import sys, re text = sys.stdin.read() pattern = re.compile(r'^(\s*)- path: (.+)\n\s*required: (?:true|false)\s*\$', re.MULTILINE) text = pattern.sub(lambda m: f'{m.group(1)}- {m.group(2)}', text) sys.stdout.write(text) " } > "$OUT" echo "Wrote ${OUT}." echo "Set Dokploy's Compose Path to ./${OUT}, not ./docker-compose.yml, and redeploy."