Skip to content

Conversation

hbelmiro
Copy link
Contributor

@hbelmiro hbelmiro commented Jun 17, 2025

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:

CC=x86_64-unknown-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o controllers/manager main.go

Then build the Docker image using the prebuilt binary:

docker build --platform linux/amd64 --build-arg PREBUILT_BINARY=controllers/manager -t "dspo:latest" -f Dockerfile .

Checklist

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Summary by CodeRabbit

  • Chores
    • Updated the build process to allow using a prebuilt Go binary or building from source during container creation, providing more flexibility for deployments.

Copy link

coderabbitai bot commented Jun 17, 2025

Walkthrough

The Dockerfile was updated to introduce a new build argument, PREBUILT_BINARY, allowing users to provide a prebuilt Go binary for the build process. If this argument is not set, the Dockerfile defaults to building the binary from source as before, adding conditional logic for increased flexibility.

Changes

File Change Summary
Dockerfile Added PREBUILT_BINARY build argument; conditional logic to use either a prebuilt or built Go binary

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
Loading

Poem

A Dockerfile hops with a brand new trick,
Prebuilt or from source—choose your pick!
With a toggle so neat,
The build is complete,
Now every bunny can build double-quick! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd2ff67 and 95e173f.

📒 Files selected for processing (1)
  • Dockerfile (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Dockerfile

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

openshift-ci bot commented Jun 17, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign anishasthana for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hbelmiro hbelmiro marked this pull request as ready for review June 17, 2025 20:58
@openshift-ci openshift-ci bot requested review from HumairAK and mprahl June 17, 2025 20:58
Copy link

@coderabbitai coderabbitai bot left a 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 base go-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

📥 Commits

Reviewing files that changed from the base of the PR and between 0546a50 and fd2ff67.

📒 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

Comment on lines +29 to +34
# 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

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.

@hbelmiro hbelmiro changed the title Added support for optional prebuilt Go binaries in Dockerfile WIP - Added support for optional prebuilt Go binaries in Dockerfile Jun 17, 2025
@hbelmiro hbelmiro changed the title WIP - Added support for optional prebuilt Go binaries in Dockerfile Added support for optional prebuilt Go binaries in Dockerfile Jun 17, 2025
@VaniHaripriya
Copy link
Contributor

/lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants