You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2022/04/18 09:18:05 UTC

[camel-k] 02/12: Updates the opm version and modifies the build-index-image script

This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit d9b9d74c99cbbce706646c10626b19d51ab9d0e8
Author: phantomjinx <p....@phantomjinx.co.uk>
AuthorDate: Tue Feb 8 17:52:08 2022 +0000

    Updates the opm version and modifies the build-index-image script
    
    * Makefile
     * Adds opm installation in the same manner as kustomize
     * Latest version supports http and skipping tls verification on unsecure
       registries
    
    * action.yaml
     * Delegate fetching opm to the Makefile
    
    * build-index-image.sh
     * Updates `opm render` to latest switches for opm version
     * Fixes for more reliable script execution
---
 .github/actions/kamel-build-bundle/action.yaml     | 11 +++----
 .../kamel-build-bundle/build-index-image.sh        | 37 +++++++++++++++++-----
 .gitignore                                         |  4 +++
 script/Makefile                                    | 23 ++++++++++++++
 4 files changed, 61 insertions(+), 14 deletions(-)

diff --git a/.github/actions/kamel-build-bundle/action.yaml b/.github/actions/kamel-build-bundle/action.yaml
index cba7333b3..b61da1231 100644
--- a/.github/actions/kamel-build-bundle/action.yaml
+++ b/.github/actions/kamel-build-bundle/action.yaml
@@ -58,12 +58,11 @@ runs:
       name: Install opm if required
       shell: bash
       run: |
-        if ! command -v opm &> /dev/null
-        then
-          curl -L https://github.com/operator-framework/operator-registry/releases/download/v1.19.5/linux-amd64-opm -o opm
-          chmod +x opm
-          sudo mv opm /usr/local/bin/
-        fi
+        make opm
+
+        # Append to PATH if not already
+        echo "${{ env.GOPATH }}/bin" >> $GITHUB_PATH
+        which opm || { echo 'opm not found' ; exit 1; }
 
     - id: build-index-image
       name: Create New Index Image
diff --git a/.github/actions/kamel-build-bundle/build-index-image.sh b/.github/actions/kamel-build-bundle/build-index-image.sh
index e708e6581..cbd44b09c 100755
--- a/.github/actions/kamel-build-bundle/build-index-image.sh
+++ b/.github/actions/kamel-build-bundle/build-index-image.sh
@@ -116,7 +116,7 @@ if [ "${PULL_REGISTRY}" != "${PUSH_REGISTRY}" ]; then
   #
 
   PULL_HOST=$(echo ${PULL_REGISTRY} | sed -e 's/\(.*\):.*/\1/')
-  PULL_PORT=$(echo ${PULL_REGISTRY} | sed -e 's/.*:\([0-9]\+\).*/\1/')
+  PULL_PORT=$(echo ${PULL_REGISTRY} | sed -ne 's/.*:\([0-9]\+\).*/\1/p')
   if [ -z "${PULL_PORT}" ]; then
     # Use standard http port
     PULL_PORT=80
@@ -128,7 +128,10 @@ if [ "${PULL_REGISTRY}" != "${PUSH_REGISTRY}" ]; then
   # Update both ipv4 and ipv6 addresses if they exist
   # 127.0.0.1 localhost
   # ::1     localhost ip6-localhost ip6-loopback
-  sudo sed -i "s/\(localhost.*\)/\1 ${PULL_HOST}/g" /etc/hosts
+  #
+  # Only add PULL_HOST if not already added (avoids repeated appended)
+  #
+  sudo sed -i "/${PULL_HOST}/!s/localhost /&${PULL_HOST} /" /etc/hosts
 
   #
   # Bring up the registry:2 instance if not already started
@@ -144,21 +147,35 @@ if [ "${PULL_REGISTRY}" != "${PUSH_REGISTRY}" ]; then
   #
   # Tag the bundle image
   #
+  echo "Tagging bundle image ..."
   docker tag \
     ${PUSH_REGISTRY}/${IMAGE_NAMESPACE}/camel-k-bundle:${IMAGE_VERSION} \
     ${BUNDLE_IMAGE}
 
   # Push the bundle image to the registry
   #
+  echo "Pushing bundle image ..."
   docker push ${BUNDLE_IMAGE}
 fi
 
 #
 # Construct an index image containing the newly built bundle image
-mkdir catalog
-opm render quay.io/operatorhubio/catalog:latest -o yaml > catalog/bundles.yaml
-sudo opm render --skip-tls ${BUNDLE_IMAGE} > catalog/camel-k.yaml
-cat << EOF >> catalog/camel-k.yaml
+#
+echo "Constructing index image ..."
+
+#
+# Removes catalog directory if already exists.
+# Stops opm from aborting due to existing directory.
+#
+CATALOG_DIR=catalog
+if [ -d ${CATALOG_DIR} ]; then
+  rm -rf ${CATALOG_DIR}
+fi
+
+mkdir ${CATALOG_DIR}
+opm render quay.io/operatorhubio/catalog:latest -o yaml > ${CATALOG_DIR}/bundles.yaml
+sudo opm render --use-http -o yaml ${BUNDLE_IMAGE} > ${CATALOG_DIR}/camel-k.yaml
+cat << EOF >> ${CATALOG_DIR}/camel-k.yaml
 ---
 schema: olm.channel
 package: camel-k
@@ -166,8 +183,12 @@ name: stable-$(make get-version | grep -Po "\d.\d")
 entries:
   - name: camel-k.v$(make get-version | grep -Po "\d.\d.\d")
 EOF
-opm validate catalog
-opm alpha generate dockerfile catalog
+opm validate ${CATALOG_DIR}
+opm generate dockerfile ${CATALOG_DIR}
+if [ ! -f catalog.Dockerfile ]; then
+  echo "Error: Failed to create catalog dockerfile"
+  exit 1
+fi
 docker build . -f catalog.Dockerfile -t ${LOCAL_IIB}
 docker push ${LOCAL_IIB}
 BUILD_BUNDLE_LOCAL_IMAGE_BUNDLE_INDEX="${REGISTRY_PULL_HOST}/${IMAGE_NAMESPACE}/camel-k-iib:${IMAGE_VERSION}"
diff --git a/.gitignore b/.gitignore
index dfa66a7a1..3c195619b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,10 @@
 # Bundle directory
 /bundle
 
+# Catalog directory
+/catalog
+catalog.Dockerfile
+
 # IDEs
 .idea
 *.iml
diff --git a/script/Makefile b/script/Makefile
index 83b7dcb47..37ea17b1a 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -29,6 +29,9 @@ BASE_IMAGE := adoptopenjdk/openjdk11:slim
 LOCAL_REPOSITORY := /tmp/artifacts/m2
 IMAGE_NAME := docker.io/apache/camel-k
 
+OPM_VERSION := v1.21.0 # <- Not yet released
+OPM_PKG := github.com/operator-framework/operator-registry
+
 #
 # Situations when user wants to override
 # the image name and version
@@ -392,6 +395,8 @@ else
 CONTROLLER_GEN=$(shell command -v controller-gen 2> /dev/null)
 endif
 
+.PHONY: kubectl kustomize operator-sdk opm
+
 kubectl:
 ifeq (, $(shell command -v kubectl 2> /dev/null))
 	$(error "No kubectl found in PATH. Please install and re-run")
@@ -438,6 +443,24 @@ else
 OPERATOR_SDK=$(shell command -v operator-sdk 2> /dev/null)
 endif
 
+opm:
+ifeq (, $(shell which opm))
+	@{ \
+	set -e ;\
+	OPM_GEN_TMP_DIR=$$(mktemp -d) ;\
+	cd $$OPM_GEN_TMP_DIR ;\
+	go mod init tmp ;\
+	go get \
+		-ldflags '-w -extldflags "-static"' -tags "json1" \
+		-ldflags "-X '$(OPM_PKG)/cmd/opm/version.opmVersion=$(OPM_VERSION)'" \
+		$(OPM_PKG)/cmd/opm@$(OPM_VERSION) ;\
+		rm -rf $$OPM_GEN_TMP_DIR ;\
+	}
+OPM=$(GOBIN)/opm
+else
+OPM=$(shell which opm)
+endif
+
 .PHONY: generate-crd $(BUNDLE_CAMEL_APIS) bundle bundle-build
 
 # - Have to copy pkg/apis since it is a module in its own right