Skip to content

Commit

Permalink
Use buildah instead of docker, support multi-arch builds (#243)
Browse files Browse the repository at this point in the history
* 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 <mrashish@redhat.com>

* 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 <mrashish@redhat.com>

* Remove unused BUILDAH_PUSH_FLAGS

Signed-off-by: Maya Rashish <mrashish@redhat.com>
  • Loading branch information
maya-r authored Aug 3, 2022
1 parent b11e9a5 commit 717af8d
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,53 @@
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

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; \
docker build -t $(DOCKER_REPO)/$(OPERATOR_IMAGE):$(TAG) -f Dockerfile .
./hack/version.sh ./_out; \
buildah build $(BUILDAH_PLATFORM_FLAG) -t $(DOCKER_REPO)/$(OPERATOR_IMAGE):$(GOARCH) -f Dockerfile .

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: image
docker push $(DOCKER_REPO)/$(OPERATOR_IMAGE):$(TAG)
push: clean manifest manifest-push

manifest-push:
buildah manifest push --all $(DOCKER_REPO)/$(OPERATOR_IMAGE):local docker://$(DOCKER_REPO)/$(OPERATOR_IMAGE):$(TAG)

generate:
./hack/update-codegen.sh

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; \
Expand Down

0 comments on commit 717af8d

Please sign in to comment.