Files
epess-web-backend/Dockerfile
Ly Tuan Kiet 2033d0ec26 feat: enhance Docker configuration and update environment variables
- Updated .dockerignore to include additional files and directories for better Docker build context management.
- Modified compose.yaml to add BASE_URL and change BUCKET_NAME to improve environment configuration.
- Refactored Dockerfile to implement a multi-stage build for optimized image size and performance.
- Updated package.json to include a new script for production Prisma generation.
- Adjusted tsconfig files to refine project structure and exclude unnecessary directories.
- Removed delta.mdx.txt file from OpenAI instructions to streamline the service.
- Updated package-lock.json and package.json to upgrade Prisma and related dependencies for improved functionality.
2024-12-05 18:37:34 +07:00

49 lines
1.4 KiB
Docker

# Use multi-stage build for optimization
FROM node:22.6.0-alpine AS dependencies
WORKDIR /app
# Copy only package files first to leverage Docker cache
COPY package*.json ./
COPY epess-database/prisma ./prisma
# Enable legacy peer deps and install dependencies in one layer
RUN npm config set legacy-peer-deps true && \
npm ci --only=production && \
npm install --save-dev typescript @types/node @swc/core @swc/cli && \
npx prisma generate
# Second stage for build
FROM node:22.6.0-alpine AS builder
WORKDIR /app
# Set legacy peer deps and copy only necessary files
COPY --from=dependencies /app/node_modules ./node_modules
COPY --from=dependencies /app/prisma ./prisma
COPY package*.json tsconfig*.json ./
COPY nest-cli.json ./
COPY src ./src
# Generate Prisma client and build
RUN npm config set legacy-peer-deps true && \
npm run build
# Final stage
FROM node:22.6.0-alpine AS runner
WORKDIR /app
# Copy only necessary files with minimal layers
COPY --from=dependencies /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/package*.json ./
# Expose the port
EXPOSE 3000
# Use non-root user for security
USER node
# Pause to allow manual inspection (for debugging)
# CMD ["sh", "-c", "echo 'Paused. Press Ctrl+C to continue...'; sleep infinity"]
CMD ["npm", "run", "start:prod"]