Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(updatecli) fix UBI9 manifest #907

Merged
merged 6 commits into from
Dec 2, 2024
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
17 changes: 10 additions & 7 deletions updatecli/scripts/ubi9-latest-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
# 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"
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 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
>&2 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')
response=$(curl --silent --fail --location --connect-timeout 10 --max-time 30 --header 'accept: application/json' "$URL")

# 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."
>&2 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[]')
# Parse the JSON response using jq to find the version associated with the "latest" tag
latest_tag=$(echo "$response" | jq -r '.data[].repositories[] | select(.tags[].name == "latest") | .tags[] | select(.name != "latest") | .name')

# Check if the latest_tag is empty
if [ -z "$latest_tag" ]; then
Expand All @@ -39,4 +39,7 @@ unique_tag=$(echo "$latest_tag" | sort | uniq | grep -v latest | grep "-")

# Trim spaces
unique_tag=$(echo "$unique_tag" | xargs)
Comment on lines 40 to 41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same (non-blocking) suggestion as #906 (comment): simplify the script to pipe a trim on the unique result from the curl | jq command then only test if it's empty before exiting 0.

(reposting as the previous discussion has been automatically hidden)

Copy link
Contributor

@lemeurherveCB lemeurherveCB Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe your query can return multiple and duplicated tags in some cases? IDK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my query will return several tags, including 9.5 and 9.5-1731517889, which will appear multiple times in the output. This repetition is typical of the data we are handling:

 "tags": [
            {
              "added_date": "2024-11-13T18:11:46.455000+00:00",
              "name": "9.5",
              "_links": {
                "tag_history": {
                  "href": "/v1/tag-history/registry/registry.access.redhat.com/repository/ubi9/tag/9.5"
                }
              }
            },
            {
              "added_date": "2024-11-13T18:11:46.455000+00:00",
              "name": "9.5-1731517889",
              "_links": {
                "tag_history": {
                  "href": "/v1/tag-history/registry/registry.access.redhat.com/repository/ubi9/tag/9.5-1731517889"
                }
              }
            },
            {
              "added_date": "2024-11-13T18:11:46.455000+00:00",
              "name": "latest",
              "_links": {
                "tag_history": {
                  "href": "/v1/tag-history/registry/registry.access.redhat.com/repository/ubi9/tag/latest"
                }
              }
            }
          ],

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though: can this query be more precise to return only the latest tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I'm not sure how to proceed with that task. 🤷
Feel free to give it a try, as I'm not proficient with jq. 😉

echo $unique_tag

# Output the latest version
echo "$unique_tag"
exit 0
30 changes: 15 additions & 15 deletions updatecli/updatecli.d/rhel-ubi9.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
# 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:
Expand All @@ -17,49 +15,51 @@ scms:

sources:
latestVersion:
name: "Get the latest UBI9 Linux version" # Source to get the latest UBI9 version
name: "Get the latest UBI9 Linux version"
kind: shell
spec:
command: bash updatecli/scripts/ubi9-latest-tag.sh # Command to fetch the latest UBI9 tag
command: bash -x updatecli/scripts/ubi9-latest-tag.sh

conditions:
checkUbi9DockerImage:
kind: dockerimage
name: Check if the container image "ubi9" is available # Condition to check if the UBI9 Docker image is available
name: Check if the container image "ubi9" is available
sourceid: latestVersion # Provides the found tag as "input"
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
image: registry.access.redhat.com/ubi9


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
name: "Update the value of the base image (ARG UBI9_TAG) in the Dockerfile"
kind: dockerfile
sourceid: latestVersion
spec:
file: rhel/ubi9/Dockerfile # Path to the Dockerfile
file: rhel/ubi9/Dockerfile
instruction:
keyword: "ARG" # Dockerfile instruction keyword
matcher: "UBI9_TAG" # Dockerfile instruction matcher
keyword: ARG
matcher: UBI9_TAG
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
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 to the docker-bake.hcl file
path: variable.UBI9_TAG.default # Path to the variable in the HCL file
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" }} # Title of the pull request
title: Bump UBI9 version to {{ source "latestVersion" }}
spec:
labels:
- dependencies
- rhel-ubi9 # Labels for the pull request
- rhel-ubi9