Skip to content

Commit

Permalink
Merge pull request red-hat-data-services#175 from opendatahub-io/v1.9…
Browse files Browse the repository at this point in the history
…-branch

Sync main from odh:v1.9-branch
  • Loading branch information
atheo89 authored Nov 28, 2024
2 parents 89fa715 + 343990c commit e61d16d
Show file tree
Hide file tree
Showing 19 changed files with 621 additions and 229 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Create Release
on:
workflow_dispatch:
inputs:
input_var:
description: "Say Hi!"
required: true
workflow_call:
inputs:
input_var:
type: string
required: true

env:
INPUT_VAR: ${{ inputs.input_var }}

jobs:
say-hello:
runs-on: ubuntu-latest

steps:
- name: Say Hello
run: echo "${{ env.INPUT_VAR }}, World!"
138 changes: 138 additions & 0 deletions .github/workflows/kubeflow-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
name: Kubeflow Release Pipeline
on:
workflow_dispatch:
inputs:
create-new-release:
description: "Create a new release?"
required: true
default: "true"
env:
CREATE_NEW_RELEASE: ${{ inputs.create-new-release }}
REPO_OWNER: opendatahub-io
REPO_NAME: kubeflow
BRANCH_NAME: v1.9-branch

jobs:
# 1. Sync changes to opendatahub:v1.9-branch from opendatahub:main
sync-main-to-release-branch:
uses: opendatahub-io/kubeflow/.github/workflows/sync-branches.yaml@main
with:
source: "main"
target: "v1.9-branch"

# 2. Poll for images to be available on quay.io the readiness of the images usually takes ~10 mins
wait-images-are-ready-on-quay:
needs: sync-main-to-release-branch
runs-on: ubuntu-latest
outputs:
images_ready: ${{ steps.check-images.outputs.images_ready }}
steps:
- name: Poll for images availability
id: check-images
run: |
# Install required tools
sudo apt-get update
sudo apt-get install -y skopeo jq curl
# Get the latest Git hash from the target branch
PAYLOAD=$(curl --silent -H 'Accept: application/vnd.github.v4.raw' https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/commits?sha=$BRANCH_NAME&per_page=1)
GIT_HASH=$(echo "$PAYLOAD" | jq -r '.[0].sha' | cut -c 1-7)
echo "GIT_HASH=$GIT_HASH"
# Images to check
IMAGES=(
"quay.io/opendatahub/kubeflow-notebook-controller:1.9-${GIT_HASH}"
"quay.io/opendatahub/odh-notebook-controller:1.9-${GIT_HASH}"
)
# Poll for image readiness total timeout=15m
MAX_ATTEMPTS=10
SLEEP_DURATION=90
for image in "${IMAGES[@]}"; do
for (( i=1; i<=MAX_ATTEMPTS; i++ )); do
echo "Checking availability of $image (Attempt $i/$MAX_ATTEMPTS)..."
if skopeo inspect docker://$image &>/dev/null; then
echo "$image is available!"
break
fi
if [[ $i -eq $MAX_ATTEMPTS ]]; then
echo "Timed out waiting for $image to become available."
exit 1
fi
sleep $SLEEP_DURATION
done
done
echo "images_ready=true" >> $GITHUB_ENV
echo "images_ready=true" >> $GITHUB_OUTPUT
- name: Images are ready
if: ${{ env.images_ready == 'true' }}
run: echo "All images are ready. Proceeding to the next step."

# 3. Once Images are availble then updates the notebook controllers’ image tags
update-release-images:
needs: wait-images-are-ready-on-quay
if: ${{ needs.wait-images-are-ready-on-quay.outputs.images_ready == 'true' }}
uses: opendatahub-io/kubeflow/.github/workflows/notebook-controller-images-updater.yaml@main
with:
branch-name: "v1.9-branch"
organization: "opendatahub-io"
generate-pr: "true"

# 4. Check PR merged status
check-pr-merged:
needs: update-release-images
runs-on: ubuntu-latest
outputs:
pr_merged: ${{ steps.check.outputs.pr_merged }}
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Check if the PR is merged
id: check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# PR to look for
PR_TITLE="[GHA-${{ github.run_id }}]"
# Fetch matching PRs
PR_NUMBER=$(gh pr list --repo "$REPO_OWNER/$REPO_NAME" --state all --search "$PR_TITLE" --json number,title | jq -r '.[0].number')
echo "PR number: $PR_NUMBER"
if [ -z "$PR_NUMBER" ]; then
echo "No matching PR found."
exit 1
fi
# Polling loop to wait for the PR to be merged total timeout=1h
MAX_ATTEMPTS=10
SLEEP_DURATION=360
for (( i=1; i<=MAX_ATTEMPTS; i++ )); do
echo "Checking if PR #$PR_NUMBER is merged (Attempt $i/$MAX_ATTEMPTS)..."
PR_STATE=$(gh pr view --repo "$REPO_OWNER/$REPO_NAME" $PR_NUMBER --json mergedAt --jq '.mergedAt')
if [ "$PR_STATE" = "null" ] || [ -z "$PR_STATE" ]; then
echo "PR #$PR_NUMBER is not merged yet. Waiting..."
sleep $SLEEP_DURATION
else
echo "PR #$PR_NUMBER is merged!"
echo "pr_merged=true" >> $GITHUB_ENV
echo "pr_merged=true" >> $GITHUB_OUTPUT
exit 0
fi
done
echo "Timed out waiting for PR #$PR_NUMBER to be merged."
echo "pr_merged=false" >> $GITHUB_ENV
echo "pr_merged=false" >> $GITHUB_OUTPUT
exit 1
# 5. Create a release (Mock-Up workflow it will be fullfill by RHOAIENG-15391)
create-release:
needs: [update-release-images, check-pr-merged]
if: ${{ needs.check-pr-merged.outputs.pr_merged == 'true' && inputs.create-new-release == 'true' }}
uses: opendatahub-io/kubeflow/.github/workflows/create-release.yaml@main
with:
input_var: "Eyo"
88 changes: 58 additions & 30 deletions .github/workflows/notebook-controller-images-updater.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
---
# This is a gha updates automaticaly the notebook controller images. Can be run on demand before a new release
name: Update Notebook Controller Images With Latest Commit ID
on: # yamllint disable-line rule:truthy
# This workflow automatically updates the notebook controllers' image tags
name: Update Notebook Controllers' Image Tags
on:
workflow_dispatch:
inputs:
branch-name:
description: "Provide name of the branch, ex: v1.9-branch"
description: "Provide name of the branch, used to commit changes"
required: true
default: "v1.9-branch"
default: "main"
organization:
required: true
description: "Owner of origin notebooks repository used to open a PR"
description: "Owner of origin kubeflow repository"
default: "opendatahub-io"
generate-pr:
description: "Create PR?"
required: true
default: "true"
workflow_call:
inputs:
branch-name:
description: "Provide name of the branch, used to commit changes"
required: true
type: string
organization:
description: "Owner of origin kubeflow repository"
required: true
type: string
generate-pr:
description: "Create PR?"
required: true
type: string

env:
REPO_OWNER: ${{ github.event.inputs.organization }}
REPO_OWNER: ${{ inputs.organization }}
TEMP_UPDATER_BRANCH: temp-${{ inputs.branch-name }}-${{ github.run_id }}
BRANCH_NAME: ${{ inputs.branch-name }}
GENERATE_PR: ${{ inputs.generate-pr }}
REPO_NAME: kubeflow
TEMP_UPDATER_BRANCH: temp-${{ github.run_id }}
BRANCH_NAME: ${{ github.event.inputs.branch-name }}

jobs:
update-notebook-controller-images:
Expand All @@ -26,28 +46,29 @@ jobs:
pull-requests: write

steps:
- name: Configure Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
- name: Checkout branch
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH_NAME }}

- name: Checkout new branch
run: |
echo ${{ env.TEMP_UPDATER_BRANCH }}
git checkout -b ${{ env.TEMP_UPDATER_BRANCH }}
git push --set-upstream origin ${{ env.TEMP_UPDATER_BRANCH }}
- name: Configure Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
echo ${{ env.TEMP_UPDATER_BRANCH }}
git fetch origin
git checkout -b ${{ env.TEMP_UPDATER_BRANCH }} origin/${{ env.BRANCH_NAME }}
git push --set-upstream origin ${{ env.TEMP_UPDATER_BRANCH }}
- name: Retrive latest commit
- name: Retrieve latest commit
id: commit-id
shell: bash
run: |
PAYLOAD=$(curl --silent -H 'Accept: application/vnd.github.v4.raw' https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/commits?sha=$BRANCH_NAME&per_page=1)
echo "COMMIT_ID=$(echo $PAYLOAD | jq -r '.[0].sha[0:7]')" >> ${GITHUB_OUTPUT}
echo "GIT_HASH=$(echo $PAYLOAD | jq -r '.[0].sha[0:7]')" >> ${GITHUB_OUTPUT}
- name: Extract version from branch-name
id: version
Expand All @@ -57,7 +78,7 @@ jobs:
else
VERSION=$(echo "${{ env.BRANCH_NAME }}" | sed -E 's/^v([0-9]+\.[0-9]+)-.*/\1/')
# Check if VERSION is empty, then, assign the full branch name
# Check if VERSION is empty, then assign the full branch name
if [[ -z "$VERSION" ]]; then
VERSION="${{ env.BRANCH_NAME }}"
fi
Expand All @@ -68,12 +89,12 @@ jobs:
- name: Update related files
id: apply-changes
run: |
COMMIT_ID=${{ steps.commit-id.outputs.COMMIT_ID }}
GIT_HASH=${{ steps.commit-id.outputs.GIT_HASH }}
VERSION=${{ steps.version.outputs.VERSION }}
echo "Updating files in VERSION=${VERSION} with COMMIT_ID=${COMMIT_ID}"
sed -E "s/(odh-kf-notebook-controller-image=quay\.io\/opendatahub\/kubeflow-notebook-controller:)[^: -]+(-)[^ ]+/\1$VERSION\2$COMMIT_ID/" -i components/notebook-controller/config/overlays/openshift/params.env
sed -E "s/(odh-notebook-controller-image=quay\.io\/opendatahub\/odh-notebook-controller:)[^: -]+(-)[^ ]+/\1$VERSION\2$COMMIT_ID/" -i components/odh-notebook-controller/config/base/params.env
sed -E "s/(KF_TAG \?= )[^\-]+(-)[^ ]+/\1$VERSION\2$COMMIT_ID/" -i components/odh-notebook-controller/makefile-vars.mk
echo "Updating files in VERSION=${VERSION} with GIT_HASH=${GIT_HASH}"
sed -E "s/(odh-kf-notebook-controller-image=quay\.io\/opendatahub\/kubeflow-notebook-controller:)[^: -]+(-)[^ ]+/\1$VERSION\2$GIT_HASH/" -i components/notebook-controller/config/overlays/openshift/params.env
sed -E "s/(odh-notebook-controller-image=quay\.io\/opendatahub\/odh-notebook-controller:)[^: -]+(-)[^ ]+/\1$VERSION\2$GIT_HASH/" -i components/odh-notebook-controller/config/base/params.env
sed -E "s/(KF_TAG \?= )[^\-]+(-)[^ ]+/\1$VERSION\2$GIT_HASH/" -i components/odh-notebook-controller/makefile-vars.mk
git status
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
Expand All @@ -83,14 +104,14 @@ jobs:
git add components/notebook-controller/config/overlays/openshift/params.env
git add components/odh-notebook-controller/config/base/params.env
git add components/odh-notebook-controller/makefile-vars.mk
git commit -m ":robot: Update odh and notebook-controller with image ${VERSION}-${COMMIT_ID}"
git commit -m "Update odh and notebook-controller with image ${VERSION}-${GIT_HASH}"
git push origin ${{ env.TEMP_UPDATER_BRANCH }}
git log --oneline
else
echo "There were no changes detected on ${{ env.BRANCH_NAME }}"
fi
- name: Create Pull Request
- name: PR Cretation
if: ${{ env.GENERATE_PR == 'true' }}
run: |
gh pr create --repo https://github.com/$REPO_OWNER/$REPO_NAME.git \
--title "$pr_title" \
Expand All @@ -99,7 +120,7 @@ jobs:
--base ${{ env.BRANCH_NAME }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pr_title: "[GHA] Update odh and notebook-controller with image ${{ steps.version.outputs.VERSION }}-${{ steps.commit-id.outputs.COMMIT_ID }}"
pr_title: "[GHA-${{ github.run_id }}] Update odh and notebook-controller with image ${{ steps.version.outputs.VERSION }}-${{ steps.commit-id.outputs.GIT_HASH }}"
pr_body: |
:robot: This is an automated Pull Request created by `/.github/workflows/notebook-controller-images-updater.yaml`.
Expand All @@ -108,3 +129,10 @@ jobs:
- components/odh-notebook-controller/config/base/params.env
- components/odh-notebook-controller/makefile-vars.mk
- name: Auto Merge Changes to Target Branch
if: ${{ env.GENERATE_PR != 'true' }}
run: |
git fetch origin
git checkout ${{ env.BRANCH_NAME }}
git merge --no-ff ${{ env.TEMP_UPDATER_BRANCH }} -m ":robot: Update odh and notebook-controller with image ${VERSION}-${GIT_HASH} auto-merged changes from ${{ env.TEMP_UPDATER_BRANCH }}"
git push origin ${{ env.BRANCH_NAME }}
Loading

0 comments on commit e61d16d

Please sign in to comment.