refactor: optimize Dockerfile for multi-stage build
- Split Dockerfile into multi-stage build for improved efficiency - Added separate builder and runner stages - Optimized dependency and artifact copying - Reduced final image size by separating build and runtime steps
This commit is contained in:
parent
f9c6230101
commit
057663233d
1 changed files with 11 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
FROM node:22-alpine AS base
|
FROM node:22-alpine AS base
|
||||||
|
|
||||||
# Rebuild the source code only when needed
|
# Rebuild the source code only when needed
|
||||||
FROM base
|
FROM base AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
|
@ -13,6 +13,16 @@ RUN cd apps/api && npm run prisma:generate
|
||||||
# Build the project
|
# Build the project
|
||||||
RUN npx turbo run build --filter=api
|
RUN npx turbo run build --filter=api
|
||||||
|
|
||||||
|
# Copy the built project
|
||||||
|
FROM base AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
|
COPY --from=builder /app/package.json ./package.json
|
||||||
|
COPY --from=builder /app/package-lock.json ./package-lock.json
|
||||||
|
COPY --from=builder /app/apps/api/package.json ./apps/api/package.json
|
||||||
|
COPY --from=builder /app/apps/api/dist ./apps/api/dist
|
||||||
|
COPY --from=builder /app/apps/api/prisma ./apps/api/prisma
|
||||||
|
|
||||||
EXPOSE 4000
|
EXPOSE 4000
|
||||||
# Start the server
|
# Start the server
|
||||||
ENTRYPOINT [ "npm", "run", "start:api" ]
|
ENTRYPOINT [ "npm", "run", "start:api" ]
|
||||||
|
|
Loading…
Add table
Reference in a new issue