Skip to content
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

update container build to use builder pattern #39

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

BlaineEXE
Copy link
Contributor

@BlaineEXE BlaineEXE commented Feb 25, 2025

Update the Dockerfile (and thus Makefile) to use the container builder pattern. This makes it easy to build a container image for any architecture, and it makes it certain that the binary built matches the container.

Importantly, this should fix the ARM builds that are currently broken.

Note: the Dockerfile and make target are based directly on those bootstrapped by kubebuilder init, slightly adjusted for the Ceph-COSI repo structure. This includes comments related to the builder pattern as well as usage of a nonroot container image (and nonroot user).

Update the Dockerfile (and thus Makefile) to use the container builder
pattern. This makes it easy to build a container image for any
architecture, and it makes it certain that the binary built matches the
container.

Importantly, this should fix the ARM builds that are currently broken.

Signed-off-by: Blaine Gardner <blaine.gardner@ibm.com>
@thotz
Copy link
Collaborator

thotz commented Feb 28, 2025

@BlaineEXE : can you please paste the O/P of make commands as well

@BlaineEXE
Copy link
Contributor Author

What is O/P ?

@thotz
Copy link
Collaborator

thotz commented Mar 3, 2025

What is O/P ?

Sorry I meant output of following command:

make build
make container

@BlaineEXE
Copy link
Contributor Author

BlaineEXE commented Mar 7, 2025

make build hasn't changed.

$ make build
mkdir -p bin
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X main.version=6834558501b5f73b0883a7d750dc78bd8177cb64 -extldflags "-static"' -o ./bin/ceph-cosi-driver ./cmd/ceph-cosi-driver
if [ "$ARCH" = "amd64" ]; then \
                CGO_ENABLED=0 GOOS=windows go build -a -ldflags '-X main.version=6834558501b5f73b0883a7d750dc78bd8177cb64 -extldflags "-static"' -o ./bin/ceph-cosi-driver.exe ./cmd/ceph-cosi-driver ; \
                CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -a -ldflags '-X main.version=6834558501b5f73b0883a7d750dc78bd8177cb64 -extldflags "-static"' -o ./bin/ceph-cosi-driver-ppc64le ./cmd/ceph-cosi-driver ; \
        fi

make container now builds using the docker builder pattern that helps ensure the built binary and end container both have the same architecture. The Dockerfile is based on kubebuilder's template, which is also the template the COSI controller and sidecar were moved to a few months ago. This is preferred especially because it works nicely with docker buildx that makes crossbuilding manifests easier than managing manifests manually.

$ make container                                                                                                             20s
podman build --tag ceph-cosi-driver:latest --label revision=6834558501b5f73b0883a7d750dc78bd8177cb64 .
[1/2] STEP 1/10: FROM golang:1.22 AS builder
[1/2] STEP 2/10: ARG TARGETOS
--> fea0d7541997
[1/2] STEP 3/10: ARG TARGETARCH
--> ee46abc37b38
[1/2] STEP 4/10: WORKDIR /workspace
--> b9c642f40a26
[1/2] STEP 5/10: COPY go.mod go.mod
--> c13e43e7e514
[1/2] STEP 6/10: COPY go.sum go.sum
--> cd2c352b0883
[1/2] STEP 7/10: RUN go mod download
--> 032ec2222d40
[1/2] STEP 8/10: COPY cmd/ cmd/
--> 93a159217480
[1/2] STEP 9/10: COPY pkg/ pkg/
--> 362e8549a6a6
[1/2] STEP 10/10: RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ceph-cosi-driver cmd/ceph-cosi-driver/*.go
--> 244b3f983407
[2/2] STEP 1/8: FROM gcr.io/distroless/static:nonroot
[2/2] STEP 2/8: LABEL maintainers="Ceph COSI Authors"
--> Using cache dcc529e5ade2dc34cde62e85b83e865f6ded1e208fe9b6d1ed755a3794570428
--> dcc529e5ade2
[2/2] STEP 3/8: LABEL description="Ceph COSI driver"
--> Using cache 9c872e80e57b92ae951aac396f5c8ee1bb62170768a4b8ffd51e74c90945d417
--> 9c872e80e57b
[2/2] STEP 4/8: WORKDIR /
--> Using cache ae8f09a7c6fde6e9c109c33b79d980ca9d09c4e4309f2de5257be01c4934219f
--> ae8f09a7c6fd
[2/2] STEP 5/8: COPY --from=builder /workspace/ceph-cosi-driver .
--> 910e0395169e
[2/2] STEP 6/8: USER 65532:65532
--> 494897455352
[2/2] STEP 7/8: ENTRYPOINT ["/ceph-cosi-driver"]
--> 773a1b153da6
[2/2] STEP 8/8: LABEL "revision"="6834558501b5f73b0883a7d750dc78bd8177cb64"
[2/2] COMMIT ceph-cosi-driver:latest
--> 10970158890a
Successfully tagged localhost/ceph-cosi-driver:latest
10970158890a0908dd948f493c688d6646cf0eae6019868ab39a781fa804f910

@thotz
Copy link
Collaborator

thotz commented Mar 10, 2025

LGTM approved

@thotz thotz merged commit 6c3c82e into ceph:master Mar 10, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants