# BASE IMAGE # Using node:20-bullseye-slim as the base image for our Docker build FROM node:20-bullseye-slim AS base # Updating package lists and upgrading installed packages RUN apt-get update -y RUN apt-get upgrade -y # Installing git as it is commonly used for various build processes RUN apt-get install -y git # Installing a specific version of npm globally RUN npm i -g npm@latest # BUILD IMAGE # Creating a new build stage starting from the "base" stage FROM base AS builder # Setting the working directory inside the Docker container WORKDIR /codechat # Copying specific project files needed for installing dependencies COPY ./package.json ./tsconfig.json ./ # Installing npm packages defined in package.json RUN npm install # Copying source code, public files, documentation, and Prisma configuration COPY ./src ./src COPY ./public ./public COPY ./docs ./docs COPY ./prisma ./prisma COPY ./views ./views COPY ./.env ./.env # Copying scriptis to working directory. COPY ./scripts/ ./scripts # Execution permission RUN chmod +x ./scripts/* # Executing command RUN ./scripts/run_database_operation_deploy.sh # Running the build process defined in package.json RUN npm run build # RELEASE IMAGE # Creating a new stage for the release image starting from the "base" stage FROM base AS release # Setting the working directory WORKDIR /codechat # Copying package.json and package-lock.json from the "builder" stage COPY --from=builder /codechat/package.json ./package.json COPY --from=builder /codechat/package-lock.json ./package-lock.json # Installing only production dependencies RUN npm install --omit=dev # Copying built code and Prisma configuration from the "builder" stage COPY --from=builder /codechat/dist ./dist COPY --from=builder /codechat/prisma ./prisma COPY --from=builder /codechat/public ./public COPY --from=builder /codechat/docs ./docs COPY --from=builder /codechat/views ./views COPY --from=builder /codechat/.env ./.env COPY --from=builder /codechat/scripts ./scripts # Creating a directory for instances (purpose may vary depending on the application) RUN mkdir instances # Setting environment variables for the Docker container ENV DOCKER_ENV=true ENV NODE_ENV='production' # Executing command ENTRYPOINT ["/bin/bash", "-c", ". ./scripts/run_database_operation_generate.sh && npm run start:prod" ]