# First stage: Build the application
FROM node:22-alpine AS deps
ENV DEBIAN_FRONTEND=noninteractive
# Set the working directory
WORKDIR /app
# Install build dependencies
COPY [Link] [Link] ./
# Install dependencies
RUN yarn install --frozen-lockfile --non-interactive && rm -rf /root/.cache
# Second stage: Build the application
FROM node:22-alpine AS build
ENV DEBIAN_FRONTEND=noninteractive
# Set the working directory
WORKDIR /app
# Copy the necessary files from the build stage
COPY --from=deps /app/node_modules ./node_modules
# Copy the rest of the application code
COPY . .
# Install dependencies, build the application, and clean up
RUN yarn global add typescript && yarn run build && rm -rf /app/src /root/.cache
# Third stage: Run the application
FROM node:22-alpine AS runtime
# Set the working directory
WORKDIR /app
# Install PM2 globally and clean up
RUN yarn global add pm2@latest && rm -rf /root/.cache
RUN mkdir -p logs
# Copy only the necessary files from the build stage
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/[Link] ./[Link]
COPY --from=build /app/[Link] ./[Link]
# Expose the port the app will run on
EXPOSE 8000
# Use PM2 to start the application in cluster mode
CMD ["yarn", "start"]