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

feat(updatecli): Track UBI9 version #885

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions updatecli/scripts/ubi9-latest-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# 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"

# 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 "-")

# Trim spaces
unique_tag=$(echo "$unique_tag" | xargs)
echo $unique_tag
65 changes: 65 additions & 0 deletions updatecli/updatecli.d/rhel-ubi9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
# 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