# syntax=docker/dockerfile:1

# ---------------------------------------------------------------- Build ----
FROM node:24-alpine AS build
WORKDIR /app

# Erst nur die Manifeste kopieren: solange sich die Dependencies nicht
# aendern, bleibt der npm-ci-Layer im Cache.
COPY package.json package-lock.json ./
RUN npm ci

COPY . .
ENV ASTRO_TELEMETRY_DISABLED=1
RUN npm run build

# -------------------------------------------------------------- Runtime ----
FROM node:24-alpine AS runtime
WORKDIR /app

ENV NODE_ENV=production \
    HOST=0.0.0.0 \
    PORT=4321 \
    ASTRO_TELEMETRY_DISABLED=1

# Nur Laufzeit-Abhaengigkeiten. Tailwind, sharp & Co. stehen in
# devDependencies und landen damit nicht im finalen Image.
COPY package.json package-lock.json ./
RUN npm ci --omit=dev --omit=optional && npm cache clean --force

COPY --from=build /app/dist ./dist

USER node
EXPOSE 4321

HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
  CMD node -e "fetch('http://127.0.0.1:4321/').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"

CMD ["node", "./dist/server/entry.mjs"]
