Skip to content

Commit

Permalink
scripts: add operator-core FB mapping (#231)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Stephens <[email protected]>
  • Loading branch information
patrick-stephens authored Nov 22, 2023
1 parent ac83f79 commit 7afd9d1
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
33 changes: 33 additions & 0 deletions operator/core-fluent-bit-default-versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"v2.0.21": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.11.1",
"v2.0.20": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.11.1",
"v2.0.19": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.11.1",
"v2.0.18": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.3",
"v2.0.17": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.3",
"v2.0.16": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.3",
"v2.0.15": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.3",
"v2.0.13": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.2",
"v2.0.12": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.2",
"v2.0.11": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.2",
"v2.0.10": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.2",
"v2.0.9": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.2",
"v2.0.8": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.2",
"v2.0.7": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.10.1",
"v2.0.6": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.9.9",
"v2.0.5": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.9.9",
"v2.0.4": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.9.9",
"v2.0.3": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.9.9",
"v2.0.2": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.9.8",
"v2.0.1": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.9.8",
"v2.0.0": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.9.7",
"v1.1.4": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.9.7",
"v1.1.3": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.9.7",
"v1.1.2": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.9.1",
"v1.1.1": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.8.9",
"v1.1.0": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.8.9",
"v1.0.15": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.8.5",
"v1.0.14": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.8.2",
"v1.0.13": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.8.1",
"v1.0.12": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.7.5",
"latest": "ghcr.io/calyptia/core/calyptia-fluent-bit:23.11.1"
}
4 changes: 3 additions & 1 deletion scripts/create-core-fluent-bit-schemas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SCHEMA_FILENAME=${SCHEMA_FILENAME:-core-fluent-bit}
GHCR_TOKEN=$(echo "$GITHUB_TOKEN" | base64)

TAGS=$(curl --silent -H "Authorization: Bearer $GHCR_TOKEN" https://ghcr.io/v2/"${CONTAINER_PACKAGE}"/tags/list?n=100000 | \
jq -r '.tags | map(select(.| test("^([0-9]+\\.|v)(.*)")))|flatten[]')
jq -r '.tags | map(select(.| test("^([0-9]+\\.|v)(.*)")))|flatten[]')
# Test for tags beginning with v* or XX.*: https://github.com/stedolan/jq/issues/1250#issuecomment-252396642

for TAG in $TAGS; do
Expand All @@ -38,3 +38,5 @@ for TAG in $TAGS; do

"$CONTAINER_RUNTIME" rm --force "test" &> /dev/null
done

"$SCRIPT_DIR/create-operator-mappings.sh"
45 changes: 45 additions & 0 deletions scripts/create-operator-mappings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
set -u
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Used to authenticate with gh api CLI
export GH_TOKEN=${GITHUB_TOKEN:?}
OPERATOR_REPO=${OPERATOR_REPO:-calyptia/core-operator-releases}
SCHEMA_FILENAME=${SCHEMA_FILENAME:-$SCRIPT_DIR/../operator/core-fluent-bit-default-versions.json}

TAGS=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/"${OPERATOR_REPO}"/releases --jq '.[].tag_name')

rm -fv "$SCHEMA_FILENAME"
echo '{' > "$SCHEMA_FILENAME"

for TAG in $TAGS; do
echo "Operator release: $TAG"
# mkdir -p "${SCHEMA_DIR}/${TAG}"
# Grab the manifest for each release
MANIFEST_URL=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/"${OPERATOR_REPO}"/releases/tags/"${TAG}" --jq '.assets[]|select(.name == "manifest.yaml")|.browser_download_url')
echo "manifest.yaml: $MANIFEST_URL"

# Select the CRD for pipelines then extract the image field from that
CORE_FLUENT_BIT_VERSION=$(curl -sSfL "$MANIFEST_URL" | yq 'select(.kind == "CustomResourceDefinition")| select(.metadata.name == "pipelines.core.calyptia.com")|.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.image.default')

echo "$TAG : $CORE_FLUENT_BIT_VERSION"
echo "\"$TAG\": \"$CORE_FLUENT_BIT_VERSION\"," >> "$SCHEMA_FILENAME"
done

# Add latest at end to close off the object fields - no need to cope with commas not at end of last entry then
MANIFEST_URL=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/"${OPERATOR_REPO}"/releases/latest --jq '.assets[]|select(.name == "manifest.yaml")|.browser_download_url')
echo "manifest.yaml: $MANIFEST_URL"

CORE_FLUENT_BIT_VERSION=$(curl -sSfL "$MANIFEST_URL" | yq 'select(.kind == "CustomResourceDefinition")| select(.metadata.name == "pipelines.core.calyptia.com")|.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.image.default')
echo "\"latest\": \"$CORE_FLUENT_BIT_VERSION\"" >> "$SCHEMA_FILENAME"

echo '}' >> "$SCHEMA_FILENAME"

0 comments on commit 7afd9d1

Please sign in to comment.