Files
sundynix-agentix/sundynix-gateway/Dockerfile
T
Blizzard 28a1543249 feat(gateway): 内嵌 admin 控制台(go:embed),去掉单独 nginx 容器
复刻 sundynix-site 的 webfs 模式:gateway 一个容器同时 serve 控制台 UI + API + 供
桌面端直连。admin 用 HashRouter + API base 走相对 /api/v1(构建传 VITE_GATEWAY=''),
源码零改动即可同源 serve。

- internal/webui:go:embed all:admin_dist + Dist();占位 index.html 让不构建前端也能编译。
  目录命名 admin_dist(避开 .gitignore dist/ 与 .dockerignore **/dist 通配)。
- router.go NoRoute:非 /api/ 路径走内嵌静态,命中 /assets/* 直吐、否则回退 index.html;
  embed 失败仅 log 降级不影响 API。/metrics /healthz /readyz /api/v1 已注册,永不进 NoRoute。
- Dockerfile 加 admin node 构建 stage,go build 前 COPY dist 覆盖 embed 占位。
- live 验证:/ 返回 admin(200)、/assets/*.js(200)、/api/v1/admin/overview(401 走 API)、/healthz(200)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 14:45:24 +08:00

39 lines
1.7 KiB
Docker
Raw 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.
# 第 2 层 业务网关。多阶段构建:node 构建 admin 控制台 → Go 编译(内嵌 admin)→ distroless 运行。
# 一个 gateway 容器同时 serve 控制台 UI + API + 供桌面端直连,无需单独 admin nginx 容器。
# 构建上下文须为「仓库根」(因 go.mod 用 replace ../sundynix-shared,且需 COPY sundynix-admin/):
# docker build -f sundynix-gateway/Dockerfile -t sundynix/gateway .
# ── 0. 构建 admin 运维控制台前端 ──
FROM node:20-alpine AS admin
WORKDIR /app
COPY sundynix-admin/package*.json ./
RUN npm config set registry https://registry.npmmirror.com && npm ci
COPY sundynix-admin/ ./
# VITE_GATEWAY 留空 → 前端走相对 /api/v1,内嵌进 gateway 后同源、免跨域。
ENV VITE_GATEWAY=""
RUN npm run build # 产物 /app/dist
# ── 1. 编译 Gogo:embed 内嵌 admin 产物)──
FROM golang:1.25-alpine AS build
WORKDIR /src
# 先拷依赖清单分层缓存(命中则跳过重下)
COPY sundynix-shared/go.mod sundynix-shared/go.sum ./sundynix-shared/
COPY sundynix-gateway/go.mod sundynix-gateway/go.sum ./sundynix-gateway/
WORKDIR /src/sundynix-gateway
ENV GOWORK=off GOFLAGS=-mod=mod
RUN go mod download
# 再拷源码编译
WORKDIR /src
COPY sundynix-shared/ ./sundynix-shared/
COPY sundynix-gateway/ ./sundynix-gateway/
WORKDIR /src/sundynix-gateway
# 用真实 admin 构建产物覆盖 embed 占位目录(go:embed 从 internal/webui/admin_dist 读)
COPY --from=admin /app/dist ./internal/webui/admin_dist
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/gateway ./cmd/server
# ── 2. 运行镜像 ──
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/gateway /gateway
EXPOSE 8080
ENTRYPOINT ["/gateway"]