diff --git a/.github/workflows/build-push-images.yaml b/.github/workflows/build-push-images.yaml index 9403aaf..db16954 100644 --- a/.github/workflows/build-push-images.yaml +++ b/.github/workflows/build-push-images.yaml @@ -14,6 +14,7 @@ jobs: REGISTRY_USERNAME: netobserv+github_ci REGISTRY_PASSWORD: ${{ secrets.QUAY_SECRET }} REGISTRY_NAMESPACE: netobserv + MULTIARCH_TARGETS: amd64 arm64 ppc64le s390x steps: - name: Checkout the latest code uses: actions/checkout@v2 @@ -24,7 +25,7 @@ jobs: make lint MUST_GATHER_IMAGE=$REGISTRY_NAMESPACE/must-gather - name: Build image run: | - make image-build MUST_GATHER_IMAGE=$REGISTRY_NAMESPACE/must-gather + MULTIARCH_TARGETS="${{ env.MULTIARCH_TARGETS }}" make image-build MUST_GATHER_IMAGE=$REGISTRY_NAMESPACE/must-gather - name: podman login to quay.io uses: redhat-actions/podman-login@v1 with: @@ -37,4 +38,4 @@ jobs: - name: Push image run: | IMAGE_TAG=${{ env.short_sha }} - make build MUST_GATHER_IMAGE=$REGISTRY_NAMESPACE/must-gather + MULTIARCH_TARGETS="${{ env.MULTIARCH_TARGETS }}" make build MUST_GATHER_IMAGE=$REGISTRY_NAMESPACE/must-gather diff --git a/Dockerfile b/Dockerfile index effce1a..924c38a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,12 @@ -FROM quay.io/openshift/origin-must-gather:4.12.0 as builder -FROM quay.io/centos/centos:stream8 +FROM quay.io/centos/centos:stream9 -COPY --from=builder /usr/bin/oc /usr/bin/oc +RUN set -x; \ + OC_TAR_URL="https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/ocp/latest/openshift-client-linux.tar.gz" && \ + curl -L -q -o /tmp/oc.tar.gz "$OC_TAR_URL" && \ + tar -C /usr/bin/ -xvf /tmp/oc.tar.gz oc && \ + ln -sf /usr/bin/oc /usr/bin/kubectl && \ + rm -f /tmp/oc.tar.gz # Copy all collection scripts to /usr/bin COPY collection-scripts/* /usr/bin/ diff --git a/Makefile b/Makefile index 2cc5bac..5372ce7 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,21 @@ TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true) BUILD_VERSION := $(TAG:v%=%) # Image building tool (docker / podman) -ifndef OCI_BIN -ifeq (,$(shell which podman 2>/dev/null)) -OCI_BIN=docker -else -OCI_BIN=podman -endif -endif +# Image building tool (docker / podman) - docker is preferred in CI +OCI_BIN_PATH := $(shell which podman 2>/dev/null || which docker) +OCI_BIN ?= $(shell basename ${OCI_BIN_PATH}) + +# build a single arch target provided as argument +define build_target + echo 'building image for arch $(1)'; \ + DOCKER_BUILDKIT=1 $(OCI_BIN) buildx build --load --platform "$(1)" --output plain -t ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}-$(1):${IMAGE_TAG} -f Dockerfile .; +endef + +# push a single arch target image +define push_target + echo 'pushing image ${IMAGE}-$(1)'; \ + DOCKER_BUILDKIT=1 $(OCI_BIN) push ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}-$(1):${IMAGE_TAG}; +endef # MUST_GATHER_IMAGE needs to be passed explicitly to avoid accidentally pushing to netobserv/must-gather check-image-env: ## Check MUST_GATHER_IMAGE make sure its set. @@ -34,12 +42,13 @@ endif .PHONY: image-build image-build: check-image-env ## Build NetObserv collection image. - $(OCI_BIN) build --build-arg BUILD_VERSION="${BUILD_VERSION}" -t ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}:${IMAGE_TAG} . + trap 'exit' INT; \ + $(foreach target,$(MULTIARCH_TARGETS),$(call build_target,$(target))) .PHONY: image-push image-push: check-image-env ## Push NetObserv collection image. - $(OCI_BIN) push ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}:${IMAGE_TAG} - + trap 'exit' INT; \ + $(foreach target,$(MULTIARCH_TARGETS),$(call push_target,$(target))) .PHONY: help help: ## Display this help.