-
Notifications
You must be signed in to change notification settings - Fork 176
feat: 指定交叉编译的镜像架构,达到构建提速目的 #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe Dockerfile’s builder stage now specifies an explicit build platform: linux/amd64. All other instructions remain unchanged. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
Dockerfile (2)
11-11
: Harden cross‑compile env and trim apk cachesIf TARGETARCH isn’t supplied (local docker build without buildx), GOARCH becomes an empty env var. Provide a sane default and avoid persisting apk indexes.
-RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags="-s -w" -trimpath -o hubproxy . && upx -9 hubproxy +RUN apk add --no-cache upx && \ + CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH:-amd64} \ + go build -ldflags="-s -w" -trimpath -o hubproxy . && \ + upx -9 hubproxyIf you adopt the BUILDPLATFORM/TARGETPLATFORM pattern, prefer GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH}.
13-20
: Propagate target platform, pin base, and drop root in runtime imageFor smaller, safer runtime images and correct platform selection in multi‑arch builds:
-FROM alpine +FROM --platform=$TARGETPLATFORM alpine:3.20 WORKDIR /root/ -COPY --from=builder /app/hubproxy . -COPY --from=builder /app/config.toml . +# Create nonroot user and copy artifacts with ownership +RUN adduser -D -u 65532 -H appuser +COPY --from=builder --chown=65532:65532 /app/hubproxy . +COPY --from=builder --chown=65532:65532 /app/config.toml . +USER 65532:65532Optional: if the binary is fully static (CGO_ENABLED=0), you can use
FROM scratch
and copy only the binary and config.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Dockerfile
(2 hunks)
🔇 Additional comments (2)
Dockerfile (2)
1-1
: Use BuildKit’s platform args for true multi-arch builds
Replace the hard-coded amd64 builder with the standard BuildKit pattern and add the necessary ARGs:+ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH -FROM --platform=linux/amd64 golang:1.25-alpine AS builder +FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS builderEnsure you propagate
$TARGETPLATFORM
in the final stage and manually verify withdocker buildx build --platform linux/amd64,linux/arm64 …
to confirm native builds for each architecture.
1-1
: Sanity check base image tag availability
Please manually confirm that thegolang:1.25-alpine
image tag is published (e.g., via Docker Hub search ordocker pull golang:1.25-alpine
) to avoid CI failures.
emm,感谢PR,不过我觉得不用优化到太极致,并且这个改动可能会对其他架构执行 |
ok |
换了个思路,实测即可达到加速目的,还不影响Dockerfile完整。
Summary by CodeRabbit