-
Notifications
You must be signed in to change notification settings - Fork 71
Added support for optional prebuilt Go binaries in Dockerfile #883
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe Dockerfile was updated to introduce a new build argument, Changes
Sequence Diagram(s)sequenceDiagram
participant Builder as Docker Build Stage
participant External as External Source (optional)
participant GoSource as Go Source Files
alt PREBUILT_BINARY is set
External->>Builder: Provide prebuilt Go binary
Builder->>Builder: Copy prebuilt binary into workspace
else PREBUILT_BINARY is unset
GoSource->>Builder: Source code available
Builder->>Builder: Build Go binary from source
end
Builder->>Builder: Continue with remaining Docker build steps
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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: 2
🧹 Nitpick comments (1)
Dockerfile (1)
25-25
: Verify necessity of switching to root user in builder stage.The
USER root
instruction may be redundant if the basego-toolset
image already runs as root. Explicitly changing user can affect layer caching and permissions. Please confirm if this elevation is required and remove it if not.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Dockerfile
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: unittest
- GitHub Check: precommit
- GitHub Check: functest
# If PREBUILT_BINARY is set, use it; otherwise, build from source | ||
RUN if [ "$PREBUILT_BINARY" = "unset" ]; then \ | ||
CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} GO111MODULE=on GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -a -o manager main.go; \ | ||
else \ | ||
cp ${PREBUILT_BINARY} /workspace/manager; \ | ||
fi |
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.
🛠️ Refactor suggestion
Fix handling of prebuilt binary import.
The cp ${PREBUILT_BINARY}
inside the RUN
step will fail because build arguments alone don’t populate files into the image. You need to explicitly COPY
the binary into the build context (or use a BuildKit mount) before referencing it. For example:
- RUN if [ "$PREBUILT_BINARY" = "unset" ]; then \
- CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} GO111MODULE=on GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -a -o manager main.go; \
- else \
- cp ${PREBUILT_BINARY} /workspace/manager; \
- fi
+ RUN if [ "$PREBUILT_BINARY" = "unset" ]; then \
+ CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} GO111MODULE=on GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -a -o manager main.go; \
+ fi
+
+ # Copy the prebuilt binary from the build context
+ COPY ${PREBUILT_BINARY} /workspace/manager
This ensures the binary is available in the container before copying.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In Dockerfile lines 29 to 34, the current RUN command tries to copy a prebuilt
binary using cp ${PREBUILT_BINARY}, but this fails because the binary is not
present in the build context or image. To fix this, add a COPY instruction
before the RUN step to explicitly copy the prebuilt binary from the host into
the image at a known location, then update the RUN command to copy from that
location. This ensures the binary is available inside the container during the
build.
Signed-off-by: Helber Belmiro <[email protected]>
/lgtm |
The issue resolved by this Pull Request:
Resolves https://issues.redhat.com/browse/RHOAIENG-26496
Description of your changes:
This commit adds support for optional prebuilt Go binaries in Dockerfiles using a
PREBUILT_BINARY
argument. It allows developers to skip source builds and use prebuilt binaries, serving as a workaround for issues like cross-platform builds. The default behavior remains unchanged for compatibility.Testing instructions
Build the binary with:
Then build the Docker image using the prebuilt binary:
Checklist
Summary by CodeRabbit