# syntax=docker/dockerfile:1

FROM node:20-bookworm-slim

WORKDIR /app

ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV HUSKY=0

COPY package.json package-lock.json ./

RUN npm ci --no-audit --no-fund

COPY drizzle.config.* ./
COPY drizzle ./drizzle
COPY src ./src
COPY scripts ./scripts
COPY tsconfig.json ./

CMD ["sh", "-c", "\
    set -e; \
    echo 'Running database migrations...'; \
    npm run migrate; \
    echo 'Running master-data seed...'; \
    npm run seed:master-data; \
    echo 'Running super-admin seed...'; \
    npm run seed:super-admin; \
    echo 'Migration and seeds completed successfully'; \
    tail -f /dev/null \
    "]