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 corepack enable && corepack prepare pnpm@9.15.4 --activate
|
||||||
RUN apk add --no-cache libc6-compat
|
RUN apk add --no-cache libc6-compat
|
||||||
|
|
||||||
# Stage 2: Fetch dependencies (better cache utilization)
|
# Stage 2: Install dependencies
|
||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY pnpm-lock.yaml ./
|
COPY package.json pnpm-lock.yaml ./
|
||||||
RUN pnpm fetch
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
# Stage 3: Build
|
# Stage 3: Build
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy lockfile and fetch cache
|
|
||||||
COPY pnpm-lock.yaml ./
|
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
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
|
# Build the application
|
||||||
COPY package.json ./
|
|
||||||
RUN pnpm install --frozen-lockfile --offline
|
|
||||||
|
|
||||||
# Copy source and build
|
|
||||||
COPY . .
|
|
||||||
RUN pnpm build
|
RUN pnpm build
|
||||||
|
|
||||||
# Prune dev dependencies
|
# Prune dev dependencies for production
|
||||||
RUN pnpm prune --prod && \
|
RUN pnpm prune --prod
|
||||||
pnpm store prune && \
|
|
||||||
rm -rf /root/.local/share/pnpm/store
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Stage 4: Production - Minimal runtime (Distroless alternative: Alpine)
|
# Stage 4: Production - Minimal runtime
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
FROM node:20-alpine AS production
|
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/node_modules ./node_modules
|
||||||
COPY --from=builder --chown=nestjs:nodejs /app/package.json ./
|
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
|
# Environment
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV BACKOFFICE_PORT=3001
|
ENV BACKOFFICE_PORT=3001
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue