# Build de production Astro SSR (adapter node standalone).
# Multi-stage : on compile dans une image lourde, on ne garde que le runtime.

# ---- Stage 1 : build ----
FROM node:22-alpine AS build
WORKDIR /app

# Dependances (cache : ne se reinstalle que si package*.json change)
COPY package.json package-lock.json* ./
RUN npm ci

# Source + build
COPY astro.config.mjs ./
COPY tsconfig.json* ./
COPY src ./src
COPY public ./public
RUN npm run build

# ---- Stage 2 : runtime ----
FROM node:22-alpine AS runtime
WORKDIR /app

ENV NODE_ENV=production
# Le serveur standalone @astrojs/node lit HOST et PORT
ENV HOST=0.0.0.0
ENV PORT=4321

# Toutes les deps du projet sont des "dependencies" (pas de devDependencies),
# le runtime SSR en a besoin (@astrojs/node, @directus/sdk).
COPY package.json package-lock.json* ./
RUN npm ci --omit=dev && npm cache clean --force

# Artefact compile uniquement
COPY --from=build /app/dist ./dist

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