Switch from Caddy templates to runtime envsubst for API and Keycloak URLs, adjust Dockerfile and entrypoint script
Build and Publish Docker Images / build-and-push (., backend/infrastructure/gateway/Dockerfile, api-gateway, api-gateway) (push) Successful in 8m31s
Build and Publish Docker Images / build-and-push (., backend/services/ping/Dockerfile, ping-service, ping-service) (push) Successful in 7m20s
Build and Publish Docker Images / build-and-push (., config/docker/caddy/web-app/Dockerfile, web-app, web-app) (push) Successful in 2m1s
Build and Publish Docker Images / build-and-push (., config/docker/keycloak/Dockerfile, keycloak, keycloak) (push) Successful in 1m39s

This commit is contained in:
2026-03-14 22:14:21 +01:00
parent a202d3d817
commit a1bc7039cb
4 changed files with 27 additions and 13 deletions
-4
View File
@@ -17,10 +17,6 @@
encode gzip zstd encode gzip zstd
templates {
mime text/html application/json
}
handle /api/* { handle /api/* {
reverse_proxy api-gateway:8081 reverse_proxy api-gateway:8081
} }
+9 -1
View File
@@ -13,6 +13,9 @@ ARG BUILD_DATE
# =================================================================== # ===================================================================
FROM caddy:${CADDY_VERSION} FROM caddy:${CADDY_VERSION}
# envsubst für Env-Var-Substitution zur Laufzeit
RUN apk add --no-cache gettext
ARG VERSION ARG VERSION
ARG BUILD_DATE ARG BUILD_DATE
@@ -21,13 +24,17 @@ LABEL service="web-app" \
maintainer="Meldestelle Development Team" \ maintainer="Meldestelle Development Team" \
build.date="${BUILD_DATE}" build.date="${BUILD_DATE}"
# Copy Caddy Config & Templates # Copy Caddy Config & Entrypoint
COPY config/docker/caddy/web-app/Caddyfile /etc/caddy/Caddyfile COPY config/docker/caddy/web-app/Caddyfile /etc/caddy/Caddyfile
COPY config/docker/caddy/web-app/config.json /usr/share/caddy/config.json COPY config/docker/caddy/web-app/config.json /usr/share/caddy/config.json
COPY config/docker/caddy/web-app/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Copy Pre-built Static Assets from Host # Copy Pre-built Static Assets from Host
# NOTE: You must run `./gradlew :frontend:shells:meldestelle-portal:jsBrowserDistribution -Pproduction=true` locally first! # NOTE: You must run `./gradlew :frontend:shells:meldestelle-portal:jsBrowserDistribution -Pproduction=true` locally first!
COPY frontend/shells/meldestelle-portal/build/dist/js/productionExecutable/ /usr/share/caddy/ COPY frontend/shells/meldestelle-portal/build/dist/js/productionExecutable/ /usr/share/caddy/
# index.html wird als Template abgelegt; der Entrypoint erzeugt daraus zur Laufzeit die finale index.html
RUN mv /usr/share/caddy/index.html /usr/share/caddy/index.html.tmpl
# Ensure favicon exists (fallback) # Ensure favicon exists (fallback)
# Using the shared asset from existing config structure # Using the shared asset from existing config structure
@@ -38,4 +45,5 @@ EXPOSE 4000
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:4000/health || exit 1 CMD wget --no-verbose --tries=1 --spider http://localhost:4000/health || exit 1
ENTRYPOINT ["/entrypoint.sh"]
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"] CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
+10
View File
@@ -0,0 +1,10 @@
#!/bin/sh
set -e
# Ersetze ${API_BASE_URL} und ${KEYCLOAK_URL} in index.html zur Container-Startzeit.
# Caddy bekommt eine fertige, statische HTML-Datei — kein Template-Parsing mehr nötig.
envsubst '${API_BASE_URL} ${KEYCLOAK_URL}' \
< /usr/share/caddy/index.html.tmpl \
> /usr/share/caddy/index.html
exec "$@"
@@ -14,13 +14,13 @@
</div> </div>
<!-- <!--
Schritt 1: Caddy füllt dieses JSON-Template aus. Schritt 1: Der Container-Entrypoint ersetzt ${API_BASE_URL} und ${KEYCLOAK_URL}
Der Inhalt ist reines JSON, was Syntaxkonflikte mit JS vermeidet. via envsubst beim Start. Caddy bekommt eine fertige statische Datei ohne Template-Parsing.
--> -->
<script id="app-config" type="application/json"> <script id="app-config" type="application/json">
{ {
"apiBaseUrl": "{{.Env.API_BASE_URL}}", "apiBaseUrl": "${API_BASE_URL}",
"keycloakUrl": "{{.Env.KEYCLOAK_URL}}" "keycloakUrl": "${KEYCLOAK_URL}"
} }
</script> </script>
@@ -33,20 +33,20 @@
const config = JSON.parse(configJson); const config = JSON.parse(configJson);
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
const tmplPrefix = '{' + '{'; // Verhindert, dass Caddy '{{' als Template-Action interpretiert const notReplaced = '${'; // Fallback-Erkennung: envsubst hat den Wert NICHT ersetzt
const apiFromCaddy = config.apiBaseUrl; const apiFromCaddy = config.apiBaseUrl;
const apiOverride = params.get('apiBaseUrl'); const apiOverride = params.get('apiBaseUrl');
globalThis.API_BASE_URL = apiOverride globalThis.API_BASE_URL = apiOverride
? apiOverride.replace(/\/$/, '') ? apiOverride.replace(/\/$/, '')
: (apiFromCaddy && !apiFromCaddy.startsWith(tmplPrefix) : (apiFromCaddy && !apiFromCaddy.startsWith(notReplaced)
? apiFromCaddy.replace(/\/$/, '') ? apiFromCaddy.replace(/\/$/, '')
: 'http://' + window.location.origin.replace(/\/$/, '')); : 'http://' + window.location.hostname + ':8081');
const kcFromCaddy = config.keycloakUrl; const kcFromCaddy = config.keycloakUrl;
const kcOverride = params.get('keycloakUrl'); const kcOverride = params.get('keycloakUrl');
globalThis.KEYCLOAK_URL = kcOverride globalThis.KEYCLOAK_URL = kcOverride
? kcOverride.replace(/\/$/, '') ? kcOverride.replace(/\/$/, '')
: (kcFromCaddy && !kcFromCaddy.startsWith(tmplPrefix) : (kcFromCaddy && !kcFromCaddy.startsWith(notReplaced)
? kcFromCaddy.replace(/\/$/, '') ? kcFromCaddy.replace(/\/$/, '')
: 'http://' + window.location.hostname + ':8180'); : 'http://' + window.location.hostname + ':8180');