Skip to content

Commit

Permalink
Merge pull request #907 from gounthar/updatecli-for-ubi9
Browse files Browse the repository at this point in the history
chore(updatecli) fix UBI9 manifest
  • Loading branch information
dduportal authored Dec 2, 2024
2 parents c6fcec5 + c7d6c67 commit dff7227
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
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)
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

0 comments on commit dff7227

Please sign in to comment.