imkFinal/backend/Dockerfile
2025-03-31 18:28:17 +02:00

66 lines
1.3 KiB
Docker

# backend/Dockerfile
FROM node:18-alpine AS builder
WORKDIR /app
# Install necessary tools
RUN apk add --no-cache curl wget postgresql-client
# Copy package files
COPY package*.json ./
# Install dependencies including dev dependencies for building
RUN npm install
# Install NestJS CLI globally
RUN npm install -g @nestjs/cli
# Copy prisma files
# COPY prisma ./prisma/
# Generate Prisma client
# RUN npx prisma generate
# Copy source code
COPY . .
# Build the application
RUN npm run build
# Production stage
FROM node:18-alpine
WORKDIR /app
# Install necessary tools
RUN apk add --no-cache curl wget postgresql-client
# Copy package files
COPY package*.json ./
# Install production dependencies only
RUN npm install --omit=dev
# Copy prisma files and generate client
COPY prisma ./prisma/
RUN npx prisma generate
# Copy built application from builder stage
COPY --from=builder /app/dist ./dist
# Create wait-for-db script
RUN echo '#!/bin/sh\n\
until pg_isready -h postgres -p 5432 -U ${POSTGRES_USER}; do\n\
echo "Waiting for postgres...";\n\
sleep 2;\n\
done\n\
\n\
echo "PostgreSQL is ready!"\n\
\n\
npx prisma migrate deploy\n\
node dist/main.js' > /app/start.sh && chmod +x /app/start.sh
EXPOSE 3000
CMD ["/app/start.sh"]