# syntax=docker/dockerfile:1
# Multi-stage build for the Astro Node-adapter SERVER build (standalone).
# No secrets are baked in — .env is supplied at runtime, never copied into the image.

# ---- build stage ----
FROM node:lts-slim AS build
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci
COPY . .
# Build-time PUBLIC_* client vars are baked into the bundle HERE (Astro inlines
# import.meta.env.PUBLIC_* at build). Declare each as ARG+ENV and pass it from CI
# (.github/workflows/deploy.yml build-args ← repo Variables — public, never secrets).
# BUILD_SHA just stamps the build. Add your own below, then wire the same name into
# deploy.yml. Runtime secrets stay in .env and are NEVER build args.
ARG BUILD_SHA=""
ENV BUILD_SHA=${BUILD_SHA}
# ARG PUBLIC_TURNSTILE_SITE_KEY=""
# ENV PUBLIC_TURNSTILE_SITE_KEY=${PUBLIC_TURNSTILE_SITE_KEY}
RUN npm run build

# ---- runtime stage ----
FROM node:lts-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production \
    HOST=0.0.0.0 \
    PORT=4321
COPY package.json package-lock.json* ./
RUN npm ci --omit=dev && npm cache clean --force
COPY --from=build /app/dist ./dist
USER node
EXPOSE 4321
CMD ["node", "./dist/server/entry.mjs"]
