Compare commits

2 Commits

Author SHA1 Message Date
ddc9e613e2 chore: 优化后端构建方式
All checks were successful
Deploy to K3s / deploy (push) Successful in 5m55s
2025-12-20 22:08:37 +08:00
93688a0e4e chore: 优化前端构建方式 2025-12-20 22:01:51 +08:00
4 changed files with 37 additions and 25 deletions

4
apps/.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
node_modules
.next
.git
.env.local

View File

@@ -8,14 +8,16 @@ RUN pnpm install --frozen-lockfile
COPY . . COPY . .
RUN pnpm run build RUN pnpm run build
FROM node:22-alpine RUN CI=true pnpm prune --prod
RUN npm install -g pnpm
FROM node:22-alpine AS runner
WORKDIR /app WORKDIR /app
COPY package.json pnpm-lock.yaml ./ ENV NODE_ENV=production
RUN pnpm install --frozen-lockfile --prod
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./package.json
EXPOSE 3001 EXPOSE 3001
CMD ["node", "dist/main.js"] CMD ["node", "dist/main.js"]

View File

@@ -1,28 +1,33 @@
FROM node:22-alpine AS builder # 安装依赖
FROM node:22-alpine AS deps
RUN npm install -g pnpm RUN apk add --no-cache libc6-compat
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
RUN npm install -g pnpm RUN npm install -g pnpm
WORKDIR /app WORKDIR /app
COPY package.json pnpm-lock.yaml ./ COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prod RUN pnpm install --frozen-lockfile
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.ts ./
# 编译
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 ARG API_BASE
ENV API_BASE=$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 EXPOSE 3000
CMD ["pnpm", "start"]
CMD ["node", "server.js"]

View File

@@ -2,6 +2,7 @@ import type { NextConfig } from "next";
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
/* config options here */ /* config options here */
output: 'standalone',
reactStrictMode: true, reactStrictMode: true,
devIndicators: { devIndicators: {
position: 'bottom-right', position: 'bottom-right',
@@ -16,7 +17,7 @@ const nextConfig: NextConfig = {
}, },
images: { images: {
remotePatterns: [new URL('https://tone-personal.oss-cn-chengdu.aliyuncs.com/**')] remotePatterns: [new URL('https://tone-personal.oss-cn-chengdu.aliyuncs.com/**')]
} },
}; };
export default nextConfig; export default nextConfig;