Skip to content

Commit 61b9656

Browse files
committed
Update Runtime updater GHA
1 parent 76ca8b2 commit 61b9656

File tree

4 files changed

+168
-6
lines changed

4 files changed

+168
-6
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
# The aim of this GitHub workflow is to update the runtimes ImageStreams
3+
name: Update runtime ImageStreams SHA digests
4+
on: # yamllint disable-line rule:truthy
5+
workflow_dispatch:
6+
inputs:
7+
branch:
8+
required: true
9+
description: "Which branch do you want to update?"
10+
tag_version:
11+
required: true
12+
description: "Provide tag version: main or YYYYx"
13+
user-hash:
14+
required: false
15+
description: "Optional: Specify a Git hash (it should exist in the provided branch's history)"
16+
17+
env:
18+
TMP_BRANCH: tmp-branch-${{ github.run_id }}
19+
BRANCH_NAME: ${{ github.event.inputs.branch || 'main' }}
20+
TAG_VERSION: ${{ github.event.inputs.tag_version || 'main' }}
21+
USER_HASH: ${{ github.event.inputs.user-hash }}
22+
23+
jobs:
24+
initialize:
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: write
28+
steps:
29+
- name: Install Skopeo CLI
30+
shell: bash
31+
run: |
32+
sudo apt-get -y update
33+
sudo apt-get -y install skopeo yq jq
34+
35+
- name: Checkout branch
36+
uses: actions/checkout@v4
37+
with:
38+
ref: ${{ env.BRANCH_NAME }}
39+
40+
- name: Create a new branch
41+
run: |
42+
echo ${{ env.TMP_BRANCH }}
43+
git checkout -b ${{ env.TMP_BRANCH }}
44+
git push --set-upstream origin ${{ env.TMP_BRANCH }}
45+
46+
update-runtimes:
47+
needs: [initialize]
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: write
51+
steps:
52+
- name: Configure Git
53+
run: |
54+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
55+
git config --global user.name "GitHub Actions"
56+
57+
- name: Checkout release branch
58+
uses: actions/checkout@v4
59+
with:
60+
ref: ${{ env.TMP_BRANCH }}
61+
fetch-depth: 0
62+
63+
- name: Invoke script to handle the update
64+
shell: bash
65+
run: |
66+
bash ${GITHUB_WORKSPACE}/ci/runtimes-digest-updater.sh ${{ env.TAG_VERSION }} ${{ env.USER_HASH }}
67+
68+
- name: Commit the changes
69+
run: |
70+
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
71+
git fetch origin "${{ env.TMP_BRANCH }}" && \
72+
git pull origin "${{ env.TMP_BRANCH }}" && \
73+
git add "manifests/base/runtime-*" && \
74+
git commit -m "Update file via ${{ env.TMP_BRANCH }} GitHub action" && \
75+
git push origin "${{ env.TMP_BRANCH }}"
76+
else
77+
echo "There were no changes detected in the images for the ${{ env.BRANCH_NAME }}"
78+
fi
79+
80+
open-pull-request:
81+
needs: [update-runtimes]
82+
runs-on: ubuntu-latest
83+
permissions:
84+
pull-requests: write
85+
steps:
86+
- name: Checkout repo
87+
uses: actions/checkout@v4
88+
89+
- name: pull-request
90+
uses: repo-sync/pull-request@v2
91+
with:
92+
source_branch: ${{ env.TMP_BRANCH }}
93+
destination_branch: ${{ env.BRANCH_NAME }}
94+
github_token: ${{ secrets.GITHUB_TOKEN }}
95+
pr_label: "automated pr"
96+
pr_title: "[Digest Updater Action] Update Runtimes ImageStreams"
97+
pr_body: |
98+
:rocket: This is an automated Pull Request.
99+
Created by `/.github/workflows/runtimes-digest-updater-upstream.yaml`
100+
101+
:exclamation: **IMPORTANT NOTE**: Remember to delete the ` ${{ env.TMP_BRANCH }}` branch after merging the changes

ci/runtimes-digest-updater.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
TAG_VERSION=$1
4+
USER_HASH=$2
5+
6+
REPO_OWNER="opendatahub-io"
7+
REPO_NAME="notebooks"
8+
GITHUB_API_URL="https://api.github.com/repos/$REPO_OWNER/$REPO_NAME"
9+
10+
if [[ -n "$USER_HASH" ]]; then
11+
HASH=$USER_HASH
12+
echo "Using user-provided HASH: $HASH"
13+
else
14+
PAYLOAD=$(curl --silent -H 'Accept: application/vnd.github.v4.raw' "$GITHUB_API_URL/commits?sha=$TAG_VERSION&per_page=1")
15+
HASH=$(echo "$PAYLOAD" | jq -r '.[0].sha' | cut -c1-7)
16+
echo "Extracted HASH: $HASH"
17+
fi
18+
19+
REPO_ROOT=$(git rev-parse --show-toplevel)
20+
MANIFEST_DIR="$REPO_ROOT/manifests/base"
21+
# Find matching files
22+
files=$(find "$MANIFEST_DIR" -type f -name "runtime-*.yaml")
23+
for file in $files; do
24+
echo "PROCESSING: $file"
25+
26+
# Extract values
27+
img=$(yq e '.spec.tags[].annotations."opendatahub.io/runtime-image-metadata" | fromjson | .[].metadata.image_name' "$file" 2>/dev/null)
28+
name=$(yq e '.spec.tags[].name' "$file" 2>/dev/null)
29+
ubi=$(yq e '.metadata.annotations."opendatahub.io/runtime-image-name"' "$file" 2>/dev/null | grep -oE 'UBI[0-9]+' | tr '[:upper:]' '[:lower:]')
30+
py_version=$(yq e '.metadata.annotations."opendatahub.io/runtime-image-name"' "$file" 2>/dev/null | grep -oE 'Python [0-9]+\.[0-9]+' | sed 's/ /-/g' | tr '[:upper:]' '[:lower:]')
31+
registry=$(echo "$img" | cut -d '@' -f1)
32+
33+
# Handling specific cases
34+
[[ $name == tensorflow* ]] && name="cuda-$name"
35+
36+
if [[ $TAG_VERSION == main ]]; then
37+
# This should match with the runtime-image tag name as is on quay.io registry
38+
regex="^runtime-$name-$ubi-$py_version-[0-9]{8}-$HASH$"
39+
else
40+
# This should match with the runtime-image tag name as is on quay.io registry
41+
regex="^runtime-$name-$ubi-$py_version-$TAG_VERSION-[0-9]{8}-$HASH$"
42+
fi
43+
44+
latest_tag=$(skopeo inspect --retry-times 3 "docker://$img" | jq -r --arg regex "$regex" '.RepoTags | map(select(. | test($regex))) | .[0]')
45+
echo "CHECKING: ${latest_tag}"
46+
47+
if [[ -z "$latest_tag" || "$latest_tag" == "null" ]]; then
48+
echo "No matching tag found on registry for $file. Skipping."
49+
continue
50+
fi
51+
52+
# Extract the digest sha from the latest tag
53+
digest=$(skopeo inspect --retry-times 3 "docker://$registry:$latest_tag" | jq .Digest | tr -d '"')
54+
output="${registry}@${digest}"
55+
echo "NEW: ${output}"
56+
57+
# Updates the ImageStream with the new SHAs
58+
yq e -i '(.spec.tags[] | .from.name) = "'"$output"'"' "$file"
59+
sed -i "s|\(\"image_name\": \"\)[^\"]*|\1${output}|" "$file"
60+
61+
done

manifests/base/runtime-pytorch-imagestream.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
opendatahub.io/runtime-image: "true"
77
annotations:
88
opendatahub.io/runtime-image-url: "https://github.com//opendatahub-io/notebooks/tree/main/runtimes"
9-
opendatahub.io/runtime-image-name: "Pytorch with CUDA and Python 3.11 (UBI9)"
9+
opendatahub.io/runtime-image-name: "PyTorch with CUDA and Python 3.11 (UBI9)"
1010
opendatahub.io/runtime-image-desc: "PyTorch runtime image for Elyra, enabling pipeline execution from Workbenches with PyTorch libraries and dependencies, supporting different runtimes for various pipeline nodes."
1111
name: runtime-pytorch
1212
spec:
@@ -18,12 +18,12 @@ spec:
1818
opendatahub.io/runtime-image-metadata: |
1919
[
2020
{
21-
"display_name": "Pytorch with CUDA and Python 3.11 (UBI9)",
21+
"display_name": "PyTorch with CUDA and Python 3.11 (UBI9)",
2222
"metadata": {
2323
"tags": [
2424
"pytorch"
2525
],
26-
"display_name": "Pytorch with CUDA and Python 3.11 (UBI9)",
26+
"display_name": "PyTorch with CUDA and Python 3.11 (UBI9)",
2727
"image_name": "quay.io/opendatahub/workbench-images@sha256:6a2806bf3cd9b00f60f3c7fe907727fb954c9776a075d9d58df26b5119d7afe6",
2828
"pull_policy": "IfNotPresent"
2929
},

manifests/base/runtime-rocm-pytorch-imagestream.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
opendatahub.io/runtime-image: "true"
77
annotations:
88
opendatahub.io/runtime-image-url: "https://github.com//opendatahub-io/notebooks/tree/main/runtimes"
9-
opendatahub.io/runtime-image-name: "Pytorch with ROCm and Python 3.11 (UBI9)"
9+
opendatahub.io/runtime-image-name: "PyTorch with ROCm and Python 3.11 (UBI9)"
1010
opendatahub.io/runtime-image-desc: "ROCm optimized PyTorch runtime image for Elyra, enabling pipeline execution from Workbenches with PyTorch libraries and dependencies, supporting different runtimes for various pipeline nodes."
1111
name: runtime-rocm-pytorch
1212
spec:
@@ -18,12 +18,12 @@ spec:
1818
opendatahub.io/runtime-image-metadata: |
1919
[
2020
{
21-
"display_name": "Pytorch with ROCm and Python 3.11 (UBI9)",
21+
"display_name": "PyTorch with ROCm and Python 3.11 (UBI9)",
2222
"metadata": {
2323
"tags": [
2424
"rocm-pytorch"
2525
],
26-
"display_name": "Pytorch with ROCm and Python 3.11 (UBI9)",
26+
"display_name": "PyTorch with ROCm and Python 3.11 (UBI9)",
2727
"image_name": "quay.io/opendatahub/workbench-images@sha256:c6d74d73b835d0f97040ca99bb25065a949b817b52179f239a5361c3299352ba",
2828
"pull_policy": "IfNotPresent"
2929
},

0 commit comments

Comments
 (0)