接入Docker蓝绿部署:自包含多阶段构建、配置外部化

- 新增根目录Dockerfile:多阶段构建(Vue前端 + Go后端),包含main.go依赖的
  internal/packed资源打包步骤(原来依赖gf build外部产出,未提交进仓库)
- 新增server/manifest/config/config.template:数据库/Redis连接串、
  token密钥等敏感配置改为占位符,运行时通过entrypoint.sh用envsubst生成
  真正的config.yaml,不再需要在仓库里维护包含真实密码的config.yaml
- entrypoint.sh改为先渲染配置再启动
- 修复web/pnpm-lock.yaml与package.json不同步的问题(有依赖被加进
  package.json但没重新生成锁文件)
- 新增web/pnpm-workspace.yaml:较新版本pnpm默认禁止依赖包运行构建脚本
  (供应链安全特性),需要显式在这里批准esbuild/@swc/core等的构建脚本,
  否则CI环境下frozen-lockfile安装会直接失败
This commit is contained in:
Your Name
2026-08-12 11:26:13 +08:00
parent 331a55751d
commit f711fec00b
5 changed files with 998 additions and 326 deletions
+50
View File
@@ -0,0 +1,50 @@
# ---- Stage 1: build the Vue frontend ----
FROM node:22-alpine AS web-build
WORKDIR /web
RUN npm install -g pnpm
COPY web/package.json web/pnpm-lock.yaml web/pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
COPY web/ .
RUN pnpm run build
# ---- Stage 2: build the Go backend, embedding the frontend build ----
FROM golang:1.24-alpine AS server-build
RUN apk add --no-cache git
WORKDIR /src
COPY server/go.mod server/go.sum ./
RUN go mod download
COPY server/ .
# Same layout the project's own Makefile produces: built frontend goes into
# resource/public/admin/ before packing/building the backend.
RUN rm -rf resource/public/admin && mkdir -p resource/public/admin
COPY --from=web-build /web/dist/ ./resource/public/admin/
# main.go does `import _ "hotgo/internal/packed"`, a file normally generated by
# `gf build` (see server/hack/config.yaml: packSrc/packDst) and gitignored —
# generate it explicitly with the same gf CLI version pinned in go.mod.
RUN go install github.com/gogf/gf/cmd/gf/v2@v2.10.0
RUN gf pack resource internal/packed/packed.go
RUN CGO_ENABLED=0 go build -o /out/hotgo main.go
# ---- Stage 3: runtime ----
FROM alpine:3.22
RUN apk add --no-cache ca-certificates gettext bash
WORKDIR /app
COPY --from=server-build /src/manifest ./manifest
COPY --from=server-build /out/hotgo .
COPY server/manifest/docker/entrypoint.sh .
RUN mkdir -p storage/logs storage/data storage/cache storage/diskqueue \
&& chmod +x entrypoint.sh hotgo
HEALTHCHECK --interval=1m --timeout=3s --start-period=20s \
CMD nc -z localhost 8000 || exit 1
EXPOSE 8000
ENTRYPOINT ["./entrypoint.sh"]