- Added .nvmrc and .npmrc files to the Docker image for consistent Node.js versioning and npm configuration. - Removed the direct copy of the prisma directory to streamline the build process.
52 lines
1.4 KiB
Docker
52 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/package*.json ./
|
|
|
|
# mount nvmrc and npmrc from host
|
|
COPY .nvmrc ./
|
|
COPY .npmrc ./
|
|
|
|
# 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"] |