# 1.- Builder
FROM node:24.19.0-alpine AS builder

WORKDIR /app

COPY package.json package-lock.json astro.config.mjs tsconfig.json ./
COPY src ./src
COPY public ./public

# RUN npm install -g npm@12.0.2
RUN npm install
RUN npm run build

# 2.- Runtime
FROM node:24.19.0-alpine AS runner

WORKDIR /app

# Only copy necessary files
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodejs -u 1001
USER nodejs

EXPOSE 4321

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