Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ COPY controllers/ controllers/
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
USER root
RUN CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} GO111MODULE=on GOEXPERIMENT=strictfipsruntime go build -tags strictfipsruntime -a -o manager main.go

# Accept an optional prebuilt Go binary
ARG PREBUILT_BINARY=unset

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


FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
WORKDIR /
Expand Down