FROM node:20-alpine

RUN apk add --no-cache git bash build-base curl

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .

# Buat config agar Next tahu output: export
RUN echo "const config = { output: 'export', images: { unoptimized: true } }; export default config;" > next.config.mjs

# Build project (Next.js 15 otomatis static export)
RUN NEXT_DISABLE_TURBOPACK=1 npx next build

# Copy static assets dan hasil build agar bisa diakses
RUN mkdir -p .next/server/app/_next && \
    cp -r .next/static .next/server/app/_next/static && \
    cp -r public/* .next/server/app/

EXPOSE 3000

CMD ["npx", "serve", ".next/server/app", "-l", "3000"]