infra: add persistent uploads volume and configure Caddy to serve static images

- Add named Docker volume `uploads` mounted at /app/public/uploads in app container
- Share same volume with Caddy at /srv/uploads for direct static file serving
- Add Caddy `handle /uploads/*` block so images bypass Next.js (standalone mode does not serve runtime public files)
- Create uploads directory with correct nextjs:nodejs ownership in Dockerfile
- Add mkdir safeguard in entrypoint.sh
This commit is contained in:
2026-05-18 17:53:30 +02:00
parent a8d4c158b8
commit b3097670c0
4 changed files with 11 additions and 0 deletions
+4
View File
@@ -1,3 +1,7 @@
localhost { localhost {
handle /uploads/* {
root * /srv
file_server
}
reverse_proxy app:3000 reverse_proxy app:3000
} }
+1
View File
@@ -31,6 +31,7 @@ COPY --from=builder /app/scripts ./scripts
COPY entrypoint.sh ./ COPY entrypoint.sh ./
RUN chmod +x entrypoint.sh RUN chmod +x entrypoint.sh
RUN apk add --no-cache postgresql-client openssl RUN apk add --no-cache postgresql-client openssl
RUN mkdir -p /app/public/uploads && chown nextjs:nodejs /app/public/uploads
USER nextjs USER nextjs
EXPOSE 3000 EXPOSE 3000
ENTRYPOINT ["./entrypoint.sh"] ENTRYPOINT ["./entrypoint.sh"]
+2
View File
@@ -1,6 +1,8 @@
#!/bin/sh #!/bin/sh
set -e set -e
mkdir -p /app/public/uploads
echo "Waiting for database..." echo "Waiting for database..."
until pg_isready -h db -p 5432 -U ecommerce; do until pg_isready -h db -p 5432 -U ecommerce; do
sleep 2 sleep 2
+4
View File
@@ -27,6 +27,8 @@ services:
DATABASE_URL: postgresql://ecommerce:ecommerce_password@db:5432/ecommerce DATABASE_URL: postgresql://ecommerce:ecommerce_password@db:5432/ecommerce
expose: expose:
- "3000" - "3000"
volumes:
- uploads:/app/public/uploads
mailpit: mailpit:
image: axllent/mailpit:latest image: axllent/mailpit:latest
@@ -44,6 +46,7 @@ services:
- ./Caddyfile:/etc/caddy/Caddyfile:ro - ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data - caddy_data:/data
- caddy_config:/config - caddy_config:/config
- uploads:/srv/uploads
depends_on: depends_on:
- app - app
@@ -51,3 +54,4 @@ volumes:
pgdata: pgdata:
caddy_data: caddy_data:
caddy_config: caddy_config:
uploads: