FROM node:24.5.0-slim AS builder

RUN apt-get update && apt-get install -y python3 python3-pip sqlite3 && rm -rf /var/lib/apt/lists/*

WORKDIR /home/gooseek

COPY package.json package-lock.json ./
COPY apps/frontend/package.json ./apps/frontend/
COPY apps/shared-types/package.json ./apps/shared-types/
COPY apps/shared-utils/package.json ./apps/shared-utils/

RUN npm install

COPY apps ./apps

RUN mkdir -p /home/gooseek/apps/frontend/data
ENV DATA_DIR=/home/gooseek/apps/frontend
RUN npm run build

FROM node:24.5.0-slim

RUN apt-get update && apt-get install -y python3 python3-pip sqlite3 && rm -rf /var/lib/apt/lists/*

WORKDIR /home/gooseek

COPY --from=builder /home/gooseek/apps/frontend/public ./public
COPY --from=builder /home/gooseek/apps/frontend/.next/static ./public/_next/static
COPY --from=builder /home/gooseek/apps/frontend/.next/standalone ./
COPY --from=builder /home/gooseek/apps/frontend/drizzle ./drizzle

RUN mkdir -p /home/gooseek/data /home/gooseek/uploads

EXPOSE 3000

ENV DATA_DIR=/home/gooseek

CMD ["node", "server.js"]
