Skip to content

Commit

Permalink
Made changes with to build via file based catalog
Browse files Browse the repository at this point in the history
Signed-off-by: Rehan Khan <[email protected]>
  • Loading branch information
R3hankhan123 committed Nov 4, 2024
1 parent 0f0fb43 commit c2d1129
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 35 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions make/catalog.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 29 additions & 26 deletions script/build_catalog.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit c2d1129

Please sign in to comment.