-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
79 lines (69 loc) · 2.08 KB
/
Dockerfile
File metadata and controls
79 lines (69 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
FROM node:20-slim AS base
FROM base AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
build-essential \
python3 \
pkg-config \
libcairo2-dev \
libjpeg-dev \
libpango1.0-dev \
libgif-dev \
librsvg2-dev \
libfreetype6-dev \
libharfbuzz-dev \
libfribidi-dev \
fonts-dejavu \
fontconfig \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
ENV npm_config_python=/usr/bin/python3
ARG NEXT_PUBLIC_APP_URL
ARG NEXT_PUBLIC_OPEN_SOURCE_URL
ARG NEXT_PUBLIC_DEFAULT_LOCALE=zh-cn
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
ENV NEXT_PUBLIC_OPEN_SOURCE_URL=$NEXT_PUBLIC_OPEN_SOURCE_URL
ENV NEXT_PUBLIC_DEFAULT_LOCALE=$NEXT_PUBLIC_DEFAULT_LOCALE
ENV NEXT_TELEMETRY_DISABLED=1
ENV DOCKER_BUILD=true
# Increase Node.js memory limit for Next.js build
ENV NODE_OPTIONS="--max-old-space-size=4096"
COPY . .
# Replace relative image paths with CDN URLs
# RUN chmod +x ./scripts/replace-image-paths.sh && ./scripts/replace-image-paths.sh
RUN npm install && npm run build
# Remove development dependencies to reduce final image size
RUN npm prune --production
FROM base AS runner
# Runtime libraries for canvas and image processing support
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
libcairo2 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libjpeg62-turbo \
libgif7 \
librsvg2-2 \
fontconfig \
libfreetype6 \
libharfbuzz0b \
libfribidi0 \
fonts-dejavu \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
WORKDIR /app
# Copy built application and node_modules from builder
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
USER nextjs
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
EXPOSE 3000
CMD ["npm", "start"]