From 11a69be1f3d49b5b18a4eec885696b4dbb7b224e Mon Sep 17 00:00:00 2001 From: VineeTagarwaL-code Date: Sun, 6 Oct 2024 18:09:20 +0530 Subject: [PATCH] fix: docker fix --- Dockerfile | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index f76d0470..04abdac1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,55 @@ +# Base stage FROM node:20-alpine AS base WORKDIR /usr/src/app + +# Copy the .env file +COPY .env .env + +# Copy the necessary files COPY package*.json ./ COPY ./prisma ./prisma -RUN npm install && npx prisma generate +# Install dependencies +RUN npm install + +# Use the .env file for the Prisma client generation +RUN npx prisma generate --schema=./prisma/schema.prisma + +# Development stage FROM node:20-alpine AS development WORKDIR /usr/src/app COPY . . COPY --from=base /usr/src/app/node_modules ./node_modules CMD ["npm", "run", "dev:docker"] -# WIP +# Build stage FROM node:20-alpine AS build -ARG DATABASE_URL WORKDIR /usr/src/app COPY package*.json ./ -RUN npm install COPY . . -RUN DATABASE_URL=$DATABASE_URL npx prisma generate -RUN DATABASE_URL=$DATABASE_URL npm run build +# Copy .env file into the build stage +COPY --from=base /usr/src/app/.env .env + +# Install dependencies and generate Prisma client using the .env file +RUN npm install +RUN npx prisma generate --schema=./prisma/schema.prisma + +# Build the Next.js application +RUN npm run build + +# Production stage FROM node:20-alpine AS production WORKDIR /usr/src/app + +# Copy the necessary files from the build stage COPY --from=build /usr/src/app/.next ./.next COPY --from=build /usr/src/app/node_modules ./node_modules COPY --from=build /usr/src/app/public ./public COPY --from=build /usr/src/app/package.json ./package.json +COPY --from=build /usr/src/app/.env .env + +# Start the application with the .env file CMD ["npm", "run", "start"] EXPOSE 3000 \ No newline at end of file