|
| 1 | +--- |
| 2 | +# The aim of this GitHub workflow is to update the params.env file with the latest digest. |
| 3 | +name: Update notebook image build commit hashes |
| 4 | +on: # yamllint disable-line rule:truthy |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + branch: |
| 8 | + required: true |
| 9 | + description: "Provide branch name: " |
| 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 || 'master' }} |
| 16 | + RELEASE_VERSION_N: 2024a |
| 17 | + RELEASE_VERSION_N_1: 2023b |
| 18 | +jobs: |
| 19 | + initialize: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: write |
| 23 | + steps: |
| 24 | + - name: Install Skopeo CLI |
| 25 | + shell: bash |
| 26 | + run: | |
| 27 | + sudo apt-get -y update |
| 28 | + sudo apt-get -y install skopeo |
| 29 | +
|
| 30 | + # Checkout the branch |
| 31 | + - name: Checkout branch |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + ref: ${{ env.BRANCH_NAME }} |
| 35 | + |
| 36 | + # Create a new branch |
| 37 | + - name: Create a new branch |
| 38 | + run: | |
| 39 | + echo ${{ env.DIGEST_UPDATER_BRANCH }} |
| 40 | + git checkout -b ${{ env.DIGEST_UPDATER_BRANCH }} |
| 41 | + git push --set-upstream origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 42 | +
|
| 43 | + update-n-version: |
| 44 | + needs: [initialize] |
| 45 | + runs-on: ubuntu-latest |
| 46 | + permissions: |
| 47 | + contents: write |
| 48 | + steps: |
| 49 | + - name: Configure Git |
| 50 | + run: | |
| 51 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 52 | + git config --global user.name "GitHub Actions" |
| 53 | +
|
| 54 | + # Get latest build commit from the https://github.com/red-hat-data-services/notebooks/${release_branch} using this as identifier for the latest tag name |
| 55 | + - name: Retrive latest commit hash from the release branch |
| 56 | + id: hash-n |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + PAYLOAD=$(curl --silent -H 'Accept: application/vnd.github.v4.raw' https://api.github.com/repos/red-hat-data-services/notebooks/commits?sha=release-$RELEASE_VERSION_N&per_page=1) |
| 60 | + echo "HASH_N=$(echo $PAYLOAD | jq -r '.[0].sha[0:7]')" >> ${GITHUB_OUTPUT} |
| 61 | +
|
| 62 | + # Checkout the release branch to apply the updates |
| 63 | + - name: Checkout release branch |
| 64 | + uses: actions/checkout@v4 |
| 65 | + with: |
| 66 | + ref: ${{ env.DIGEST_UPDATER_BRANCH }} |
| 67 | + |
| 68 | + - name: Fetch digest, and update the params.env file |
| 69 | + shell: bash |
| 70 | + run: | |
| 71 | + echo Latest commit is: ${{ steps.hash-n.outputs.HASH_N }} on ${{ env.RELEASE_VERSION_N}} |
| 72 | + IMAGES=("odh-minimal-notebook-image-n" "odh-minimal-gpu-notebook-image-n" "odh-pytorch-gpu-notebook-image-n" "odh-generic-data-science-notebook-image-n" "odh-tensorflow-gpu-notebook-image-n" "odh-trustyai-notebook-image-n" "odh-codeserver-notebook-image-n") |
| 73 | + REGEXES=("v2-${{ env.RELEASE_VERSION_N }}-\d{8}+-${{ steps.hash-n.outputs.HASH_N }}" "cuda-[a-z]+-minimal-[a-z0-9]+-[a-z]+-3.9-${{ env.RELEASE_VERSION_N }}-\d{8}-${{ steps.hash-n.outputs.HASH_N }}" "v2-${{ env.RELEASE_VERSION_N }}-\d{8}+-${{ steps.hash-n.outputs.HASH_N }}" \ |
| 74 | + "v2-${{ env.RELEASE_VERSION_N }}-\d{8}+-${{ steps.hash-n.outputs.HASH_N }}" "cuda-[a-z]+-tensorflow-[a-z0-9]+-[a-z]+-3.9-${{ env.RELEASE_VERSION_N }}-\d{8}-${{ steps.hash-n.outputs.HASH_N }}" "v2-${{ env.RELEASE_VERSION_N }}-\d{8}+-${{ steps.hash-n.outputs.HASH_N }}" \ |
| 75 | + "codeserver-[a-z0-9]+-[a-z]+-3.9-${{ env.RELEASE_VERSION_N }}-\d{8}-${{ steps.hash-n.outputs.HASH_N }}") |
| 76 | +
|
| 77 | + for ((i=0;i<${#IMAGES[@]};++i)); do |
| 78 | + image=${IMAGES[$i]} |
| 79 | + echo "CHECKING: " $image |
| 80 | + regex=${REGEXES[$i]} |
| 81 | + img=$(cat manifests/base/params.env | grep -E "${image}=" | cut -d '=' -f2) |
| 82 | + registry=$(echo $img | cut -d '@' -f1) |
| 83 | + latest_tag=$(skopeo inspect docker://$img | jq -r --arg regex "$regex" '.RepoTags | map(select(. | test($regex))) | .[0]') |
| 84 | + digest=$(skopeo inspect docker://$registry:$latest_tag | jq .Digest | tr -d '"') |
| 85 | + output=$registry@$digest |
| 86 | + echo "NEW: " $output |
| 87 | + sed -i "s|${image}=.*|${image}=$output|" manifests/base/params.env |
| 88 | + done |
| 89 | + if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then |
| 90 | + git fetch origin ${{ env.DIGEST_UPDATER_BRANCH }} && git pull origin ${{ env.DIGEST_UPDATER_BRANCH }} && git add manifests/base/params.env && git commit -m "Update images for release N via ${{ env.DIGEST_UPDATER_BRANCH }} GitHub action" && git push origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 91 | + else |
| 92 | + echo "There were no changes detected in the images for the ${{ env.RELEASE_VERSION_N}}" |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: Fetch digest, and update the commit.env file |
| 96 | + run: | |
| 97 | + echo Latest commit is: ${{ steps.hash-n.outputs.HASH_N }} on ${{ env.RELEASE_VERSION_N}} |
| 98 | + COMMIT=("odh-minimal-notebook-image-commit-n" |
| 99 | + "odh-minimal-gpu-notebook-image-commit-n" |
| 100 | + "odh-pytorch-gpu-notebook-image-commit-n" |
| 101 | + "odh-generic-data-science-notebook-image-commit-n" |
| 102 | + "odh-tensorflow-gpu-notebook-image-commit-n" |
| 103 | + "odh-trustyai-notebook-image-commit-n" |
| 104 | + "odh-codeserver-notebook-image-commit-n") |
| 105 | +
|
| 106 | + for val in "${COMMIT[@]}"; do |
| 107 | + echo $val |
| 108 | + sed -i "s|${val}=.*|${val}=${{ steps.hash-n.outputs.HASH_N }}|" manifests/base/commit.env |
| 109 | + done |
| 110 | + if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then |
| 111 | + git fetch origin ${{ env.DIGEST_UPDATER_BRANCH }} && git pull origin ${{ env.DIGEST_UPDATER_BRANCH }} && git add manifests/base/commit.env && git commit -m "Update image commits for release N via ${{ env.DIGEST_UPDATER_BRANCH }} GitHub action" && git push origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 112 | + else |
| 113 | + echo "There were no changes detected in the images for the ${{ env.RELEASE_VERSION_N}}" |
| 114 | + fi |
| 115 | +
|
| 116 | + update-n-1-version: |
| 117 | + needs: [initialize, update-n-version] |
| 118 | + runs-on: ubuntu-latest |
| 119 | + permissions: |
| 120 | + contents: write |
| 121 | + steps: |
| 122 | + - name: Configure Git |
| 123 | + run: | |
| 124 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 125 | + git config --global user.name "GitHub Actions" |
| 126 | +
|
| 127 | + # Get latest build commit from the https://github.com/red-hat-data-services/notebooks/${release_branch} using this as identifier for the latest tag name |
| 128 | + - name: Retrive latest commit hash from the release branch |
| 129 | + id: hash-n-1 |
| 130 | + shell: bash |
| 131 | + run: | |
| 132 | + PAYLOAD=$(curl --silent -H 'Accept: application/vnd.github.v4.raw' https://api.github.com/repos/red-hat-data-services/notebooks/commits?sha=release-$RELEASE_VERSION_N_1&per_page=1) |
| 133 | + echo "HASH_N_1=$(echo $PAYLOAD | jq -r '.[0].sha[0:7]')" >> ${GITHUB_OUTPUT} |
| 134 | +
|
| 135 | + # Checkout the release branch to apply the updates |
| 136 | + - name: Checkout release branch |
| 137 | + uses: actions/checkout@v4 |
| 138 | + with: |
| 139 | + ref: ${{ env.DIGEST_UPDATER_BRANCH }} |
| 140 | + |
| 141 | + - name: Fetch digest, and update the params.env file |
| 142 | + shell: bash |
| 143 | + run: | |
| 144 | + echo Latest commit is: ${{ steps.hash-n-1.outputs.HASH_N_1 }} on ${{ env.RELEASE_VERSION_N_1}} |
| 145 | + IMAGES=("odh-minimal-notebook-image-n-1" "odh-minimal-gpu-notebook-image-n-1" "odh-pytorch-gpu-notebook-image-n-1" "odh-generic-data-science-notebook-image-n-1" "odh-tensorflow-gpu-notebook-image-n-1" "odh-trustyai-notebook-image-n-1" "odh-codeserver-notebook-image-n-1") |
| 146 | + REGEXES=("v2-${{ env.RELEASE_VERSION_N_1 }}-\d{8}+-${{ steps.hash-n-1.outputs.HASH_N_1 }}" "cuda-[a-z]+-minimal-[a-z0-9]+-[a-z]+-3.9-${{ env.RELEASE_VERSION_N_1 }}-\d{8}-${{ steps.hash-n-1.outputs.HASH_N_1 }}" "v2-${{ env.RELEASE_VERSION_N_1 }}-\d{8}+-${{ steps.hash-n-1.outputs.HASH_N_1 }}" \ |
| 147 | + "v2-${{ env.RELEASE_VERSION_N_1 }}-\d{8}+-${{ steps.hash-n-1.outputs.HASH_N_1 }}" "cuda-[a-z]+-tensorflow-[a-z0-9]+-[a-z]+-3.9-${{ env.RELEASE_VERSION_N_1 }}-\d{8}-${{ steps.hash-n-1.outputs.HASH_N_1 }}" "v2-${{ env.RELEASE_VERSION_N_1 }}-\d{8}+-${{ steps.hash-n-1.outputs.HASH_N_1 }}" \ |
| 148 | + "codeserver-[a-z0-9]+-[a-z]+-3.9-${{ env.RELEASE_VERSION_N_1 }}-\d{8}-${{ steps.hash-n-1.outputs.HASH_N_1 }}") |
| 149 | +
|
| 150 | + for ((i=0;i<${#IMAGES[@]};++i)); do |
| 151 | + image=${IMAGES[$i]} |
| 152 | + echo "CHECKING: " $image |
| 153 | + regex=${REGEXES[$i]} |
| 154 | + img=$(cat manifests/base/params.env | grep -E "${image}=" | cut -d '=' -f2) |
| 155 | + registry=$(echo $img | cut -d '@' -f1) |
| 156 | + latest_tag=$(skopeo inspect docker://$img | jq -r --arg regex "$regex" '.RepoTags | map(select(. | test($regex))) | .[0]') |
| 157 | + digest=$(skopeo inspect docker://$registry:$latest_tag | jq .Digest | tr -d '"') |
| 158 | + output=$registry@$digest |
| 159 | + echo "NEW: " $output |
| 160 | + sed -i "s|${image}=.*|${image}=$output|" manifests/base/params.env |
| 161 | + done |
| 162 | + if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then |
| 163 | + git fetch origin ${{ env.DIGEST_UPDATER_BRANCH }} && git pull origin ${{ env.DIGEST_UPDATER_BRANCH }} && git add manifests/base/params.env && git commit -m "Update images for release N-1 via ${{ env.DIGEST_UPDATER_BRANCH }} GitHub action" && git push origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 164 | + else |
| 165 | + echo "There were no changes detected in the images for the ${{ env.RELEASE_VERSION_N}}" |
| 166 | + fi |
| 167 | +
|
| 168 | + - name: Fetch digest, and update the commit.env file |
| 169 | + run: | |
| 170 | + echo Latest commit is: ${{ steps.hash-n-1.outputs.HASH_N_1 }} on ${{ env.RELEASE_VERSION_N_1}} |
| 171 | + COMMIT=("odh-minimal-notebook-image-commit-n-1" |
| 172 | + "odh-minimal-gpu-notebook-image-commit-n-1" |
| 173 | + "odh-pytorch-gpu-notebook-image-commit-n-1" |
| 174 | + "odh-generic-data-science-notebook-image-commit-n-1" |
| 175 | + "odh-tensorflow-gpu-notebook-image-commit-n-1" |
| 176 | + "odh-trustyai-notebook-image-commit-n-1" |
| 177 | + "odh-codeserver-notebook-image-commit-n-1") |
| 178 | +
|
| 179 | + for val in "${COMMIT[@]}"; do |
| 180 | + echo $val |
| 181 | + sed -i "s|${val}=.*|${val}=${{ steps.hash-n-1.outputs.HASH_N_1 }}|" manifests/base/commit.env |
| 182 | + done |
| 183 | + if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then |
| 184 | + git fetch origin ${{ env.DIGEST_UPDATER_BRANCH }} && git pull origin ${{ env.DIGEST_UPDATER_BRANCH }} && git add manifests/base/commit.env && git commit -m "Update image commits for release N-1 via ${{ env.DIGEST_UPDATER_BRANCH }} GitHub action" && git push origin ${{ env.DIGEST_UPDATER_BRANCH }} |
| 185 | + else |
| 186 | + echo "There were no changes detected in the images for the ${{ env.RELEASE_VERSION_N}}" |
| 187 | + fi |
| 188 | +
|
| 189 | + open-pull-request: |
| 190 | + needs: [update-n-version, update-n-1-version] |
| 191 | + runs-on: ubuntu-latest |
| 192 | + permissions: |
| 193 | + pull-requests: write |
| 194 | + steps: |
| 195 | + - name: Checkout repo |
| 196 | + uses: actions/checkout@v4 |
| 197 | + |
| 198 | + - name: pull-request |
| 199 | + uses: repo-sync/pull-request@v2 |
| 200 | + with: |
| 201 | + source_branch: ${{ env.DIGEST_UPDATER_BRANCH }} |
| 202 | + destination_branch: ${{ env.BRANCH_NAME}} |
| 203 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 204 | + pr_label: "automated pr" |
| 205 | + pr_title: "[Digest Updater Action] Update Notebook Images" |
| 206 | + pr_body: | |
| 207 | + :rocket: This is an automated Pull Request. |
| 208 | + Created by `/.github/workflows/notebooks-digest-updater-upstream.yaml` |
| 209 | +
|
| 210 | + This PR updates the following files: |
| 211 | + - `manifests/base/params.env` file with the latest updated SHA digests of the notebooks (N & N-1). |
| 212 | + - `manifests/base/commit.env` file with the latest commit (N & N-1). |
| 213 | +
|
| 214 | + :exclamation: **IMPORTANT NOTE**: Remember to delete the ` ${{ env.DIGEST_UPDATER_BRANCH }}` branch after merging the changes |
0 commit comments