From c2d1129a31c74ba2f084f207592d32f3c64a8d8d Mon Sep 17 00:00:00 2001 From: Rehan Khan Date: Mon, 4 Nov 2024 13:20:55 +0530 Subject: [PATCH] Made changes with to build via file based catalog Signed-off-by: Rehan Khan --- .github/workflows/build-images.yaml | 16 ++++----- make/catalog.mk | 13 +++++++ script/build_catalog.sh | 55 +++++++++++++++-------------- 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/.github/workflows/build-images.yaml b/.github/workflows/build-images.yaml index 5603cc31..915684d0 100644 --- a/.github/workflows/build-images.yaml +++ b/.github/workflows/build-images.yaml @@ -192,20 +192,18 @@ jobs: else echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV fi - - name: Install opm from OpenShift Mirror - uses: redhat-actions/openshift-tools-installer@v1 - with: - opm: "4.14.4" - - name: Set permissions for build script - run: chmod +x ./script/build_catalog.sh + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - name: Login to Quay.io uses: docker/login-action@v1 with: - registry: ${{ secrets.IMG_REGISTRY_HOST || 'quay.io' }} + registry: ${{ env.IMG_REGISTRY_HOST }} username: ${{ secrets.IMG_REGISTRY_USERNAME }} password: ${{ secrets.IMG_REGISTRY_TOKEN }} - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + - name: Set permissions for build script + run: chmod +x ./script/build_catalog.sh + - name: Git diff + run: git diff - name: build and push catalog (main) if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }} shell: bash diff --git a/make/catalog.mk b/make/catalog.mk index fe9e0ef4..c7068a24 100644 --- a/make/catalog.mk +++ b/make/catalog.mk @@ -32,6 +32,19 @@ catalog: $(OPM) ## Generate catalog content and validate. $(MAKE) $(CATALOG_FILE) BUNDLE_IMG=$(BUNDLE_IMG) cd $(PROJECT_DIR)/catalog && $(OPM) validate authorino-operator-catalog +.PHONY: catalog-multiarch +catalog-multiarch: $(OPM) ## Generate catalog content using architechture specific binaries and validate. + #Initializing the Catalog + @echo "Building catalog for architecture: $(arch)" + -rm -rf $(PROJECT_DIR)/catalog/authorino-operator-catalog + -rm -rf $(PROJECT_DIR)/catalog/authorino-operator-catalog.Dockerfile + -mkdir -p $(PROJECT_DIR)/catalog/authorino-operator-catalog + cd $(PROJECT_DIR)/catalog && $(OPM) generate dockerfile authorino-operator-catalog -i "quay.io/operator-framework/opm:v1.28.0-${arch}" + @echo "creating dir" + $(MAKE) $(CATALOG_FILE) BUNDLE_IMG=$(BUNDLE_IMG) + @echo "leaving dir" + cd $(PROJECT_DIR)/catalog && $(OPM) validate authorino-operator-catalog + # Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'. # Ref https://olm.operatorframework.io/docs/tasks/creating-a-catalog/#catalog-creation-with-raw-file-based-catalogs .PHONY: catalog-build diff --git a/script/build_catalog.sh b/script/build_catalog.sh index 7a7df464..883e85bb 100644 --- a/script/build_catalog.sh +++ b/script/build_catalog.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -# builds the OLM catalog index and pushes it to quay.io. -# +# Builds the OLM catalog index and pushes it to quay.io. # To push to your own registry, override the IMG_REGISTRY_HOST , IMG_REGISTRY_ORG , OPERATOR_NAME and TAG env vars, # i.e: # IMG_REGISTRY_HOST=quay.io IMG_REGISTRY_ORG=yourusername OPERATOR_NAME=authorino-operator TAG=latest ./script/build_catalog.sh @@ -9,32 +8,36 @@ # * a valid login session to a container registry. # * `docker` # * `opm` -# - -# Iterate over tag list i.e. latest 8a17c81d5e9f04545753e5501dddc4a0ac2c7e03 -IFS=' ' read -r -a tags <<< "$TAG" -for tag in "${tags[@]}" -do - # Build & push catalog images for each architecture using the tag - opm index add --build-tool docker --tag "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-amd64" --bundles "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-bundle:${tag}" --binary-image "quay.io/operator-framework/opm:v1.28.0-amd64" - docker push ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-amd64 +set -e # Exit on error - opm index add --build-tool docker --tag "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-ppc64le" --bundles "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-bundle:${tag}" --binary-image "quay.io/operator-framework/opm:v1.28.0-ppc64le" - docker push ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-ppc64le - - opm index add --build-tool docker --tag "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-arm64" --bundles "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-bundle:${tag}" --binary-image "quay.io/operator-framework/opm:v1.28.0-arm64" - docker push ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-arm64 - - opm index add --build-tool docker --tag "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-s390x" --bundles "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-bundle:${tag}" --binary-image "quay.io/operator-framework/opm:v1.28.0-s390x" - docker push ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-s390x +# Split tags into an array +IFS=' ' read -r -a tags <<< "$TAG" +first_tag="${tags[0]}" +architectures=("amd64" "arm64" "ppc64le" "s390x") +# Build and push catalog images for each architecture +for arch in "${architectures[@]}"; do + make catalog-multiarch arch="${arch}" + image_tag="${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${first_tag}-${arch}" + make catalog-build CATALOG_IMG="${image_tag}" + docker push "${image_tag}" & + wait +done - # Create a multi-architecture manifest - docker manifest create --amend ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag} \ - ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-amd64 \ - ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-arm64 \ - ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-ppc64le \ - ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}-s390x +# Tag and push the manifest for tags +for tag in "${tags[@]}"; do + echo "Creating manifest for $TAG" + docker manifest create --amend "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}" \ + ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${first_tag}-amd64 \ + ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${first_tag}-arm64 \ + ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${first_tag}-ppc64le \ + ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${first_tag}-s390x + docker manifest push "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}" + docker rmi "${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag}" || true +done - docker manifest push ${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${tag} +# Clean up images +for arch in "${architectures[@]}"; do + image_tag="${IMG_REGISTRY_HOST}/${IMG_REGISTRY_ORG}/${OPERATOR_NAME}-catalog:${first_tag}-${arch}" + docker rmi "${image_tag}" || true done \ No newline at end of file