diff --git a/ganesh/Dockerfile b/ganesh/Dockerfile index 8771f84..7a62f84 100644 --- a/ganesh/Dockerfile +++ b/ganesh/Dockerfile @@ -1,14 +1,41 @@ -FROM --platform=linux/amd64 node:20 +# Use the official Node.js image +FROM --platform=linux/amd64 node:20-alpine AS builder +# Set working directory inside the container WORKDIR /app +# Copy package.json and package-lock.json COPY package*.json ./ -RUN npm install +# Install dependencies +RUN npm install --frozen-lockfile + +# Copy the entire project COPY . . +# Generate Prisma client RUN npx prisma generate +# Build Next.js app +RUN npm run build + +# Create a lightweight production image +FROM --platform=linux/amd64 node:20-alpine AS runner + +WORKDIR /app + +# Copy only necessary files from the builder stage +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/public ./public +COPY --from=builder /app/package.json ./package.json + +# Set environment variables for production +ENV NODE_ENV=production +ENV PORT=3000 + +# Expose port 3000 EXPOSE 3000 -CMD [ "npm", "run", "dev" ] \ No newline at end of file +# Start the Next.js app in production mode +CMD ["npm", "run", "start"] diff --git a/ganesh/README.md b/ganesh/README.md index f05aee3..0ada4dc 100644 --- a/ganesh/README.md +++ b/ganesh/README.md @@ -25,6 +25,12 @@ Rode todos os passos a seguir no diretório `/ganesh`. 9. Na rota '/admin', você poderá logar com email: `admin@example.com` e senha: `password`. 10. Caso queira terminar, `docker compose down`. +##### Para produção + +1. Rode `docker compose build`. +2. Rode `docker compose up -d`. + + ##### Caso queira deletar o usuário Rode `npm run delete`. diff --git a/ganesh/docker-compose.yaml b/ganesh/docker-compose.yaml index 495309b..3d59718 100644 --- a/ganesh/docker-compose.yaml +++ b/ganesh/docker-compose.yaml @@ -1,15 +1,15 @@ +version: "3.8" + services: app: build: . - restart: on-failure + restart: always ports: - - 3000:3000 + - "3000:3000" environment: DATABASE_URL: ${DATABASE_URL_PRODUCTION} - NEXTAUTH_SECRET: ${NEXTAUTH_SECRET} - volumes: - - .:/app # Mount the local directory into the container - - node_modules:/app/node_modules # Ensure node_modules inside the container is not overwritten + NEXTAUTH_SECRET: ${NEXTAUTH_SECRET} + NODE_ENV: production depends_on: - postgres networks: @@ -17,13 +17,13 @@ services: postgres: image: postgres:13-alpine - restart: on-failure + restart: always environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} ports: - - 5432:5432 + - "5432:5432" volumes: - postgres_database:/var/lib/postgresql/data/ networks: @@ -31,6 +31,6 @@ services: volumes: postgres_database: - node_modules: + networks: app-network: