Skip to content

Commit 3c12d5a

Browse files
fix(docker): fix Caddy crash when VDS_DOMAIN is empty
Generate Caddyfile from template in entrypoint, avoid empty email/site placeholders, and use curl.exe on Windows for health checks. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3f3137c commit 3c12d5a

6 files changed

Lines changed: 39 additions & 14 deletions

File tree

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
# VDS_DOMAIN — public hostname (e.g. vds.example.com). Leave empty for local HTTP on :80.
2-
# ACME_EMAIL — optional; Let's Encrypt expiry notices when VDS_DOMAIN is set.
3-
# Certificates persist in the caddy-data volume (/data).
1+
# Generated at container start from VDS_DOMAIN (see docker-entrypoint.sh).
2+
# @SITE@ is :80 for local HTTP, or your public hostname for automatic HTTPS.
43

5-
{
6-
email {$ACME_EMAIL}
7-
}
8-
9-
{$VDS_DOMAIN::80} {
4+
@SITE@ {
105
root * /srv
116
encode gzip zstd
127

frontend/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ COPY . .
99
RUN npm run build
1010

1111
FROM ${CADDY_IMAGE}
12+
RUN apk add --no-cache curl
1213
COPY --from=build /app/dist /srv
13-
COPY Caddyfile /etc/caddy/Caddyfile
14+
COPY Caddyfile.template /etc/caddy/Caddyfile.template
15+
COPY email.caddy /etc/caddy/email.caddy
16+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
17+
RUN sed -i 's/\r$//' /usr/local/bin/docker-entrypoint.sh \
18+
&& chmod +x /usr/local/bin/docker-entrypoint.sh
1419
EXPOSE 80 443 443/udp
20+
ENTRYPOINT ["docker-entrypoint.sh"]

frontend/docker-entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ -z "${VDS_DOMAIN:-}" ]; then
5+
SITE=":80"
6+
else
7+
SITE="$VDS_DOMAIN"
8+
fi
9+
10+
sed "s|@SITE@|${SITE}|g" /etc/caddy/Caddyfile.template > /etc/caddy/Caddyfile
11+
12+
if [ -n "${ACME_EMAIL:-}" ]; then
13+
exec caddy run \
14+
--config /etc/caddy/email.caddy \
15+
--config /etc/caddy/Caddyfile \
16+
--adapter caddyfile
17+
fi
18+
19+
exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

frontend/email.caddy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
email {$ACME_EMAIL}
3+
}

scripts/run-in-docker.cmd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ echo Waiting for %URL% ...
4040

4141
set /a ATTEMPTS=90
4242
:waitLoop
43-
curl -fsS -o nul -m 3 "%URL%" 2>nul
43+
curl.exe -fsS -o nul -m 3 "%URL%" 2>nul
4444
if not errorlevel 1 goto ready
4545
set /a ATTEMPTS-=1
4646
if %ATTEMPTS% LEQ 0 goto timeout
@@ -53,5 +53,7 @@ if "%NO_OPEN%"=="0" start "" "%URL%"
5353
exit /b 0
5454

5555
:timeout
56-
echo Timed out waiting for the UI. Check: docker compose logs -f >&2
56+
echo Timed out waiting for the UI at %URL%. >&2
57+
docker compose ps >&2
58+
docker compose logs frontend --tail 15 >&2
5759
exit /b 1

scripts/run-in-docker.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ done
5050

5151
if [[ "$ready" -ne 1 ]]; then
5252
echo "Timed out waiting for the UI at ${URL}." >&2
53+
docker compose ps >&2 || true
54+
docker compose logs frontend --tail 15 >&2 || true
5355
if [[ "$URL" == https://* ]]; then
54-
echo "For HTTPS: confirm VDS_DOMAIN DNS, ports 80/443 open, and: docker compose logs -f frontend" >&2
55-
else
56-
echo "Check: docker compose logs -f" >&2
56+
echo "For HTTPS: confirm VDS_DOMAIN DNS and ports 80/443 open." >&2
5757
fi
5858
exit 1
5959
fi

0 commit comments

Comments
 (0)