From d3d81a0e9d709d85d61ba08d6ce99fe3f64c76de Mon Sep 17 00:00:00 2001 From: Jean-Marc ANDRE Date: Thu, 20 Apr 2023 09:28:30 +0200 Subject: [PATCH] buildah instead of docker --- Dockerfile | 5 +++-- Makefile | 25 +------------------------ 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8f9cca1..4f23fb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ # Build the manager binary -FROM golang:1.19 as builder +FROM --platform=${BUILDPLATFORM} golang:1.19 as builder ARG TARGETOS ARG TARGETARCH +ARG TARGETPLATFORM WORKDIR /workspace # Copy the Go Modules manifests @@ -25,7 +26,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ma # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot +FROM --platform=${TARGETPLATFORM} gcr.io/distroless/static:nonroot WORKDIR / COPY --from=builder /workspace/manager . USER 65532:65532 diff --git a/Makefile b/Makefile index af5b974..a3276e9 100644 --- a/Makefile +++ b/Makefile @@ -71,38 +71,15 @@ run: manifests generate fmt vet ## Run a controller from your host. go run ./main.go PLATFORMS ?= linux/arm64,linux/amd64 -# If you wish built the manager image targeting other platforms you can use the --platform flag. -# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it. -# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ -.PHONY: docker-build -docker-build: test ## Build docker image with the manager. - docker build -t ${IMG} . - .PHONY: docker-build-multiarch docker-build-multiarch: - buildah bud --manifest $(MANIFEST) --platform=$(PLATFORMS) --layers Dockerfile.multi + buildah bud --manifest $(MANIFEST) --platform=$(PLATFORMS) --layers . .PHONY: docker-push docker-push: ## Push docker image with the manager. buildah manifest push --all --rm $(MANIFEST) "docker://$(IMG)" #docker push ${IMG} -# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple -# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: -# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/ -# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/ -# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=> then the export will fail) -# To properly provided solutions that supports more than one platform you should use this option. -.PHONY: docker-buildx -docker-buildx: test ## Build and push docker image for the manager for cross-platform support - # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - - docker buildx create --name project-v3-builder - docker buildx use project-v3-builder - - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . - - docker buildx rm project-v3-builder - rm Dockerfile.cross - ##@ Deployment ifndef ignore-not-found