From 452db3c75f5863ea86aca9834ed75e5cfef903d0 Mon Sep 17 00:00:00 2001 From: gounthar Date: Thu, 26 Sep 2024 14:14:28 +0200 Subject: [PATCH 1/5] 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/5] 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/5] 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/5] 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/5] 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