build+deploy: 编译加 -trimpath,镜像改 lghost/opsxsql,K8s 部署到 sql 命名空间
1. -trimpath(抹除源码绝对路径)
- Dockerfile: go build 加 -trimpath
- run.sh: 两处 go build 加 -trimpath
效果:二进制内 /app/backend/ 绝对路径命中 66 → 0(module 相对路径 sql-platform/ 仍保留,
那是 Go 的正常行为,-trimpath 只去绝对前缀)
2. 镜像
- kubernetes/deployment.yaml: opsxsql:latest → lghost/opsxsql:latest
- kubernetes/install.sh: 默认 IMAGE 改 lghost/opsxsql:latest
- 已构建并推送:lghost/opsxsql:latest (digest 70562a408cae, 25.2MB)
3. K8s 部署验证(namespace: sql)
- Deployment opsxsql 1/1 Running,0 重启
- Pod: opsxsql-695444d6b9-chrzp (node 172.19.0.161)
- Service opsxsql.sql.svc.cluster.local:80
- PVC opsxsql-data Bound 10Gi (cbs)
- Secret opsxsql-secrets 自动生成(SECRET_KEY / JWT_SECRET)
- /health → {"backend":"go","status":"ok","version":"0.4.0"}
- 首页正常,seed 完成(26 条审核规则 + LDAP 默认配置)
部署命令:bash kubernetes/install.sh
This commit is contained in:
1 parent
dbe9e4ab86
commit
396df57c9c
15 files changed
+233
-24
No files matched your search
+19
-7
@@ -24,21 +24,33 @@ WORKDIR /app/backend
|
||||
COPY backend/go.* ./
|
||||
RUN go mod download
|
||||
COPY backend/ ./
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -o /out/opsxsql ./cmd/server/
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/opsxsql ./cmd/server/
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# Stage 3: gh-ost 在线变更工具(静态二进制,按架构取包)
|
||||
#
|
||||
# 注意:GitHub release 的实际 asset 名不是 gh-ost-linux-<arch>,而是:
|
||||
# amd64: gh-ost (裸二进制,18MB)
|
||||
# arm64: gh-ost-binary-linux-arm64-<ts>.tar.gz(tar 包)
|
||||
# ---------------------------------------------------------------
|
||||
FROM alpine:3.20 AS ghost
|
||||
ARG TARGETARCH
|
||||
RUN apk add --no-cache curl && \
|
||||
ARG GH_OST_VER=v1.1.9
|
||||
ARG GH_OST_ARM64_ASSET=gh-ost-binary-linux-arm64-20260501022029.tar.gz
|
||||
RUN mkdir -p /out && \
|
||||
apk add --no-cache curl tar && \
|
||||
case "${TARGETARCH}" in \
|
||||
arm64) GH_ARCH="arm64" ;; \
|
||||
*) GH_ARCH="amd64" ;; \
|
||||
arm64) \
|
||||
curl -fsSL -o /tmp/gh.tgz \
|
||||
"https://github.com/github/gh-ost/releases/download/${GH_OST_VER}/${GH_OST_ARM64_ASSET}" && \
|
||||
tar -xzf /tmp/gh.tgz -C /tmp && \
|
||||
mv /tmp/gh-ost-binary-linux-arm64-* /out/gh-ost ;; \
|
||||
*) \
|
||||
curl -fsSL -o /out/gh-ost \
|
||||
"https://github.com/github/gh-ost/releases/download/${GH_OST_VER}/gh-ost" ;; \
|
||||
esac && \
|
||||
curl -fsSL -o /out/gh-ost \
|
||||
"https://github.com/github/gh-ost/releases/download/v1.1.9/gh-ost-linux-${GH_ARCH}" && \
|
||||
chmod +x /out/gh-ost
|
||||
chmod +x /out/gh-ost && \
|
||||
ls -lh /out/gh-ost
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# Stage 4: 运行时镜像
|
||||
|
||||
Reference in new issue
Block a user