|
| 1 | +--- |
| 2 | +# The aim of this GitHub workflow is to update the runtimes across `/jupyter/datascience/ubi*-python-*/runtime-images/*.json` paths. |
| 3 | +name: Update runtime images |
| 4 | +on: # yamllint disable-line rule:truthy |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + branch: |
| 8 | + required: true |
| 9 | + description: "Provide the name of the branch you want to update ex main, vYYYYx etc: " |
| 10 | + # Put the scheduler on comment until automate the full release procedure |
| 11 | + # schedule: |
| 12 | + # - cron: "0 0 * * 5" #Scheduled every Friday |
| 13 | +env: |
| 14 | + DIGEST_UPDATER_BRANCH: digest-updater-${{ github.run_id }} |
| 15 | + BRANCH_NAME: ${{ github.event.inputs.branch || 'main' }} |
| 16 | + RELEASE_VERSION_N: 2024a |
| 17 | +jobs: |
| 18 | + initialize: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: write |
| 22 | + steps: |
| 23 | + - name: Install Skopeo CLI |
| 24 | + shell: bash |
| 25 | + run: | |
| 26 | + sudo apt-get -y update |
| 27 | + sudo apt-get -y install skopeo |
| 28 | +
|
| 29 | + # Checkout the branch |
| 30 | + - name: Checkout branch |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + ref: ${{ env.BRANCH_NAME }} |
| 34 | + |
| 35 | + # Create a new branch |
| 36 | + - name: Create a new branch |
| 37 | + run: | |
| 38 | + echo ${{ env.DIGEST_UPDATER_BRANCH }} |
| 39 | + git checkout -b ${{ env.DIGEST_UPDATER_BRANCH }} |
| 40 | + git push --set-upstream origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 41 | +
|
| 42 | + update-runtimes: |
| 43 | + needs: [initialize] |
| 44 | + runs-on: ubuntu-latest |
| 45 | + permissions: |
| 46 | + contents: write |
| 47 | + steps: |
| 48 | + - name: Configure Git |
| 49 | + run: | |
| 50 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 51 | + git config --global user.name "GitHub Actions" |
| 52 | +
|
| 53 | + # Get latest build commit from the https://github.com/opendatahub-io/notebooks/${release_branch} using this as identifier for the latest tag name |
| 54 | + - name: Retrive latest commit hash from the release branch |
| 55 | + id: hash-n |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + PAYLOAD=$(curl --silent -H 'Accept: application/vnd.github.v4.raw' https://api.github.com/repos/opendatahub-io/notebooks/commits?sha=$RELEASE_VERSION_N&per_page=1) |
| 59 | + echo "HASH_N=$(echo $PAYLOAD | jq -r '.[0].sha[0:7]')" >> ${GITHUB_OUTPUT} |
| 60 | +
|
| 61 | + # Checkout the release branch to apply the updates |
| 62 | + - name: Checkout release branch |
| 63 | + uses: actions/checkout@v4 |
| 64 | + with: |
| 65 | + ref: ${{ env.DIGEST_UPDATER_BRANCH }} |
| 66 | + |
| 67 | + - name: Update Runtimes |
| 68 | + run: | |
| 69 | + echo Latest commit is: ${{ steps.hash-n.outputs.HASH_N }} on ${{ env.RELEASE_VERSION_N}} |
| 70 | + PATHS=("jupyter/datascience/anaconda-python-3.8/runtime-images/datascience-ubi8-py38.json" |
| 71 | + "jupyter/datascience/anaconda-python-3.8/runtime-images/pytorch-ubi8-py38.json" |
| 72 | + "jupyter/datascience/anaconda-python-3.8/runtime-images/tensorflow-ubi8-py38.json" |
| 73 | + "jupyter/datascience/anaconda-python-3.8/runtime-images/ubi8-py38.json" |
| 74 | + "jupyter/datascience/ubi8-python-3.8/runtime-images/datascience-ubi8-py38.json" |
| 75 | + "jupyter/datascience/ubi8-python-3.8/runtime-images/pytorch-ubi8-py38.json" |
| 76 | + "jupyter/datascience/ubi8-python-3.8/runtime-images/tensorflow-ubi8-py38.json" |
| 77 | + "jupyter/datascience/ubi8-python-3.8/runtime-images/ubi8-py38.json" |
| 78 | + "jupyter/datascience/ubi9-python-3.9/runtime-images/datascience-ubi9-py39.json" |
| 79 | + "jupyter/datascience/ubi9-python-3.9/runtime-images/pytorch-ubi9-py39.json" |
| 80 | + "jupyter/datascience/ubi9-python-3.9/runtime-images/tensorflow-ubi9-py39.json" |
| 81 | + "jupyter/datascience/ubi9-python-3.9/runtime-images/ubi9-py39.json") |
| 82 | +
|
| 83 | + for ((i=0;i<${#PATHS[@]};++i)); do |
| 84 | + path=${PATHS[$i]} |
| 85 | + img=$(cat ${path} | jq -r '.metadata.image_name') |
| 86 | + name=$(echo "$path" | sed 's#.*runtime-images/\(.*\)-py.*#\1#') |
| 87 | + py_version=$(echo "$path" | grep -o 'python-[0-9]\.[0-9]') |
| 88 | + # Handling specific cases |
| 89 | + if [[ $name == *tensorflow* ]]; then |
| 90 | + name="cuda-$name" |
| 91 | + elif [[ $name == ubi* ]]; then |
| 92 | + name="minimal-$name" |
| 93 | + fi |
| 94 | + registry=$(echo $img | cut -d '@' -f1) |
| 95 | + regex="runtime-$name-$py_version-${{ env.RELEASE_VERSION_N}}-\d+-${{ steps.hash-n.outputs.HASH_N }}" |
| 96 | + echo "CHECKING: " $regex |
| 97 | + latest_tag=$(skopeo inspect docker://$img | jq -r --arg regex "$regex" '.RepoTags | map(select(. | test($regex))) | .[0]') |
| 98 | + digest=$(skopeo inspect docker://$registry:$latest_tag | jq .Digest | tr -d '"') |
| 99 | + output=$registry@$digest |
| 100 | + echo "NEW: " $output |
| 101 | + jq --arg output "$output" '.metadata.image_name = $output' "$path" > "$path.tmp" && mv "$path.tmp" "$path" |
| 102 | + done |
| 103 | + if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then |
| 104 | + git fetch origin ${{ env.DIGEST_UPDATER_BRANCH }} && git pull origin ${{ env.DIGEST_UPDATER_BRANCH }} && git add jupyter/datascience/* && git commit -m "Update file via ${{ env.DIGEST_UPDATER_BRANCH }} GitHub action" && git push origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 105 | + else |
| 106 | + echo "There were no changes detected in the images for the ${{ env.RELEASE_VERSION_N}}" |
| 107 | + fi |
| 108 | +
|
| 109 | + open-pull-request: |
| 110 | + needs: [update-runtimes] |
| 111 | + runs-on: ubuntu-latest |
| 112 | + permissions: |
| 113 | + pull-requests: write |
| 114 | + steps: |
| 115 | + - name: Checkout repo |
| 116 | + uses: actions/checkout@v4 |
| 117 | + |
| 118 | + - name: pull-request |
| 119 | + uses: repo-sync/pull-request@v2 |
| 120 | + with: |
| 121 | + source_branch: ${{ env.DIGEST_UPDATER_BRANCH }} |
| 122 | + destination_branch: ${{ env.BRANCH_NAME}} |
| 123 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 124 | + pr_label: "automated pr" |
| 125 | + pr_title: "[Digest Updater Action] Update Runtimes Images" |
| 126 | + pr_body: | |
| 127 | + :rocket: This is an automated Pull Request. |
| 128 | + Created by `/.github/workflows/runtimes-digest-updater-upstream.yaml` |
| 129 | +
|
| 130 | + This PR updates the following files: |
| 131 | + - All the runtime images across `/jupyter/datascience/ubi*-python-*/runtime-images/*.json` paths |
| 132 | +
|
| 133 | + :exclamation: **IMPORTANT NOTE**: Remember to delete the ` ${{ env.DIGEST_UPDATER_BRANCH }}` branch after merging the changes |
0 commit comments