-
Notifications
You must be signed in to change notification settings - Fork 18
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
update container build to use builder pattern #39
Conversation
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>
@BlaineEXE : can you please paste the O/P of make commands as well |
What is O/P ? |
Sorry I meant output of following command:
|
$ 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 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
|
LGTM approved |
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).