From 452db3c75f5863ea86aca9834ed75e5cfef903d0 Mon Sep 17 00:00:00 2001 From: gounthar Date: Thu, 26 Sep 2024 14:14:28 +0200 Subject: [PATCH 1/9] fix(updatecli): First working version. --- updatecli/scripts/ubi9-latest-tag.sh | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 updatecli/scripts/ubi9-latest-tag.sh diff --git a/updatecli/scripts/ubi9-latest-tag.sh b/updatecli/scripts/ubi9-latest-tag.sh new file mode 100755 index 000000000..bcbdebb96 --- /dev/null +++ b/updatecli/scripts/ubi9-latest-tag.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# The Swagger API endpoints for the Red Hat Container Catalog API are documented at: https://catalog.redhat.com/api/containers/v1/ui/#/Repositories/graphql.images.get_images_by_repo +# Correct URL of the Red Hat Container Catalog API for UBI9 +URL="https://catalog.redhat.com/api/containers/v1/repositories/registry/registry.access.redhat.com/repository/ubi9/images?page_size=10&page=0&sort_by=last_update_date%5Bdesc%5D" + +# Check if jq and curl are installed +# If they are not installed, exit the script with an error message +if ! command -v jq >/dev/null 2>&1 || ! command -v curl >/dev/null 2>&1; then + echo "jq and curl are required but not installed. Exiting with status 1." >&2 + exit 1 +fi + +# Fetch the tags using curl +response=$(curl -s "$URL" -H 'accept: application/json') + +# Check if the response is empty or null +if [ -z "$response" ] || [ "$response" == "null" ]; then + echo "Error: Failed to fetch tags from the Red Hat Container Catalog API." + exit 1 +fi + +# Parse the JSON response using jq to find the "latest" tag and its associated tags +latest_tag=$(echo "$response" | jq -r '.data[].repositories[].signatures[] | select(.tags[] == "latest") | .tags[]') + +# Check if the latest_tag is empty +if [ -z "$latest_tag" ]; then + echo "Error: No valid tags found." + exit 1 +fi + +# Sort and remove duplicates +unique_tag=$(echo "$latest_tag" | sort | uniq | grep -v latest | grep "-") + +unique_tag=$(echo "$unique_tag" | xargs) +echo $unique_tag From e763366d21ae3d83f8cc0442fc6ee83e819cad3d Mon Sep 17 00:00:00 2001 From: gounthar Date: Thu, 26 Sep 2024 14:17:03 +0200 Subject: [PATCH 2/9] fix(updatecli): Add documentation --- updatecli/scripts/ubi9-latest-tag.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/updatecli/scripts/ubi9-latest-tag.sh b/updatecli/scripts/ubi9-latest-tag.sh index bcbdebb96..a626fe384 100755 --- a/updatecli/scripts/ubi9-latest-tag.sh +++ b/updatecli/scripts/ubi9-latest-tag.sh @@ -1,6 +1,11 @@ #!/bin/bash -# The Swagger API endpoints for the Red Hat Container Catalog API are documented at: https://catalog.redhat.com/api/containers/v1/ui/#/Repositories/graphql.images.get_images_by_repo +# This script fetches the latest tag from the Red Hat Container Catalog API for UBI9 images. +# It ensures that `jq` and `curl` are installed, fetches the tags, and processes them to find the unique tag. + +# The Swagger API endpoints for the Red Hat Container Catalog API are documented at: +# https://catalog.redhat.com/api/containers/v1/ui/#/Repositories/graphql.images.get_images_by_repo + # Correct URL of the Red Hat Container Catalog API for UBI9 URL="https://catalog.redhat.com/api/containers/v1/repositories/registry/registry.access.redhat.com/repository/ubi9/images?page_size=10&page=0&sort_by=last_update_date%5Bdesc%5D" @@ -32,5 +37,6 @@ fi # Sort and remove duplicates unique_tag=$(echo "$latest_tag" | sort | uniq | grep -v latest | grep "-") +# Trim spaces unique_tag=$(echo "$unique_tag" | xargs) echo $unique_tag From 9f05cdf440621f16edc5030942364bb8a475537d Mon Sep 17 00:00:00 2001 From: gounthar Date: Thu, 26 Sep 2024 14:22:51 +0200 Subject: [PATCH 3/9] feat(updatecli): Update UBI9 to its latest tag. --- updatecli/updatecli.d/rhel-ubi9.yaml | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 updatecli/updatecli.d/rhel-ubi9.yaml diff --git a/updatecli/updatecli.d/rhel-ubi9.yaml b/updatecli/updatecli.d/rhel-ubi9.yaml new file mode 100644 index 000000000..22015cd0b --- /dev/null +++ b/updatecli/updatecli.d/rhel-ubi9.yaml @@ -0,0 +1,51 @@ +--- +name: Bump UBI9 version + +scms: + default: + kind: github + spec: + user: "{{ .github.user }}" + email: "{{ .github.email }}" + owner: "{{ .github.owner }}" + repository: "{{ .github.repository }}" + token: "{{ requiredEnv .github.token }}" + username: "{{ .github.username }}" + branch: "{{ .github.branch }}" + +sources: + latestVersion: + name: "Get the latest UBI9 Linux version" + kind: shell + spec: + command: bash updatecli/scripts/ubi9-latest-tag.sh + +targets: + updateDockerfile: + name: "Update the value of the base image (ARG UBI9_TAG) in the Dockerfile" + kind: dockerfile + sourceid: latestVersion + spec: + file: rhel/ubi9/Dockerfile + instruction: + keyword: "ARG" + matcher: "UBI9_TAG" + scmid: default + updateDockerBake: + name: "Update the default value of the variable UBI9_TAG in the docker-bake.hcl" + kind: hcl + sourceid: latestVersion + spec: + file: docker-bake.hcl + path: variable.UBI9_TAG.default + scmid: default + +actions: + default: + kind: github/pullrequest + scmid: default + title: Bump UBI9 version to {{ source "latestVersion" }} + spec: + labels: + - dependencies + - rhel-ubi9 From c21b140bd7306537a75e56cfaca1bd89172f328c Mon Sep 17 00:00:00 2001 From: gounthar Date: Thu, 26 Sep 2024 14:29:51 +0200 Subject: [PATCH 4/9] feat(updatecli): Added a few CPU platforms as a condition --- updatecli/updatecli.d/rhel-ubi9.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/updatecli/updatecli.d/rhel-ubi9.yaml b/updatecli/updatecli.d/rhel-ubi9.yaml index 22015cd0b..a6663ce36 100644 --- a/updatecli/updatecli.d/rhel-ubi9.yaml +++ b/updatecli/updatecli.d/rhel-ubi9.yaml @@ -20,6 +20,18 @@ sources: spec: command: bash updatecli/scripts/ubi9-latest-tag.sh +conditions: + checkUbi9DockerImage: + kind: dockerimage + name: Check if the container image "ubi9" is available + spec: + architectures: + - linux/amd64 + - linux/arm64 + - linux/s390x + - linux/ppc64le + image: registry.access.redhat.com/ubi9 + targets: updateDockerfile: name: "Update the value of the base image (ARG UBI9_TAG) in the Dockerfile" From 6f800cf76387bccb7e8fa3e84ff48f99f25de2c3 Mon Sep 17 00:00:00 2001 From: gounthar Date: Thu, 26 Sep 2024 14:34:24 +0200 Subject: [PATCH 5/9] fix(updatecli): Added comments --- updatecli/updatecli.d/rhel-ubi9.yaml | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/updatecli/updatecli.d/rhel-ubi9.yaml b/updatecli/updatecli.d/rhel-ubi9.yaml index a6663ce36..24fe2013b 100644 --- a/updatecli/updatecli.d/rhel-ubi9.yaml +++ b/updatecli/updatecli.d/rhel-ubi9.yaml @@ -1,4 +1,6 @@ --- +# This YAML configuration file is used to bump the UBI9 version in the Dockerfile and docker-bake.hcl and create a pull request with the changes. + name: Bump UBI9 version scms: @@ -15,49 +17,49 @@ scms: sources: latestVersion: - name: "Get the latest UBI9 Linux version" + name: "Get the latest UBI9 Linux version" # Source to get the latest UBI9 version kind: shell spec: - command: bash updatecli/scripts/ubi9-latest-tag.sh + command: bash updatecli/scripts/ubi9-latest-tag.sh # Command to fetch the latest UBI9 tag conditions: checkUbi9DockerImage: kind: dockerimage - name: Check if the container image "ubi9" is available + name: Check if the container image "ubi9" is available # Condition to check if the UBI9 Docker image is available spec: architectures: - linux/amd64 - linux/arm64 - linux/s390x - linux/ppc64le - image: registry.access.redhat.com/ubi9 + image: registry.access.redhat.com/ubi9 # Docker image to check. The tag is automatically set to the version found in the only source targets: updateDockerfile: - name: "Update the value of the base image (ARG UBI9_TAG) in the Dockerfile" + name: "Update the value of the base image (ARG UBI9_TAG) in the Dockerfile" # Target to update the Dockerfile with the new UBI9 tag kind: dockerfile sourceid: latestVersion spec: - file: rhel/ubi9/Dockerfile + file: rhel/ubi9/Dockerfile # Path to the Dockerfile instruction: - keyword: "ARG" - matcher: "UBI9_TAG" + keyword: "ARG" # Dockerfile instruction keyword + matcher: "UBI9_TAG" # Dockerfile instruction matcher scmid: default updateDockerBake: - name: "Update the default value of the variable UBI9_TAG in the docker-bake.hcl" + name: "Update the default value of the variable UBI9_TAG in the docker-bake.hcl" # Target to update the docker-bake.hcl file with the new UBI9 tag kind: hcl sourceid: latestVersion spec: - file: docker-bake.hcl - path: variable.UBI9_TAG.default + file: docker-bake.hcl # Path to the docker-bake.hcl file + path: variable.UBI9_TAG.default # Path to the variable in the HCL file scmid: default actions: default: kind: github/pullrequest scmid: default - title: Bump UBI9 version to {{ source "latestVersion" }} + title: Bump UBI9 version to {{ source "latestVersion" }} # Title of the pull request spec: labels: - dependencies - - rhel-ubi9 + - rhel-ubi9 # Labels for the pull request From aa6eb9e0ea8cbe4a12fe5a9830e1af5f6e514a3f Mon Sep 17 00:00:00 2001 From: gounthar Date: Fri, 27 Sep 2024 21:19:29 +0200 Subject: [PATCH 6/9] fix(updatecli): Now outputs the tags and their published date. --- updatecli/scripts/ubi9-tags.sh | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 updatecli/scripts/ubi9-tags.sh diff --git a/updatecli/scripts/ubi9-tags.sh b/updatecli/scripts/ubi9-tags.sh new file mode 100755 index 000000000..6626a6013 --- /dev/null +++ b/updatecli/scripts/ubi9-tags.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# This script fetches all tags from the Red Hat Container Catalog API for UBI9 images. +# It ensures that `jq` and `curl` are installed, fetches the tags, and processes them to find all unique tags. + +# Correct URL of the Red Hat Container Catalog API for UBI9 +URL="https://catalog.redhat.com/api/containers/v1/repositories/registry/registry.access.redhat.com/repository/ubi9/images?page_size=100&page=0&sort_by=last_update_date%5Bdesc%5D" + +# Check if jq and curl are installed +if ! command -v jq >/dev/null 2>&1 || ! command -v curl >/dev/null 2>&1; then + echo "jq and curl are required but not installed. Exiting with status 1." >&2 + exit 1 +fi + +# Fetch the tags using curl +response=$(curl -s "$URL" -H 'accept: application/json') + +# Check if the response is empty or null +if [ -z "$response" ] || [ "$response" == "null" ]; then + echo "Error: Failed to fetch tags from the Red Hat Container Catalog API." + exit 1 +fi + +# Parse the JSON response using jq to find all tags and their published dates +all_tags=$(echo "$response" | jq -c '.data[] | {published_date: .repositories[].published_date, tags: .repositories[].signatures[].tags}') + +# Check if the all_tags is empty +if [ -z "$all_tags" ]; then + echo "Error: No valid tags found." + exit 1 +fi + +# Declare an associative array to store tags and their published dates +declare -A tag_dates + +# Iterate over the parsed JSON to populate the associative array +while IFS= read -r line; do + published_date=$(echo "$line" | jq -r '.published_date') + tags=$(echo "$line" | jq -r '.tags[]') + + for tag in $tags; do + # Update the published_date if the current date is more recent + if [[ -z "${tag_dates[$tag]}" || "$published_date" > "${tag_dates[$tag]}" ]]; then + tag_dates[$tag]=$published_date + fi + done +done <<< "$all_tags" + +# Print the associative array +for tag in "${!tag_dates[@]}"; do + echo "Tag: $tag, Published Date: ${tag_dates[$tag]}" +done From 6b2e3a2874312ff4aaf4688af0bba5cda7449136 Mon Sep 17 00:00:00 2001 From: gounthar Date: Mon, 30 Sep 2024 14:46:50 +0200 Subject: [PATCH 7/9] fix(updatecli): Now outputs the tags correctly ordered. --- updatecli/scripts/ubi9-tags.sh | 37 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/updatecli/scripts/ubi9-tags.sh b/updatecli/scripts/ubi9-tags.sh index 6626a6013..e75a06e77 100755 --- a/updatecli/scripts/ubi9-tags.sh +++ b/updatecli/scripts/ubi9-tags.sh @@ -33,20 +33,43 @@ fi # Declare an associative array to store tags and their published dates declare -A tag_dates -# Iterate over the parsed JSON to populate the associative array +# Declare an array to maintain the original order of tags +ordered_tags=() + +# Iterate over the parsed JSON to populate the associative array and ordered array while IFS= read -r line; do published_date=$(echo "$line" | jq -r '.published_date') tags=$(echo "$line" | jq -r '.tags[]') for tag in $tags; do - # Update the published_date if the current date is more recent - if [[ -z "${tag_dates[$tag]}" || "$published_date" > "${tag_dates[$tag]}" ]]; then - tag_dates[$tag]=$published_date + # Filter tags that contain a hyphen + if [[ $tag == *-* ]]; then + # Check if a more complete tag exists + base_tag=${tag%%.*} + if [[ -n "${tag_dates[$base_tag]}" && "$tag" != "$base_tag" ]]; then + # If a more complete tag exists, skip the incomplete tag + echo "a more complete tag exists for $tag, skip the incomplete tag for base tag $base_tag" + continue + fi + # Update the published_date if the current date is more recent or the same + if [[ -z "${tag_dates[$tag]}" || ! "$published_date" < "${tag_dates[$tag]}" ]]; then + tag_dates[$tag]=$published_date + fi + # Add the tag to the ordered array if it's not already present + if [[ ! " ${ordered_tags[*]} " =~ " ${tag} " ]]; then + ordered_tags+=("$tag") + fi fi done done <<< "$all_tags" -# Print the associative array -for tag in "${!tag_dates[@]}"; do - echo "Tag: $tag, Published Date: ${tag_dates[$tag]}" +# Custom sort function with correct order +sort_tags() { + printf "%s\n" "${ordered_tags[@]}" | sort -t '-' -k1,1n -k2,2n -k2.1,2.3n -k2.5,2.12n +} + +# Print the sorted array and their corresponding published dates +for tag in $(sort_tags | tac); do +# echo "Tag: $tag, Published Date: ${tag_dates[$tag]}" + echo "$tag" done From d2cc819f7990069574f51c39b0de813edc36a821 Mon Sep 17 00:00:00 2001 From: gounthar Date: Tue, 15 Oct 2024 09:32:55 +0200 Subject: [PATCH 8/9] fix(updatecli): WIP --- updatecli/scripts/ubi9-tags.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/updatecli/scripts/ubi9-tags.sh b/updatecli/scripts/ubi9-tags.sh index e75a06e77..856187f0e 100755 --- a/updatecli/scripts/ubi9-tags.sh +++ b/updatecli/scripts/ubi9-tags.sh @@ -40,23 +40,26 @@ ordered_tags=() while IFS= read -r line; do published_date=$(echo "$line" | jq -r '.published_date') tags=$(echo "$line" | jq -r '.tags[]') - for tag in $tags; do # Filter tags that contain a hyphen if [[ $tag == *-* ]]; then - # Check if a more complete tag exists - base_tag=${tag%%.*} - if [[ -n "${tag_dates[$base_tag]}" && "$tag" != "$base_tag" ]]; then - # If a more complete tag exists, skip the incomplete tag - echo "a more complete tag exists for $tag, skip the incomplete tag for base tag $base_tag" - continue - fi # Update the published_date if the current date is more recent or the same if [[ -z "${tag_dates[$tag]}" || ! "$published_date" < "${tag_dates[$tag]}" ]]; then tag_dates[$tag]=$published_date fi - # Add the tag to the ordered array if it's not already present - if [[ ! " ${ordered_tags[*]} " =~ " ${tag} " ]]; then + # Add or replace the tag in the ordered array + IFS='.' read -r part1 part2 _ <<< "$tag" + base_tag="${part1}.${part2}" + # echo "Base tag is $base_tag and tag is $tag" + replaced=false + for i in "${!ordered_tags[@]}"; do + if [[ "${ordered_tags[i]}" == "$base_tag" ]]; then + ordered_tags[i]="$tag" + replaced=true + break + fi + done + if ! $replaced; then ordered_tags+=("$tag") fi fi @@ -70,6 +73,5 @@ sort_tags() { # Print the sorted array and their corresponding published dates for tag in $(sort_tags | tac); do -# echo "Tag: $tag, Published Date: ${tag_dates[$tag]}" echo "$tag" done From c1bc4675ae38244f7a97d5792fddb40a1a1cfe15 Mon Sep 17 00:00:00 2001 From: Bruno Verachten Date: Thu, 31 Oct 2024 11:25:50 +0100 Subject: [PATCH 9/9] fix(updatecli): RHEL/UBI9 is back --- updatecli/updatecli.d/rhel-ubi9.yaml.disabled | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 updatecli/updatecli.d/rhel-ubi9.yaml.disabled diff --git a/updatecli/updatecli.d/rhel-ubi9.yaml.disabled b/updatecli/updatecli.d/rhel-ubi9.yaml.disabled deleted file mode 100644 index 24fe2013b..000000000 --- a/updatecli/updatecli.d/rhel-ubi9.yaml.disabled +++ /dev/null @@ -1,65 +0,0 @@ ---- -# This YAML configuration file is used to bump the UBI9 version in the Dockerfile and docker-bake.hcl and create a pull request with the changes. - -name: Bump UBI9 version - -scms: - default: - kind: github - spec: - user: "{{ .github.user }}" - email: "{{ .github.email }}" - owner: "{{ .github.owner }}" - repository: "{{ .github.repository }}" - token: "{{ requiredEnv .github.token }}" - username: "{{ .github.username }}" - branch: "{{ .github.branch }}" - -sources: - latestVersion: - name: "Get the latest UBI9 Linux version" # Source to get the latest UBI9 version - kind: shell - spec: - command: bash updatecli/scripts/ubi9-latest-tag.sh # Command to fetch the latest UBI9 tag - -conditions: - checkUbi9DockerImage: - kind: dockerimage - name: Check if the container image "ubi9" is available # Condition to check if the UBI9 Docker image is available - spec: - architectures: - - linux/amd64 - - linux/arm64 - - linux/s390x - - linux/ppc64le - image: registry.access.redhat.com/ubi9 # Docker image to check. The tag is automatically set to the version found in the only source - -targets: - updateDockerfile: - name: "Update the value of the base image (ARG UBI9_TAG) in the Dockerfile" # Target to update the Dockerfile with the new UBI9 tag - kind: dockerfile - sourceid: latestVersion - spec: - file: rhel/ubi9/Dockerfile # Path to the Dockerfile - instruction: - keyword: "ARG" # Dockerfile instruction keyword - matcher: "UBI9_TAG" # Dockerfile instruction matcher - scmid: default - updateDockerBake: - name: "Update the default value of the variable UBI9_TAG in the docker-bake.hcl" # Target to update the docker-bake.hcl file with the new UBI9 tag - kind: hcl - sourceid: latestVersion - spec: - file: docker-bake.hcl # Path to the docker-bake.hcl file - path: variable.UBI9_TAG.default # Path to the variable in the HCL file - scmid: default - -actions: - default: - kind: github/pullrequest - scmid: default - title: Bump UBI9 version to {{ source "latestVersion" }} # Title of the pull request - spec: - labels: - - dependencies - - rhel-ubi9 # Labels for the pull request