feat: web docker

This commit is contained in:
2026-03-11 16:59:56 +08:00
parent ce53a4f218
commit 7bd4e379de
2 changed files with 69 additions and 0 deletions

59
apps/web/Dockerfile Normal file
View File

@@ -0,0 +1,59 @@
FROM node:22-alpine AS base
# ============================================
# Stage 1: Install dependencies
# ============================================
FROM base AS builder
RUN apk add --no-cache gcompat
RUN corepack enable && corepack prepare pnpm@10.18.2 --activate
WORKDIR /app
# 复制 monorepo 根配置catalog、lockfile 等)
COPY pnpm-workspace.yaml pnpm-lock.yaml package.json ./
# 复制 web 应用源码
COPY apps/web/package.json ./apps/web/package.json
COPY apps/web/next.config.ts ./apps/web/next.config.ts
COPY apps/web/tsconfig.json ./apps/web/tsconfig.json
COPY apps/web/postcss.config.mjs ./apps/web/postcss.config.mjs
COPY apps/web/app ./apps/web/app
COPY apps/web/components ./apps/web/components
COPY apps/web/lib ./apps/web/lib
COPY apps/web/types ./apps/web/types
COPY apps/web/public ./apps/web/public
COPY apps/web/middleware.ts ./apps/web/middleware.ts
RUN pnpm install --filter web
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN pnpm --filter web run build
# ============================================
# Stage 2: Run Next.js application
# ============================================
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/public ./public
RUN mkdir .next && chown nextjs:nodejs .next
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
USER nextjs
EXPOSE 3000
CMD ["node", "apps/web/server.js"]