fix(deploy): inject NEXT_PUBLIC_TOS_DOMAIN at docker build time
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 6m17s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 6m17s
线上 https://cyberstar.airlabs.art 立绘 + 视频全部缺失, 因为部署镜像里 NEXT_PUBLIC_TOS_DOMAIN 是空字符串, 触发 tosUrl() fallback 走相对路径 (/portraits/001.webp 等), 而 public/portraits 已经 .gitignore 不入镜像 → 全 404。 根因: Next.js 把 NEXT_PUBLIC_* 编译进 client bundle, 必须 build 时注入, 运行时通过 envFrom secret 注入无效。 修复: - Dockerfile builder 阶段加 ARG NEXT_PUBLIC_TOS_DOMAIN + ENV, 在 next build 前生效 - .gitea/workflows/deploy.yaml docker build 步骤加 --build-arg NEXT_PUBLIC_TOS_DOMAIN=... 推送后 CI 自动重建镜像, 部署后 HTML 里 src 会变成完整 TOS URL。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a9f4799f71
commit
cfd44403cb
@ -38,6 +38,7 @@ jobs:
|
||||
for attempt in 1 2 3; do
|
||||
echo "Build web attempt $attempt/3..."
|
||||
DOCKER_BUILDKIT=0 docker build \
|
||||
--build-arg NEXT_PUBLIC_TOS_DOMAIN=https://cyber-star.tos-cn-shanghai.volces.com \
|
||||
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/cyberstar-web:${{ env.IMAGE_TAG }} \
|
||||
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/cyberstar-web:latest \
|
||||
. 2>&1 | tee /tmp/build.log && break
|
||||
|
||||
@ -28,6 +28,10 @@ RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
# Build-time public env:NEXT_PUBLIC_* 必须在 next build 之前注入,
|
||||
# 否则会被烧成空字符串,运行时再设也无效 (Next.js 把这类 env 编译进 client bundle)
|
||||
ARG NEXT_PUBLIC_TOS_DOMAIN
|
||||
ENV NEXT_PUBLIC_TOS_DOMAIN=${NEXT_PUBLIC_TOS_DOMAIN}
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
# COPY . . 会覆盖 prisma/schema 的最新版本,需要再 generate 一次确保 client 同步
|
||||
RUN pnpm exec prisma generate \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user