Files
Volcano-Engine-TTS-UI/Dockerfile
T
sun 8be40ae6dc chore: embed health.html 到 binary,单文件分发
把 health.html 从外部依赖改为 //go:embed 内嵌,
实现真正的"单 exe 分发"。

  - 新建 router/dashboard.go,用 //go:embed 嵌入 health.html
  - router/router.go:/dashboard handler 改为 w.Write(dashboardHTML)
  - setting/config.go:删 CheckStaticFiles(无需文件检查)
  - main.go:删 setting.CheckStaticFiles() 调用
  - Dockerfile:删 COPY health.html 步骤(已嵌入)
  - .gitignore:加 release/(build 产物不入 git)
  - 物理移动 health.html 到 router/(embed 限制:同包或子包)

效果:
  - 之前: release 包 = tts-api.exe + health.html (2 个文件)
  - 之后: release 包 = tts-api.exe (1 个文件,~7 MB)
  - 用户部署无需额外文件,/dashboard 路由直接工作
2026-08-27 11:44:44 +08:00

40 lines
957 B
Docker

FROM golang:1.26-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# VERSION 由 CI/CD 传入,通常为 `git describe --tags --always --dirty` 的输出
# COMMIT 为 `git rev-parse --short HEAD`
# 本地默认 dev
ARG VERSION=dev
ARG COMMIT=dev
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags "-X github.com/volcano-tts/tts-api/version.Version=${VERSION} \
-X github.com/volcano-tts/tts-api/version.Commit=${COMMIT}" \
-o tts-api .
FROM alpine:3.21
RUN apk --no-cache add ca-certificates tzdata \
&& addgroup -S appgroup && adduser -S appuser -G appgroup
WORKDIR /app
COPY --from=builder /app/tts-api .
# health.html 已通过 //go:embed 嵌入 binary,无需单独复制
RUN chown -R appuser:appgroup /app
USER appuser
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD wget -qO- http://localhost:8080/health || exit 1
ENTRYPOINT ["./tts-api"]