# Standalone frontend Dockerfile (when building from repo root context)
# For CapRover, use the root-level Dockerfile.frontend instead.
# This is for: docker build -t thegrind-web -f frontend/Dockerfile .
# (run from repo root)

FROM node:20-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /build
COPY shared/package.json ./shared/
COPY shared/tsconfig.json ./shared/
COPY shared/src/ ./shared/src/
COPY frontend/package*.json ./frontend/
WORKDIR /build/frontend
RUN npm install --legacy-peer-deps

FROM node:20-alpine AS builder
RUN apk add --no-cache libc6-compat
WORKDIR /build
COPY --from=deps /build/shared ./shared
COPY --from=deps /build/frontend/node_modules ./frontend/node_modules
COPY frontend/ ./frontend/
COPY shared/ ./shared/
WORKDIR /build/frontend
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build

FROM node:20-alpine
RUN apk add --no-cache libc6-compat tini
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
COPY --from=builder /build/frontend/.next/standalone ./
COPY --from=builder /build/frontend/.next/static ./.next/static
COPY --from=builder /build/frontend/public ./public
EXPOSE 3000
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "server.js"]