diff --git a/apps/.dockerignore b/apps/.dockerignore new file mode 100644 index 0000000..b97feae --- /dev/null +++ b/apps/.dockerignore @@ -0,0 +1,4 @@ +node_modules +.next +.git +.env.local \ No newline at end of file diff --git a/apps/frontend/Dockerfile b/apps/frontend/Dockerfile index 8ccfa56..d7b607d 100644 --- a/apps/frontend/Dockerfile +++ b/apps/frontend/Dockerfile @@ -1,28 +1,33 @@ -FROM node:22-alpine AS builder - -RUN npm install -g pnpm - -WORKDIR /app -COPY package*.json pnpm-lock.yaml ./ -RUN pnpm install --frozen-lockfile -COPY . . - -ARG API_BASE -ENV API_BASE=$API_BASE - -RUN pnpm run build - -FROM node:22-alpine +# 安装依赖 +FROM node:22-alpine AS deps +RUN apk add --no-cache libc6-compat RUN npm install -g pnpm WORKDIR /app COPY package.json pnpm-lock.yaml ./ -RUN pnpm install --frozen-lockfile --prod -COPY --from=builder /app/.next ./.next -COPY --from=builder /app/public ./public -COPY --from=builder /app/next.config.ts ./ +RUN pnpm install --frozen-lockfile +# 编译 +FROM node:22-alpine AS builder +RUN npm install -g pnpm +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +ARG API_BASE +ENV API_BASE=$API_BASE +RUN pnpm run build + +# 运行 +FROM node:22-alpine AS runner +WORKDIR /app + +ENV NODE_ENV=production ARG API_BASE ENV API_BASE=$API_BASE +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/public ./public + EXPOSE 3000 -CMD ["pnpm", "start"] \ No newline at end of file + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/apps/frontend/next.config.ts b/apps/frontend/next.config.ts index 056d978..5d35687 100644 --- a/apps/frontend/next.config.ts +++ b/apps/frontend/next.config.ts @@ -2,6 +2,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { /* config options here */ + output: 'standalone', reactStrictMode: true, devIndicators: { position: 'bottom-right', @@ -16,7 +17,7 @@ const nextConfig: NextConfig = { }, images: { remotePatterns: [new URL('https://tone-personal.oss-cn-chengdu.aliyuncs.com/**')] - } + }, }; export default nextConfig;