build: make Go image build resilient to registry mirror failures

This commit is contained in:
zn-admin committed 2026-08-14 10:45:08 +08:00
1 parent 550edcdc05
commit c7d2cb212c
5 files changed
+121 -3

No files matched your search

@@ -0,0 +1,40 @@
# Task: Make Go image build resilient to mirror failures
## Identity
- Task ID: 20260814-go-image-build-fix-7d4b9e2c
- Mode: Feature
- Branch: main
- Worktree: /Users/brother7/Documents/AI/NianAIGC
- Base commit: 550edcdc059073d9bea96d4b577d4fafeaefdf74
- Owner: dsh
- Status: Ready for Integration
## Scope
- Fix the CI image build failure where the build machine's registry accelerator (mirror.aliyuncs.com) returned 500 on a `golang:1.21-alpine` blob: make the base images overridable and add a golang-image-free build path.
## Intent And Constraints
- Keep the standard multi-stage build as the default; no behavioral change for healthy registries.
- The runtime image must stay non-root, root-filesystem-read-only compatible, and identical across both build paths.
## Outcome
- `backend/Dockerfile`: added `GOLANG_IMAGE` and `RUNTIME_IMAGE` ARGs so a working mirror can be supplied via `--build-arg` without editing the file.
- Added `backend/Dockerfile.runtime`: alpine-only image that copies a prebuilt static `zhinian-api.linux` binary, for build environments that cannot pull the golang builder image at all.
- Documented all three build paths (standard, mirror override, prebuilt binary) in `backend/README.md` and `docs/DEPLOYMENT.md`.
## Verification
- `CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o zhinian-api.linux ./cmd/zhinian-api` succeeds on this machine: 12.3 MB statically linked stripped ELF x86-64, confirming the prebuilt-binary path is usable.
- Docker image assembly itself must run on a machine with Docker; both Dockerfiles follow the same runtime stage as the already-merged image definition.
## Follow-ups
- On the CI machine, either switch the registry accelerator in `/etc/docker/daemon.json` or use the prebuilt-binary path.
- Re-run the failing Gitea build to confirm.
## Promotion Candidates
- None.