fix(docker): use Alpine and reduce memory for build
- Switch from node:20-slim to node:20-alpine for smaller image - Reduce NODE_OPTIONS memory from 4096 to 2048 - Use Alpine apk instead of apt-get
This commit is contained in:
parent
a9227252e8
commit
ff2c2291cf
1 changed files with 16 additions and 8 deletions
24
Dockerfile
24
Dockerfile
|
|
@ -1,24 +1,32 @@
|
||||||
FROM node:20-slim AS builder
|
# Multi-stage build with memory optimization
|
||||||
|
FROM node:20-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Skip browser downloads
|
||||||
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
||||||
ENV CYPRESS_INSTALL_BINARY=0
|
ENV CYPRESS_INSTALL_BINARY=0
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
# Install build dependencies
|
||||||
python3 \
|
RUN apk add --no-cache python3 make g++
|
||||||
make \
|
|
||||||
g++ \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm install --legacy-peer-deps
|
|
||||||
|
|
||||||
|
# Install dependencies with reduced memory
|
||||||
|
RUN npm install --legacy-peer-deps --prefer-offline --no-audit
|
||||||
|
|
||||||
|
# Copy source
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN NODE_OPTIONS="--max-old-space-size=4096" npm run build
|
|
||||||
|
|
||||||
|
# Build with memory optimization (reduced from 4096 to 2048 for Alpine)
|
||||||
|
ENV NODE_OPTIONS="--max-old-space-size=2048"
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Runtime stage
|
||||||
FROM node:20-alpine
|
FROM node:20-alpine
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy built output
|
||||||
COPY --from=builder /app/.output ./.output
|
COPY --from=builder /app/.output ./.output
|
||||||
|
|
||||||
ENV PORT=9202
|
ENV PORT=9202
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue