From c8ad301750801fea83127beaa22d6c592ff56bf3 Mon Sep 17 00:00:00 2001 From: Maya Rashish Date: Tue, 5 Jul 2022 23:12:32 +0300 Subject: [PATCH 1/3] Instead of passing environment variables, export them in Makefile This passes them to all subprocesses, but they can still be overridden due to the ?= construct. Signed-off-by: Maya Rashish --- Makefile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index fe89dbd4..b397b06c 100644 --- a/Makefile +++ b/Makefile @@ -16,23 +16,26 @@ OPERATOR_IMAGE?=hostpath-provisioner-operator TAG?=latest DOCKER_REPO?=quay.io/kubevirt +export GOLANG_VER +export TAG + all: test build operator: - GOLANG_VER=${GOLANG_VER} ./hack/build-operator.sh + ./hack/build-operator.sh mounter: - GOLANG_VER=${GOLANG_VER} ./hack/build-mounter.sh + ./hack/build-mounter.sh csv-generator: - GOLANG_VER=${GOLANG_VER} ./hack/build-csv-generator.sh + ./hack/build-csv-generator.sh crd-generator: generate-crd - GOLANG_VER=${GOLANG_VER} ./hack/build-crd-generator.sh + ./hack/build-crd-generator.sh _out/crd-generator --sourcefile=./deploy/operator.yaml --outputDir=./tools/helper image: operator mounter csv-generator - TAG=$(TAG) ./hack/version.sh ./_out; \ + ./hack/version.sh ./_out; \ docker build -t $(DOCKER_REPO)/$(OPERATOR_IMAGE):$(TAG) -f Dockerfile . push: image From 68ef62387a61209edbd64df3b373fb4f215d6f86 Mon Sep 17 00:00:00 2001 From: Maya Rashish Date: Wed, 6 Jul 2022 00:48:21 +0300 Subject: [PATCH 2/3] Switch to buildah, enable multi-arch builds Now we can run: make clean && \ GOARCH=arm64 make manifest && GOARCH=amd64 make manifest && \ make manifest-push And spit out a manifest for both arm64 and amd64, in the same image. Caveats: - We have a special 'manifest-clean' target, as we can add arbitrarily many images to a manifest and don't want the old ones. Delete old image in case a regular non-manifest image exists by the same name, too. - The push and image/manifest creation are split, so we can run the image creation for more than one architecture and push the combined manifest including both. - We keep `make push` behaving the same to avoid breaking CI. Signed-off-by: Maya Rashish --- Makefile | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b397b06c..80219a03 100644 --- a/Makefile +++ b/Makefile @@ -15,9 +15,14 @@ OPERATOR_IMAGE?=hostpath-provisioner-operator TAG?=latest DOCKER_REPO?=quay.io/kubevirt +GOOS?=linux +GOARCH?=amd64 +BUILDAH_PLATFORM_FLAG?=--platform $(GOOS)/$(GOARCH) export GOLANG_VER export TAG +export GOOS +export GOARCH all: test build @@ -36,10 +41,16 @@ crd-generator: generate-crd image: operator mounter csv-generator ./hack/version.sh ./_out; \ - docker build -t $(DOCKER_REPO)/$(OPERATOR_IMAGE):$(TAG) -f Dockerfile . + buildah build $(BUILDAH_PLATFORM_FLAG) -t $(DOCKER_REPO)/$(OPERATOR_IMAGE):$(GOARCH) -f Dockerfile . -push: image - docker push $(DOCKER_REPO)/$(OPERATOR_IMAGE):$(TAG) +manifest: image + -buildah manifest create $(DOCKER_REPO)/$(OPERATOR_IMAGE):local + buildah manifest add --arch $(GOARCH) $(DOCKER_REPO)/$(OPERATOR_IMAGE):local containers-storage:$(DOCKER_REPO)/$(OPERATOR_IMAGE):$(GOARCH) + +push: clean manifest manifest-push + +manifest-push: + buildah manifest push $(BUILDAH_PUSH_FLAGS) --all $(DOCKER_REPO)/$(OPERATOR_IMAGE):local docker://$(DOCKER_REPO)/$(OPERATOR_IMAGE):$(TAG) generate: ./hack/update-codegen.sh @@ -47,7 +58,10 @@ generate: generate-crd: ./hack/generate-crd.sh -clean: +manifest-clean: + -buildah manifest rm $(DOCKER_REPO)/$(OPERATOR_IMAGE):local + +clean: manifest-clean GO111MODULE=on; \ go mod tidy; \ go mod vendor; \ From f3091543af3ba4c6ba6f4c6fcd22ef969d9bd926 Mon Sep 17 00:00:00 2001 From: Maya Rashish Date: Wed, 3 Aug 2022 16:36:33 +0300 Subject: [PATCH 3/3] Remove unused BUILDAH_PUSH_FLAGS Signed-off-by: Maya Rashish --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 80219a03..d65e4386 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ manifest: image push: clean manifest manifest-push manifest-push: - buildah manifest push $(BUILDAH_PUSH_FLAGS) --all $(DOCKER_REPO)/$(OPERATOR_IMAGE):local docker://$(DOCKER_REPO)/$(OPERATOR_IMAGE):$(TAG) + buildah manifest push --all $(DOCKER_REPO)/$(OPERATOR_IMAGE):local docker://$(DOCKER_REPO)/$(OPERATOR_IMAGE):$(TAG) generate: ./hack/update-codegen.sh