From a266ff6e8f52f24246009c2db35c5ca0644dee94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Reme=C5=A1?= Date: Tue, 26 Nov 2024 16:23:51 +0100 Subject: [PATCH 1/2] Revert "generate catalog Dockerfile dynamically (#390)" This reverts commit 93075f4f5d6caeacf8329993cc50417e6baced0d. --- build/build_opm_catalog.sh | 13 ++++++------- olm/catalog.Dockerfile | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 olm/catalog.Dockerfile diff --git a/build/build_opm_catalog.sh b/build/build_opm_catalog.sh index 7507fc42..58ce61af 100755 --- a/build/build_opm_catalog.sh +++ b/build/build_opm_catalog.sh @@ -140,12 +140,11 @@ function validate_opm_bundle() { function build_opm_catalog() { log "Updating the catalog index" - mkdir -p olm/catalog + mkdir olm/catalog - ${COMMAND_OPM} generate dockerfile olm/catalog - ${COMMAND_OPM} render ${OLM_BUNDLE_IMAGE_VERSION} -o yaml >> olm/catalog/index.yaml + ${COMMAND_OPM} render ${OLM_BUNDLE_IMAGE_VERSION} -o yaml >> olm/deployment-validation-operator-index/catalog.yaml - cat << EOF >> olm/catalog/index.yaml + cat << EOF >> olm/deployment-validation-operator-index/catalog.yaml --- defaultChannel: alpha name: deployment-validation-operator @@ -159,10 +158,10 @@ entries: skipRange: ">=0.0.1 <${OPERATOR_VERSION}" EOF - cat olm/catalog/index.yaml + cat olm/deployment-validation-operator-index/catalog.yaml log "Validating the catalog" - ${COMMAND_OPM} validate olm/catalog + ${COMMAND_OPM} validate olm/deployment-validation-operator-index log "Building the catalog image" ${CONTAINER_ENGINE} build -f olm/catalog.Dockerfile -t ${OLM_CATALOG_IMAGE_VERSION} @@ -226,4 +225,4 @@ function main() { if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then main -fi \ No newline at end of file +fi diff --git a/olm/catalog.Dockerfile b/olm/catalog.Dockerfile new file mode 100644 index 00000000..5e0335b7 --- /dev/null +++ b/olm/catalog.Dockerfile @@ -0,0 +1,14 @@ +# The builder image is expected to contain +# /bin/opm (with serve subcommand) +FROM quay.io/operator-framework/opm:latest + +# Configure the entrypoint and command +ENTRYPOINT ["/bin/opm"] +CMD ["serve", "/configs", "--cache-dir=/tmp/cache"] + +# Copy FBC root into image at /configs and pre-populate serve cache +ADD deployment-validation-operator-index /configs + +# Set FBC-specific label for the location of the FBC root directory +# in the image +LABEL operators.operatorframework.io.index.configs.v1=/configs From c295d18f23daf153912ca9bc8325b02382aec0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Reme=C5=A1?= Date: Tue, 26 Nov 2024 16:26:02 +0100 Subject: [PATCH 2/2] Revert "Migrate to file based catalog (#388)" This reverts commit bbbe961f83106ca51acd530831052af554d4f845. --- build/build_opm_catalog.sh | 78 +++++++++++++++++++++++++------------- olm/catalog.Dockerfile | 14 ------- 2 files changed, 52 insertions(+), 40 deletions(-) delete mode 100644 olm/catalog.Dockerfile diff --git a/build/build_opm_catalog.sh b/build/build_opm_catalog.sh index 58ce61af..cee1faa4 100755 --- a/build/build_opm_catalog.sh +++ b/build/build_opm_catalog.sh @@ -12,6 +12,8 @@ DIR_MANIFESTS="" GOOS=$(go env GOOS) OPM_VERSION="v1.23.2" COMMAND_OPM="" +GRPCURL_VERSION="1.7.0" +COMMAND_GRPCURL="" export REGISTRY_AUTH_FILE=${CONTAINER_ENGINE_CONFIG_DIR}/config.json @@ -57,6 +59,11 @@ function download_dependencies() { chmod +x opm COMMAND_OPM="$DIR_EXEC/opm" + local grpcurl_url="https://github.com/fullstorydev/grpcurl/releases/download/v$GRPCURL_VERSION/grpcurl_${GRPCURL_VERSION}_${GOOS}_x86_64.tar.gz" + curl -sfL "$grpcurl_url" | tar -xz -O grpcurl > "grpcurl" + chmod +x grpcurl + COMMAND_GRPCURL="$DIR_EXEC/grpcurl" + cd ~- } @@ -139,32 +146,50 @@ function validate_opm_bundle() { } function build_opm_catalog() { - log "Updating the catalog index" - mkdir olm/catalog - - ${COMMAND_OPM} render ${OLM_BUNDLE_IMAGE_VERSION} -o yaml >> olm/deployment-validation-operator-index/catalog.yaml - - cat << EOF >> olm/deployment-validation-operator-index/catalog.yaml ---- -defaultChannel: alpha -name: deployment-validation-operator -schema: olm.package ---- -schema: olm.channel -package: deployment-validation-operator -name: alpha -entries: -- name: deployment-validation-operator.v${OPERATOR_VERSION} - skipRange: ">=0.0.1 <${OPERATOR_VERSION}" -EOF - - cat olm/deployment-validation-operator-index/catalog.yaml - - log "Validating the catalog" - ${COMMAND_OPM} validate olm/deployment-validation-operator-index - - log "Building the catalog image" - ${CONTAINER_ENGINE} build -f olm/catalog.Dockerfile -t ${OLM_CATALOG_IMAGE_VERSION} + local FROM_INDEX="" + local PREV_COMMIT=${PREV_VERSION#*g} # remove versioning and the g commit hash prefix + # check if the previous catalog image is available + if [ "$(${CONTAINER_ENGINE} pull "${OLM_CATALOG_IMAGE}":"${PREV_COMMIT}" &> /dev/null; echo $?)" -eq 0 ]; then + FROM_INDEX="--from-index ${OLM_CATALOG_IMAGE}:${PREV_COMMIT}" + log "Index argument is $FROM_INDEX" + fi + + log "Creating catalog image $OLM_CATALOG_IMAGE_VERSION using opm" + + ${COMMAND_OPM} index add --bundles "$OLM_BUNDLE_IMAGE_VERSION" \ + --tag "$OLM_CATALOG_IMAGE_VERSION" \ + --build-tool "$(basename "$CONTAINER_ENGINE" | awk '{print $1}')" \ + $FROM_INDEX +} + +function validate_opm_catalog() { + log "Checking that catalog we have built returns the correct version $OPERATOR_VERSION" + + local free_port="" + local container_id="" + local catalog_current_version="" + + free_port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()') + + log "Running $OLM_CATALOG_IMAGE_VERSION and exposing $free_port" + container_id=$(${CONTAINER_ENGINE} run -d -p "$free_port:50051" "$OLM_CATALOG_IMAGE_VERSION") + + log "Getting current version from running catalog" + catalog_current_version=$( + ${COMMAND_GRPCURL} -plaintext -d '{"name": "'"$OPERATOR_NAME"'"}' \ + "localhost:$free_port" api.Registry/GetPackage | \ + jq -r '.channels[] | select(.name=="'"$OLM_CHANNEL"'") | .csvName' | \ + sed "s/$OPERATOR_NAME\.//" + ) + log " catalog version: $catalog_current_version" + + log "Removing docker container $container_id" + ${CONTAINER_ENGINE} rm -f "$container_id" + + if [[ "$catalog_current_version" != "v$OPERATOR_VERSION" ]]; then + log "Version from catalog $catalog_current_version != v$OPERATOR_VERSION" + return 1 + fi } function update_versions_repo() { @@ -213,6 +238,7 @@ function main() { validate_opm_bundle build_opm_catalog + validate_opm_catalog if [[ -n "${APP_SRE_BOT_PUSH_TOKEN:-}" ]]; then update_versions_repo diff --git a/olm/catalog.Dockerfile b/olm/catalog.Dockerfile deleted file mode 100644 index 5e0335b7..00000000 --- a/olm/catalog.Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -# The builder image is expected to contain -# /bin/opm (with serve subcommand) -FROM quay.io/operator-framework/opm:latest - -# Configure the entrypoint and command -ENTRYPOINT ["/bin/opm"] -CMD ["serve", "/configs", "--cache-dir=/tmp/cache"] - -# Copy FBC root into image at /configs and pre-populate serve cache -ADD deployment-validation-operator-index /configs - -# Set FBC-specific label for the location of the FBC root directory -# in the image -LABEL operators.operatorframework.io.index.configs.v1=/configs