lty/qy-lty-admin/Dockerfile
pmc 3e8a212e9f
All checks were successful
Build and Deploy LTY / build-and-deploy (push) Successful in 8m38s
fix(admin): 修复 NEXT_PUBLIC_API_BASE_URL 注入时机导致登录 Network Error
- qy-lty-admin/Dockerfile: build 阶段加 ARG/ENV,让该变量在 next build 时进客户端 JS 包
- .gitea/workflows/deploy.yaml: admin docker build 加 --build-arg https://${DOMAIN_API}/api;删除已失效的 sed 替换
- k8s/admin-deployment-prod.yaml: 删除运行时无效的 NEXT_PUBLIC_API_BASE_URL env,留注释说明

根因:Next.js NEXT_PUBLIC_* 变量在 next build 时被静态编译进客户端 JS。
原配置在容器运行时才设该变量,对已打包的 fallback 默认值无效,
导致线上前端实际打到 http://localhost:8000/api 触发 ERR_CONNECTION_REFUSED。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-07 15:53:37 +08:00

56 lines
1.4 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 构建阶段
FROM docker.m.daocloud.io/node:22.10.0-alpine AS builder
# 设置工作目录
WORKDIR /app
# 设置yarn镜像源为淘宝镜像
RUN yarn config set registry https://registry.npmmirror.com && \
yarn config set disturl https://npmmirror.com/dist --global
# 复制package.json和yarn.lock
COPY package.json yarn.lock* ./
# 安装依赖包括devDependencies用于构建
RUN yarn install --frozen-lockfile
# 复制源代码
COPY . .
# 注入 NEXT_PUBLIC_API_BASE_URLNext.js NEXT_PUBLIC_* 变量必须在 build 期注入才能进客户端 JS 包)
ARG NEXT_PUBLIC_API_BASE_URL
ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL}
# 构建应用
RUN yarn build
# 运行阶段
FROM docker.m.daocloud.io/node:22.10.0-alpine AS runner
# 设置工作目录
WORKDIR /app
# 设置yarn镜像源为淘宝镜像
RUN yarn config set registry https://registry.npmmirror.com && \
yarn config set disturl https://npmmirror.com/dist --global
# 复制package.json和yarn.lock
COPY package.json yarn.lock* ./
# 仅安装生产依赖
RUN yarn install --production --frozen-lockfile
# 设置环境变量
ENV NODE_ENV=production
ENV PATH=/app/node_modules/.bin:$PATH
# 从构建阶段复制构建产物
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.mjs ./
# 暴露端口
EXPOSE 3000
# 启动应用
CMD ["yarn", "start"]