docs: document Dockerfile smoke tests and load workflow for Minikube
- add 3-stage build table (builder/certs/scratch) with image size note
- add build-arg USER_ID override example in section 5.1
- add section 5.1.1 with smoke-test commands (size check, inspect, dry
run, full start)
- add workflow for loading pre-built local images into Minikube
directly
- bump builder base image from golang:1.25-alpine to
golang:1.26-alpine
- normalize inline Dockerfile comments to lowercase
- remove example config COPY from final scratch stage
This commit is contained in:
parent
c6545e29ba
commit
3309e53653
|
|
@ -787,14 +787,67 @@ kubectl delete -f deploy/k8s/mongodb-service.yaml \
|
|||
|
||||
#### 5.1 构建并推送镜像
|
||||
|
||||
镜像采用三阶段构建,最终基于 `scratch`:
|
||||
|
||||
| 阶段 | 基础镜像 | 作用 |
|
||||
| :--- | :--- | :--- |
|
||||
| **builder** | `golang:1.26-alpine` | 编译 Go 二进制(`CGO_ENABLED=0`,`-trimpath -ldflags="-s -w"`) |
|
||||
| **certs** | `alpine:3.21` | 提取 CA 证书、时区数据及非 root 用户定义(UID 默认 `1000`) |
|
||||
| **runtime** | `scratch` | 仅含可执行文件与运行时依赖,无 shell、无包管理器 |
|
||||
|
||||
**方式一:从源码构建并加载**
|
||||
|
||||
```bash
|
||||
# 在项目根目录执行
|
||||
# 在项目根目录执行(默认运行用户 UID=1000)
|
||||
docker build -f deploy/dockerfile/modelrt.Dockerfile -t coslight/modelrt:latest .
|
||||
|
||||
# 推送到镜像仓库(或直接加载到 Minikube)
|
||||
# 自定义运行用户 UID
|
||||
docker build -f deploy/dockerfile/modelrt.Dockerfile \
|
||||
--build-arg USER_ID=2000 \
|
||||
-t coslight/modelrt:latest .
|
||||
|
||||
# 加载到 Minikube(无需私有仓库)
|
||||
minikube image load coslight/modelrt:latest
|
||||
```
|
||||
|
||||
**方式二:直接加载已有本地镜像**
|
||||
|
||||
Ubuntu 宿主机上已存在构建好的镜像(如 `modelrt:v1`)时,无需重新构建,直接导入 Minikube:
|
||||
|
||||
```bash
|
||||
# 确认本地镜像存在
|
||||
docker images modelrt:v1
|
||||
|
||||
# 加载到 Minikube
|
||||
minikube image load modelrt:v1
|
||||
|
||||
# 验证镜像已进入 Minikube 缓存
|
||||
minikube image ls | grep modelrt
|
||||
```
|
||||
|
||||
> **注意:** `deploy/k8s/modelrt-deployment.yaml` 中的 `image` 字段需与加载的镜像名称一致,并将 `imagePullPolicy` 设为 `Never`,防止 Minikube 尝试从远端拉取。
|
||||
|
||||
#### 5.1.1 镜像冒烟测试
|
||||
|
||||
```bash
|
||||
# 查看镜像大小(scratch 镜像预期 ≤ 25 MB)
|
||||
docker images coslight/modelrt:latest
|
||||
|
||||
# 检查镜像元信息(确认 User、Cmd、架构)
|
||||
docker inspect coslight/modelrt:latest
|
||||
|
||||
# 验证二进制可执行(无 config 时程序报错退出属预期行为,说明镜像构建正常)
|
||||
docker run --rm coslight/modelrt:latest
|
||||
|
||||
# 挂载示例配置做完整启动验证(Ctrl+C 退出)
|
||||
docker run --rm \
|
||||
-v "$(pwd)/configs/config.example.yaml:/app/configs/config.yaml" \
|
||||
-p 8080:8080 \
|
||||
coslight/modelrt:latest
|
||||
```
|
||||
|
||||
> **注意:** `scratch` 镜像不含 shell,无法使用 `docker exec` 进入容器调试;如需排查问题,可临时将最终阶段改为 `alpine` 进行本地调试,确认后再切回 `scratch`。
|
||||
|
||||
#### 5.2 创建客户端证书 Secret
|
||||
|
||||
在 RabbitMQ TLS 证书生成完成后(见 4.2),进入证书文件所在目录执行:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
FROM golang:1.25-alpine AS builder
|
||||
FROM golang:1.26-alpine AS builder
|
||||
RUN apk --no-cache upgrade
|
||||
|
||||
WORKDIR /app
|
||||
|
|
@ -21,15 +21,14 @@ RUN apk --no-cache add ca-certificates tzdata && \
|
|||
FROM scratch
|
||||
# CA certificates required for TLS connections (RabbitMQ amqps://)
|
||||
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
# Timezone data
|
||||
# timezone data
|
||||
COPY --from=certs /usr/share/zoneinfo /usr/share/zoneinfo
|
||||
# Non-root user/group definitions
|
||||
# non-root user/group definitions
|
||||
COPY --from=certs /etc/passwd /etc/passwd
|
||||
COPY --from=certs /etc/group /etc/group
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/modelrt ./modelrt
|
||||
COPY configs/config.example.yaml ./configs/config.example.yaml
|
||||
|
||||
USER modelrt
|
||||
CMD ["/app/modelrt", "-modelRT_config_dir=/app/configs"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue