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

Kubeflow sync release pipeline #469

Merged
merged 8 commits into from
Nov 28, 2024
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 @@
---
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @andyatmiami! This is only a mockup gha, it prints a Eyo, World for now 🤣 It used to work on the logic of the kubeflow release.

Copy link

@andyatmiami andyatmiami Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, fwiw... and I'm happy to change what I did with the create release PoC I did.. but I was condititioning the release creation logic on the push of a tag matching a specific pattern...

So it wouldn't need to be explicitly invoked here.. but if that "trigger off tag" won't work for reasons I am not appreciating - I am happy to adapt!

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!"
140 changes: 140 additions & 0 deletions .github/workflows/kubeflow-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
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-to-build-on-quay:
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
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: |
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
# 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)
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
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-to-build-on-quay
if: ${{ needs.wait-images-to-build-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
gh pr list --repo atheo89/kubeflow --state all --search "$PR_TITLE" --json number,title > pr_list.json
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
# Extract the PR number
PR_NUMBER=$(jq -r '.[0].number' pr_list.json)
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 atheo89/kubeflow $PR_NUMBER --json mergedAt --jq '.mergedAt')
atheo89 marked this conversation as resolved.
Show resolved Hide resolved

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"
86 changes: 61 additions & 25 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"
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -31,23 +51,32 @@ jobs:
with:
ref: ${{ env.BRANCH_NAME }}

- name: Debug Inputs
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
run: |
echo "generate-pr: ${{ env.GENERATE_PR }}"
echo "branch-name: ${{ env.BRANCH_NAME }}"
echo "organization: ${{ env.REPO_OWNER }}"
echo "temp-branch-name: ${{ env.TEMP_UPDATER_BRANCH }}"


- 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 }}
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: Configure Git
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"

- 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}
atheo89 marked this conversation as resolved.
Show resolved Hide resolved

- name: Extract version from branch-name
id: version
Expand All @@ -57,7 +86,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 +97,12 @@ jobs:
- name: Update related files
id: apply-changes
run: |
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
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 +112,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' }}
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
run: |
gh pr create --repo https://github.com/$REPO_OWNER/$REPO_NAME.git \
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
--title "$pr_title" \
Expand All @@ -99,7 +128,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 }}"
atheo89 marked this conversation as resolved.
Show resolved Hide resolved
pr_body: |
:robot: This is an automated Pull Request created by `/.github/workflows/notebook-controller-images-updater.yaml`.

Expand All @@ -108,3 +137,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