From 911f6c64160df665e7f7db120c3c2c8842ac5e5b Mon Sep 17 00:00:00 2001 From: Suraj Kota Date: Fri, 1 Jul 2022 02:35:50 +0000 Subject: [PATCH] add auto script for kserve and kserve models webapp manifests --- hack/sync-kserve-manifests.sh | 118 ++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100755 hack/sync-kserve-manifests.sh diff --git a/hack/sync-kserve-manifests.sh b/hack/sync-kserve-manifests.sh new file mode 100755 index 0000000000..c45b96b4fc --- /dev/null +++ b/hack/sync-kserve-manifests.sh @@ -0,0 +1,118 @@ +#!/usr/bin/env bash + +# This script aims at helping create a PR to update the manifests of the +# kubeflow/pipelines repo. +# This script: +# 1. Checks out a new branch +# 2. Copies files to the correct places +# 3. Commits the changes +# +# Afterwards the developers can submit the PR to the kubeflow/manifests +# repo, based on that local branch + +# strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail +IFS=$'\n\t' + +CLONE_DIR=${CLONE_DIR:=/tmp} +KSERVE_DIR="${CLONE_DIR?}/kserve" +WEBAPP_DIR="${CLONE_DIR?}/models-web-app" +BRANCH=${BRANCH:=sync-kserve-manifests-${KSERVE_COMMIT?}} +# required only if commit does not match the tag +KSERVE_VERSION=${KSERVE_VERSION:=${KSERVE_COMMIT?}} +WEBAPP_VERSION=${WEBAPP_VERSION:=${WEBAPP_COMMIT?}} + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +MANIFESTS_DIR=$(dirname "${SCRIPT_DIR}") + +echo "Creating branch: ${BRANCH}" + +# DEV: Comment out this if when local testing +if [ -n "$(git status --porcelain)" ]; then + # Uncommitted changes + echo "WARNING: You have uncommitted changes, exiting..." +# exit 1 +fi + +if [ "$(git branch --list "${BRANCH}")" ] +then + echo "WARNING: Branch ${BRANCH} already exists. Exiting..." + exit 1 +fi + +# DEV: Comment out this checkout command when local testing +git checkout -b "${BRANCH}" + +echo "Checking out in $KSERVE_DIR to $KSERVE_COMMIT..." +pushd $CLONE_DIR + if [ ! -d "$KSERVE_DIR" ] + then + git clone https://github.com/kserve/kserve.git && cd kserve + git checkout "${KSERVE_COMMIT}" + else + echo "WARNING: ${KSERVE_DIR} directory already exists. Exiting..." + exit 1 + fi +popd + +echo "Copying kserve manifests..." +SRC_MANIFEST_PATH="$KSERVE_DIR"/install/"$KSERVE_VERSION" +if [ ! -d "$SRC_MANIFEST_PATH" ] +then + echo "Directory $SRC_MANIFEST_PATH DOES NOT exists." + exit 1 +fi + +DST_DIR=$MANIFESTS_DIR/contrib/kserve/kserve +pushd "$DST_DIR" + rm -rf kserve* +popd +cp "$SRC_MANIFEST_PATH"/* "$DST_DIR" -r + + +echo "Successfully copied kserve manifests." + +echo "Updating README..." +SRC_TXT="\[.*\](https://github.com/kserve/kserve/tree/.*)" +DST_TXT="\[$KSERVE_COMMIT\](https://github.com/kserve/kserve/tree/$KSERVE_COMMIT/install/$KSERVE_VERSION)" + +sed -i "s|$SRC_TXT|$DST_TXT|g" "${MANIFESTS_DIR}"/README.md + +echo "Checking out in $WEBAPP_DIR to $WEBAPP_COMMIT..." +pushd $CLONE_DIR + if [ ! -d "$WEBAPP_DIR" ] + then + git clone https://github.com/kserve/models-web-app.git && cd models-web-app + git checkout "${WEBAPP_COMMIT}" + else + echo "WARNING: ${WEBAPP_DIR} directory already exists. Exiting..." + exit 1 + fi +popd + +echo "Copying kserve models web app manifests..." +SRC_MANIFEST_PATH="$WEBAPP_DIR"/config +if [ ! -d "$SRC_MANIFEST_PATH" ] +then + echo "Directory $SRC_MANIFEST_PATH DOES NOT exists." + exit 1 +fi + +DST_DIR=$MANIFESTS_DIR/contrib/kserve/models-web-app +rm -r "$DST_DIR" +cp "$SRC_MANIFEST_PATH" "$DST_DIR" -r + +echo "Successfully copied kserve manifests." + +echo "Updating README..." +SRC_TXT="\[.*\](https://github.com/kserve/models-web-app/tree/.*)" +DST_TXT="\[$WEBAPP_COMMIT\](https://github.com/kserve/models-web-app/tree/$WEBAPP_COMMIT/config)" + +sed -i "s|$SRC_TXT|$DST_TXT|g" "${MANIFESTS_DIR}"/README.md + +# DEV: Comment out these commands when local testing +echo "Committing the changes..." +cd "$MANIFESTS_DIR" +git add contrib/kserve +git add README.md +git commit -m "Update kserve manifests from ${KSERVE_VERSION}" -m "Update kserve/kserve manifests from ${KSERVE_COMMIT}" -m "Update kserve/models-web-app manifests from ${WEBAPP_COMMIT}"