FROM node:24.4-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN npm install -g pnpm@10.22.0

FROM base AS build
COPY . /usr/src/app
WORKDIR /usr/src/app

# Install dependencies
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --filter=./apps/website --frozen-lockfile

# Deploy only the dokploy app

ENV NODE_ENV=production
RUN pnpm --filter=./apps/website run build
RUN pnpm --filter=./apps/website --prod deploy --legacy /prod/website

RUN cp -R /usr/src/app/apps/website/.next /prod/website/.next

FROM base AS dokploy
WORKDIR /app

# Set production
ENV NODE_ENV=production

# Copy only the necessary files
COPY --from=build /prod/website/.next ./.next
COPY --from=build /prod/website/public ./public
COPY --from=build /prod/website/package.json ./package.json
COPY --from=build /prod/website/node_modules ./node_modules

EXPOSE 3000
CMD HOSTNAME=0.0.0.0 && pnpm start