Skip to content

Commit

Permalink
Use buildah instead of docker, support multi-arch builds (kubevirt#115)
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 <[email protected]>

* Build sanity.test statically

Avoid failure when the binary is built with Fedora 36 and thus
requires newer glibc symbols than the container.

Signed-off-by: Maya Rashish <[email protected]>

* Switch to buildah & podman, 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.
- Full DOCKER_REPO name is used, as podman-like tools have odd behavior
  with short names.

Signed-off-by: Maya Rashish <[email protected]>

* Tolerate docker instead of podman

Signed-off-by: Maya Rashish <[email protected]>

* Only add --tls-verify=false if the registry matches localhost*

Add a message about this, too

Signed-off-by: Maya Rashish <[email protected]>
  • Loading branch information
maya-r authored and awels committed Jun 16, 2023
1 parent f386d1b commit 4239d3a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 106 deletions.
61 changes: 44 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,85 @@ KUBEVIRT_PROVIDER?=k8s-1.22
HPP_IMAGE?=hostpath-provisioner
HPP_CSI_IMAGE?=hostpath-csi-driver
TAG?=latest
DOCKER_REPO?=kubevirt
DOCKER_REPO?=quay.io/kubevirt
ARTIFACTS_PATH?=_out
GOLANG_VER?=1.16.8
GOOS?=linux
GOARCH?=amd64
BUILDAH_PLATFORM_FLAG?=--platform $(GOOS)/$(GOARCH)
OCI_BIN ?= $(shell if podman ps >/dev/null 2>&1; then echo podman; elif docker ps >/dev/null 2>&1; then echo docker; fi)

export GOLANG_VER
export KUBEVIRT_PROVIDER
export DOCKER_REPO
export GOOS
export GOARCH
export OCI_BIN

all: controller hostpath-provisioner

hostpath-provisioner:
GOLANG_VER=${GOLANG_VER} ./hack/build-provisioner.sh
./hack/build-provisioner.sh

hostpath-csi-driver:
GOLANG_VER=${GOLANG_VER} ./hack/build-csi.sh
./hack/build-csi.sh

image: image-controller image-csi

push: push-controller push-csi
push: clean manifest manifest-push

push-controller: hostpath-provisioner image
docker push $(DOCKER_REPO)/$(HPP_IMAGE):$(TAG)
manifest: manifest-controller manifest-csi

manifest-push: push-csi push-controller

image-controller: hostpath-provisioner
docker build -t $(DOCKER_REPO)/$(HPP_IMAGE):$(TAG) -f Dockerfile.controller .
buildah build $(BUILDAH_PLATFORM_FLAG) -t $(DOCKER_REPO)/$(HPP_IMAGE):$(GOARCH) -f Dockerfile.controller .

image-csi: hostpath-csi-driver
docker build -t $(DOCKER_REPO)/$(HPP_CSI_IMAGE):$(TAG) -f Dockerfile.csi .
buildah build $(BUILDAH_PLATFORM_FLAG) -t $(DOCKER_REPO)/$(HPP_CSI_IMAGE):$(GOARCH) -f Dockerfile.csi .

manifest-controller: image-controller
-buildah manifest create $(DOCKER_REPO)/$(HPP_IMAGE):local
buildah manifest add --arch $(GOARCH) $(DOCKER_REPO)/$(HPP_IMAGE):local containers-storage:$(DOCKER_REPO)/$(HPP_IMAGE):$(GOARCH)

manifest-csi: image-csi
-buildah manifest create $(DOCKER_REPO)/$(HPP_CSI_IMAGE):local
buildah manifest add --arch $(GOARCH) $(DOCKER_REPO)/$(HPP_CSI_IMAGE):local containers-storage:$(DOCKER_REPO)/$(HPP_CSI_IMAGE):$(GOARCH)

push-csi: hostpath-csi-driver image-csi
docker push $(DOCKER_REPO)/$(HPP_CSI_IMAGE):$(TAG)
push-csi:
buildah manifest push $(BUILDAH_PUSH_FLAGS) --all $(DOCKER_REPO)/$(HPP_CSI_IMAGE):local docker://$(DOCKER_REPO)/$(HPP_CSI_IMAGE):$(TAG)

clean:
push-controller:
buildah manifest push $(BUILDAH_PUSH_FLAGS) --all $(DOCKER_REPO)/$(HPP_IMAGE):local docker://$(DOCKER_REPO)/$(HPP_IMAGE):$(TAG)

clean: manifest-clean
rm -rf _out

manifest-clean:
-buildah manifest rm $(DOCKER_REPO)/$(HPP_IMAGE):local
-buildah manifest rm $(DOCKER_REPO)/$(HPP_CSI_IMAGE):local

build: clean hostpath-provisioner hostpath-csi-driver

cluster-up:
KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} ./cluster-up/up.sh
./cluster-up/up.sh

cluster-down:
KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} ./cluster-up/down.sh
./cluster-up/down.sh

cluster-sync: cluster-clean
KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} ./cluster-sync/sync.sh
./cluster-sync/sync.sh

cluster-clean:
KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} ./cluster-sync/clean.sh
./cluster-sync/clean.sh

test:
GOLANG_VER=${GOLANG_VER} ./hack/run-unit-test.sh
./hack/run-unit-test.sh
hack/language.sh

test-functional:
go mod vendor
KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} gotestsum --format short-verbose --junitfile ${ARTIFACTS_PATH}/junit.functest.xml -- ./tests/... -kubeconfig="../_ci-configs/$(KUBEVIRT_PROVIDER)/.kubeconfig"

test-sanity:
GOLANG_VER=${GOLANG_VER} DOCKER_REPO=${DOCKER_REPO} hack/sanity.sh
hack/sanity.sh
6 changes: 5 additions & 1 deletion cluster-sync/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ for i in $(seq 1 ${KUBEVIRT_NUM_NODES}); do
done

registry=${IMAGE_REGISTRY:-localhost:$(_port registry)}
DOCKER_REPO=${registry} make push
if [[ ${registry} == localhost* ]]; then
echo "not verifying tls, registry contains localhost"
export BUILDAH_PUSH_FLAGS="--tls-verify=false"
fi
DOCKER_REPO=${registry} make manifest manifest-push

if [ ! -z $UPGRADE_FROM ]; then
_kubectl apply -f https://github.com/kubevirt/hostpath-provisioner-operator/releases/download/$UPGRADE_FROM/namespace.yaml
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
google.golang.org/grpc v1.38.0
gotest.tools/gotestsum v1.7.0 // indirect
k8s.io/api v0.22.2
k8s.io/apiextensions-apiserver v0.22.2
k8s.io/apimachinery v0.22.2
Expand Down
Loading

0 comments on commit 4239d3a

Please sign in to comment.