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

+29
View File
@@ -37,6 +37,35 @@ npm run go:vet
npm run go:build
```
## Container images
Standard multi-stage build (needs the `golang` builder image):
```bash
docker build -f backend/Dockerfile -t REGISTRY/PROJECT/zhinian-go-api:TAG backend/
```
Mirror-friendly build (override the base images when the registry accelerator
cannot serve docker.io images):
```bash
docker build -f backend/Dockerfile \
--build-arg GOLANG_IMAGE=<mirror>/golang:1.21-alpine \
--build-arg RUNTIME_IMAGE=<mirror>/alpine:3.20 \
-t REGISTRY/PROJECT/zhinian-go-api:TAG backend/
```
Prebuilt-binary build (no `golang` image at all; compile the static binary on
any Go 1.21 machine, then assemble from `alpine` only):
```bash
cd backend
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -trimpath -ldflags="-s -w" -o zhinian-api.linux ./cmd/zhinian-api
docker build -f backend/Dockerfile.runtime \
-t REGISTRY/PROJECT/zhinian-go-api:TAG backend/
```
The runner defaults to `CGO_ENABLED=0` for reproducible cross-platform builds.
To exercise the local foundation manually without changing the existing Next
server, use a different port: