Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 26 additions & 52 deletions build/build_opm_catalog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ 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

Expand Down Expand Up @@ -59,11 +57,6 @@ 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 ~-
}

Expand Down Expand Up @@ -146,50 +139,32 @@ function validate_opm_bundle() {
}

function build_opm_catalog() {
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
log "Updating the catalog index"
mkdir olm/deployment-validation-operator-index

${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}
}

function update_versions_repo() {
Expand Down Expand Up @@ -238,7 +213,6 @@ function main() {
validate_opm_bundle

build_opm_catalog
validate_opm_catalog

if [[ -n "${APP_SRE_BOT_PUSH_TOKEN:-}" ]]; then
update_versions_repo
Expand Down
14 changes: 14 additions & 0 deletions olm/catalog.Dockerfile
Original file line number Diff line number Diff line change
@@ -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