fix(backoffice): simplify Dockerfile for proper source code copying
This commit is contained in:
parent
bda4741c17
commit
ce37206286
1 changed files with 10 additions and 29 deletions
|
|
@ -8,35 +8,28 @@ FROM node:20-alpine AS base
|
|||
RUN corepack enable && corepack prepare pnpm@9.15.4 --activate
|
||||
RUN apk add --no-cache libc6-compat
|
||||
|
||||
# Stage 2: Fetch dependencies (better cache utilization)
|
||||
# Stage 2: Install dependencies
|
||||
FROM base AS deps
|
||||
WORKDIR /app
|
||||
COPY pnpm-lock.yaml ./
|
||||
RUN pnpm fetch
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Stage 3: Build
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
|
||||
# Copy lockfile and fetch cache
|
||||
COPY pnpm-lock.yaml ./
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
COPY tsconfig*.json nest-cli.json ./
|
||||
COPY src ./src
|
||||
|
||||
# Copy package files and install
|
||||
COPY package.json ./
|
||||
RUN pnpm install --frozen-lockfile --offline
|
||||
|
||||
# Copy source and build
|
||||
COPY . .
|
||||
# Build the application
|
||||
RUN pnpm build
|
||||
|
||||
# Prune dev dependencies
|
||||
RUN pnpm prune --prod && \
|
||||
pnpm store prune && \
|
||||
rm -rf /root/.local/share/pnpm/store
|
||||
# Prune dev dependencies for production
|
||||
RUN pnpm prune --prod
|
||||
|
||||
# =============================================================================
|
||||
# Stage 4: Production - Minimal runtime (Distroless alternative: Alpine)
|
||||
# Stage 4: Production - Minimal runtime
|
||||
# =============================================================================
|
||||
FROM node:20-alpine AS production
|
||||
|
||||
|
|
@ -51,18 +44,6 @@ COPY --from=builder --chown=nestjs:nodejs /app/dist ./dist
|
|||
COPY --from=builder --chown=nestjs:nodejs /app/node_modules ./node_modules
|
||||
COPY --from=builder --chown=nestjs:nodejs /app/package.json ./
|
||||
|
||||
# Remove unnecessary files to reduce size
|
||||
RUN find node_modules -name "*.md" -delete 2>/dev/null || true && \
|
||||
find node_modules -name "*.d.ts" -delete 2>/dev/null || true && \
|
||||
find node_modules -name "CHANGELOG*" -delete 2>/dev/null || true && \
|
||||
find node_modules -name "LICENSE*" -delete 2>/dev/null || true && \
|
||||
find node_modules -name "*.map" -delete 2>/dev/null || true && \
|
||||
find node_modules -type d -name "test" -exec rm -rf {} + 2>/dev/null || true && \
|
||||
find node_modules -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true && \
|
||||
find node_modules -type d -name "__tests__" -exec rm -rf {} + 2>/dev/null || true && \
|
||||
find node_modules -type d -name "docs" -exec rm -rf {} + 2>/dev/null || true && \
|
||||
rm -rf /tmp/* /var/cache/apk/*
|
||||
|
||||
# Environment
|
||||
ENV NODE_ENV=production
|
||||
ENV BACKOFFICE_PORT=3001
|
||||
|
|
|
|||
Loading…
Reference in a new issue