FROM node:23.5.0-alpine

ENV PORT=4000
ENV NODE_ENV=production
ENV NODE_OPTIONS="--max-old-space-size=4096"

RUN apk add --no-cache \
    python3 \
    make \
    g++ \
    git \
    sqlite-dev

WORKDIR /usr/src/app

# Copy dependency files
COPY package.json package-lock.json ./

# Install dependencies
RUN npm install

# Copy source code
COPY . .

# Init DB (aman karena pakai || true)
# RUN mkdir -p ./lib/db
# RUN node scripts/init-db.js || true

# Build Next.js
RUN npm run build

EXPOSE 4000

CMD ["npm", "run", "start"]
