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.
This commit is contained in:
50
Dockerfile
50
Dockerfile
@@ -1,23 +1,49 @@
|
||||
FROM node:22.6.0-alpine AS node_base
|
||||
|
||||
# Set the working directory
|
||||
# Use multi-stage build for optimization
|
||||
FROM node:22.6.0-alpine AS dependencies
|
||||
WORKDIR /app
|
||||
|
||||
# Enable legacy peer deps
|
||||
RUN npm config set legacy-peer-deps true
|
||||
# Copy only package files first to leverage Docker cache
|
||||
COPY package*.json ./
|
||||
COPY epess-database/prisma ./prisma
|
||||
|
||||
COPY . .
|
||||
# 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
|
||||
|
||||
# Install the dependencies
|
||||
RUN npm install
|
||||
# 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 the Prisma client
|
||||
RUN npm run prisma:generate
|
||||
# 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
|
||||
|
||||
# Start the application
|
||||
# Use non-root user for security
|
||||
USER node
|
||||
|
||||
CMD ["npm", "run", "start:dev"]
|
||||
# Pause to allow manual inspection (for debugging)
|
||||
# CMD ["sh", "-c", "echo 'Paused. Press Ctrl+C to continue...'; sleep infinity"]
|
||||
|
||||
CMD ["npm", "run", "start:prod"]
|
||||
Reference in New Issue
Block a user