-
Notifications
You must be signed in to change notification settings - Fork 12
HYPERFLEET-509 - feat: Standardize Dockerfiles and Makefile for building images #59
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
Open
xueli181114
wants to merge
1
commit into
openshift-hyperfleet:main
Choose a base branch
from
xueli181114:HYPERFLEET-509
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,60 @@ | ||
| ARG BASE_IMAGE=gcr.io/distroless/static-debian12:nonroot | ||
|
|
||
| # OpenAPI generation stage | ||
| FROM golang:1.25 AS builder | ||
| FROM registry.access.redhat.com/ubi9/go-toolset:1.25 AS builder | ||
|
|
||
| ARG GIT_SHA=unknown | ||
| ARG GIT_DIRTY="" | ||
| ARG BUILD_DATE="" | ||
| ARG VERSION="" | ||
|
|
||
| # Install make as root (UBI9 go-toolset doesn't include it), then switch back to non-root. | ||
| USER root | ||
| RUN dnf install -y make && dnf clean all | ||
| WORKDIR /build | ||
|
|
||
| # Copy go mod files | ||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
|
|
||
| # Copy source code | ||
| COPY . . | ||
|
|
||
| # Build binary | ||
| RUN CGO_ENABLED=0 GOOS=linux make build | ||
| RUN chown 1001:0 /build | ||
| USER 1001 | ||
|
|
||
| # Install bingo tools (mockgen, oapi-codegen) under /build/.gobin and add to PATH | ||
| # so "go generate" can find them. ENV persists for all subsequent RUN commands. | ||
| ENV GOBIN=/build/.gobin | ||
| ENV PATH="${GOBIN}:${PATH}" | ||
|
|
||
| COPY --chown=1001:0 go.mod go.sum ./ | ||
| RUN --mount=type=cache,target=/opt/app-root/src/go/pkg/mod,uid=1001 \ | ||
| go mod download | ||
|
|
||
| COPY --chown=1001:0 . . | ||
|
|
||
| # CGO_ENABLED=0 produces a static binary required for distroless runtime. | ||
| # For FIPS-compliant builds (CGO_ENABLED=1 + GOEXPERIMENT=boringcrypto), use a | ||
| # runtime image with glibc (e.g. ubi9-micro) instead of distroless. | ||
| RUN --mount=type=cache,target=/opt/app-root/src/go/pkg/mod,uid=1001 \ | ||
| --mount=type=cache,target=/opt/app-root/src/.cache/go-build,uid=1001 \ | ||
| mkdir -p $GOBIN && \ | ||
| CGO_ENABLED=0 GOOS=linux \ | ||
| GIT_SHA=${GIT_SHA} GIT_DIRTY=${GIT_DIRTY} BUILD_DATE=${BUILD_DATE} VERSION=${VERSION} \ | ||
| make build | ||
|
|
||
| # Runtime stage | ||
| FROM ${BASE_IMAGE} | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy binary from builder | ||
| COPY --from=builder /build/bin/hyperfleet-api /app/hyperfleet-api | ||
|
|
||
| # Copy OpenAPI schema for validation (uses the source spec, not the generated one) | ||
| COPY --from=builder /build/openapi/openapi.yaml /app/openapi/openapi.yaml | ||
|
|
||
| # Set default schema path (can be overridden by Helm for provider-specific schemas) | ||
| ENV OPENAPI_SCHEMA_PATH=/app/openapi/openapi.yaml | ||
|
|
||
| USER 65532:65532 | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| EXPOSE 8000 | ||
|
|
||
| ENTRYPOINT ["/app/hyperfleet-api"] | ||
| CMD ["serve"] | ||
|
|
||
| ARG VERSION="" | ||
| LABEL name="hyperfleet-api" \ | ||
| vendor="Red Hat" \ | ||
| version="0.0.1" \ | ||
| version="${VERSION}" \ | ||
| summary="HyperFleet API - Cluster Lifecycle Management Service" \ | ||
| description="HyperFleet API for cluster lifecycle management" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: openshift-hyperfleet/hyperfleet-api
Length of output: 61
🏁 Script executed:
git ls-files | grep -i dockerfileRepository: openshift-hyperfleet/hyperfleet-api
Length of output: 89
🏁 Script executed:
cat -n Dockerfile | head -35Repository: openshift-hyperfleet/hyperfleet-api
Length of output: 1414
🌐 Web query:
registry.access.redhat.com ubi9 go-toolset 1.24 available tags versions💡 Result:
For
registry.access.redhat.com/ubi9/go-toolset(Go Toolset 1.24 stream), the tags follow Red Hat’s standard “floating stream + pinned patch + build-id” pattern:Floating stream tags (recommended if you want 1.24.x updates automatically):
1.24latest(typically points at the current supported stream/build)Pinned patch tags (example currently shown in Red Hat’s catalog for Go Toolset 1.24 images):
1.24.6(patch-level pin) [1]Build-specific tags (examples from the catalog; these pin to a specific rebuild):
1.24-17618418781.24.6-1761841878[1]Independent confirmation that the
1.24tag is in active use for the UBI9 Go Toolset image can be seen in OpenShift release content referencing an update toregistry.access.redhat.com/ubi9/go-toolset“Docker tag to v1.24”. [2]If you need the exact current full tag list as returned by the registry, the usual way is:
Sources: [1] [2]
🌐 Web query:
Go 1.24.9 release golang version availability💡 Result:
Go 1.24.9 was an official Go patch release, released on October 13, 2025 [1]. It’s still available for download (source tarball and installers/archives for multiple OS/architectures) on the official downloads page at go.dev/dl under “go1.24.9” [2].
Note: Go 1.24.9 is not the latest 1.24 patch anymore (the 1.24 line continued past it) [1].
Sources: [1] [2]
🌐 Web query:
registry.access.redhat.com ubi9 ubi-micro FIPS glibc boringcrypto💡 Result:
ubi9/ubi-micro) are RHEL 9 userspace, i.e., glibc-based (not musl). Example from a UBI9 container shows glibc 2.34. [1]dlopen+ OpenSSL at runtime, and require dynamic linking with glibc (not static). [3]ubi9/ubi-micro: UBI micro is designed to be extremely small and has no package manager, so you typically won’t have (or be able to easily add) the needed OpenSSL bits unless you add/copy them during a multi-stage build. [4]ubi9/ubi-minimalorubi9/ubiand ensure OpenSSL is present, then run the container on a FIPS-enabled RHEL host so the FIPS provider is activated. [2][3][4]Sources:
[1] https://access.redhat.com/discussions/7097037
[2] https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/epub/9.0_release_notes/bug-fix_high-availability-and-clusters
[3] https://developers.redhat.com/articles/2025/01/23/fips-mode-red-hat-go-toolset
[4] https://www.redhat.com/en/blog/introducing-red-hat-universal-base-image
Align to Go 1.24 with FIPS-compliant build settings.
Line 4 currently uses Go 1.25, and line 29 sets
CGO_ENABLED=0. This deviates from the project requirement: Go 1.24 with FIPS-compliant crypto (CGO_ENABLED=1+GOEXPERIMENT=boringcrypto).Update line 4 to use
registry.access.redhat.com/ubi9/go-toolset:1.24(available in the registry; exact patch level may vary) and line 29 to enable CGO and boringcrypto:Suggested alignment
For the runtime stage (line 1), switch
BASE_IMAGEfromgcr.io/distroless/static-debian12:nonrootto a glibc-based image (e.g.,registry.access.redhat.com/ubi9/ubi-minimal:latest) to support FIPS boringcrypto at runtime.🤖 Prompt for AI Agents
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.
1.25 is what I needed.
"Enable CGO_ENABLED=1 + boringcrypto" — Valid concern, but premature
this is a deliberate tradeoff I already documented in the Dockerfile
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.
@xueli181114, you're absolutely right—I apologize for the confusion. I see now that Go 1.25 is the intended version for this project, and the Dockerfile already documents the deliberate tradeoff at lines 27-29:CGO_ENABLED=0produces a static binary for the distroless runtime, with clear guidance that FIPS-compliant builds would require switching toCGO_ENABLED=1+boringcrypto+ a glibc-based runtime image when needed. My review comment was premature. Thank you for the clarification!✏️ Learnings added
🧠 Learnings used