Skip to content

Commit

Permalink
Merge pull request #123 from clobrano/build-file-based-catalog-0
Browse files Browse the repository at this point in the history
Build file-based catalog
  • Loading branch information
clobrano authored Mar 5, 2024
2 parents 8e3e24b + 1ba63fd commit 84e63f8
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ SORT_IMPORTS_VERSION = v0.2.1
# OCP Version: for OKD bundle community
OCP_VERSION = 4.12

BLUE_ICON_PATH = "./config/assets/medik8s_blue_icon.png"

# VERSION defines the project version for the bundle.
# Update this value when you upgrade the version of your project.
# To re-generate a bundle for another specific version without changing the standard setup, you can:
Expand Down Expand Up @@ -84,6 +86,9 @@ export IMAGE_TAG
# medik8s/machine-deletion-remediation-bundle:$(IMAGE_TAG) and medik8s/machine-deletion-remediation-catalog:$(IMAGE_TAG).
IMAGE_TAG_BASE ?= $(IMAGE_REGISTRY)/$(OPERATOR_NAME)

# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-operator-catalog:$(IMAGE_TAG)

# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-operator-bundle:$(IMAGE_TAG)
Expand Down Expand Up @@ -293,7 +298,7 @@ bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metada
$(MAKE) bundle-validate

## Some addition to bundle creation in the bundle
DEFAULT_ICON_BASE64 := $(shell base64 --wrap=0 ./config/assets/medik8s_blue_icon.png)
DEFAULT_ICON_BASE64 := $(shell base64 --wrap=0 ${BLUE_ICON_PATH})
export ICON_BASE64 ?= ${DEFAULT_ICON_BASE64}
export CSV="./bundle/manifests/$(OPERATOR_NAME).clusterserviceversion.yaml"

Expand Down Expand Up @@ -347,11 +352,50 @@ bundle-run: operator-sdk ## Run bundle image
bundle-cleanup: operator-sdk ## Remove bundle installed via bundle-run
$(OPERATOR_SDK) -n $(BUNDLE_RUN_NAMESPACE) cleanup $(OPERATOR_NAME)

# Build a file-based catalog image
# https://docs.openshift.com/container-platform/4.14/operators/admin/olm-managing-custom-catalogs.html#olm-managing-custom-catalogs-fb
# NOTE: CATALOG_DIR and CATALOG_DOCKERFILE items won't be deleted in case of recipe's failure
CATALOG_DIR := catalog
CATALOG_DOCKERFILE := ${CATALOG_DIR}.Dockerfile
CATALOG_INDEX := $(CATALOG_DIR)/index.yaml

.PHONY: add_channel_entry_for_the_bundle
add_channel_entry_for_the_bundle:
@echo "---" >> ${CATALOG_INDEX}
@echo "schema: olm.channel" >> ${CATALOG_INDEX}
@echo "package: ${OPERATOR_NAME}" >> ${CATALOG_INDEX}
@echo "name: ${CHANNELS}" >> ${CATALOG_INDEX}
@echo "entries:" >> ${CATALOG_INDEX}
@echo " - name: ${OPERATOR_NAME}.v${VERSION}" >> ${CATALOG_INDEX}

.PHONY: catalog-build
catalog-build: opm ## Build a file-based catalog image.
# Remove the catalog directory and Dockerfile if they exist
-rm -r ${CATALOG_DIR} ${CATALOG_DOCKERFILE}
@mkdir -p ${CATALOG_DIR}
$(OPM) generate dockerfile ${CATALOG_DIR}
$(OPM) init ${OPERATOR_NAME} \
--default-channel=${CHANNELS} \
--description=./README.md \
--icon=${BLUE_ICON_PATH} \
--output yaml \
> ${CATALOG_INDEX}
$(OPM) render ${BUNDLE_IMG} --output yaml >> ${CATALOG_INDEX}
$(MAKE) add_channel_entry_for_the_bundle
$(OPM) validate ${CATALOG_DIR}
docker build . -f ${CATALOG_DOCKERFILE} -t ${CATALOG_IMG}
# Clean up the catalog directory and Dockerfile
rm -r ${CATALOG_DIR} ${CATALOG_DOCKERFILE}

.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

##@ Targets used by CI

.PHONY: container-build
container-build: ## Build containers
make docker-build bundle-build
make docker-build bundle-build catalog-build catalog-push

.PHONY: container-push
container-push: ## Push containers
Expand Down

0 comments on commit 84e63f8

Please sign in to comment.