mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-29 23:16:51 +00:00
feat: 优化dockerfile,可使包体积从1.1G缩小至200M
This commit is contained in:
28
Dockerfile
28
Dockerfile
@@ -1,23 +1,39 @@
|
|||||||
ARG NOTION_PAGE_ID
|
ARG NOTION_PAGE_ID
|
||||||
ARG NEXT_PUBLIC_THEME
|
ARG NEXT_PUBLIC_THEME
|
||||||
|
|
||||||
# Install dependencies only when needed
|
FROM node:18-alpine3.18 AS base
|
||||||
FROM node:18-alpine3.18 AS deps
|
|
||||||
|
# 1. Install dependencies only when needed
|
||||||
|
FROM base AS deps
|
||||||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||||
RUN apk add --no-cache libc6-compat
|
RUN apk add --no-cache libc6-compat
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json ./
|
COPY package.json ./
|
||||||
RUN yarn install --frozen-lockfile
|
RUN yarn install --frozen-lockfile
|
||||||
|
|
||||||
# Rebuild the source code only when needed
|
# 2. Rebuild the source code only when needed
|
||||||
FROM node:18-alpine3.18 AS builder
|
FROM base AS builder
|
||||||
ARG NOTION_PAGE_ID
|
ARG NOTION_PAGE_ID
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN yarn build
|
RUN yarn build
|
||||||
|
|
||||||
ENV NODE_ENV production
|
# 3. Production image, copy all the files and run next
|
||||||
|
FROM base AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
|
||||||
|
# Automatically leverage output traces to reduce image size
|
||||||
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||||
|
COPY --from=builder /app/.next/standalone ./
|
||||||
|
COPY --from=builder /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
# 个人仓库把将配置好的.env.local文件放到项目根目录,可自动使用环境变量
|
||||||
|
# COPY --from=builder /app/.env.local ./
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
@@ -26,4 +42,4 @@ EXPOSE 3000
|
|||||||
# Uncomment the following line in case you want to disable telemetry.
|
# Uncomment the following line in case you want to disable telemetry.
|
||||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
CMD ["yarn", "start"]
|
CMD ["node", "server.js"]
|
||||||
@@ -84,7 +84,7 @@ const nextConfig = {
|
|||||||
eslint: {
|
eslint: {
|
||||||
ignoreDuringBuilds: true
|
ignoreDuringBuilds: true
|
||||||
},
|
},
|
||||||
output: process.env.EXPORT ? 'export' : undefined,
|
output: process.env.EXPORT ? 'export' : 'standalone',
|
||||||
staticPageGenerationTimeout: 120,
|
staticPageGenerationTimeout: 120,
|
||||||
// 多语言, 在export时禁用
|
// 多语言, 在export时禁用
|
||||||
i18n: process.env.EXPORT
|
i18n: process.env.EXPORT
|
||||||
|
|||||||
Reference in New Issue
Block a user