Skip to content

Commit

Permalink
enable GMC system installation on push (#158)
Browse files Browse the repository at this point in the history
Signed-off-by: Yingchun Guo <[email protected]>
  • Loading branch information
daisy-ycguo authored Jul 5, 2024
1 parent 07494c0 commit af2d0f5
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 60 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/gmc-on-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

name: Upgrade GMC system on push event

on:
push:
branches: ["main"]
paths:
- microservices-connector/**
- manifests/**
- "!**.md"
- "!**.txt"
- "!**.png"
- "!.**"
- .github/workflows/gmc-on-push.yaml

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-on-push
cancel-in-progress: true

env:
GOSRC_DIR: "microservices-connector"

jobs:
image-build:
strategy:
matrix:
platform: [xeon, gaudi]
uses: ./.github/workflows/reuse-gmc-image-build.yaml
with:
image_tag: 'latest'
runner_label: 'docker-build-${{ matrix.platform }}'

gmc-install:
strategy:
matrix:
platform: [xeon, gaudi]
needs: image-build
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout out Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set variables
run: |
echo "SYSTEM_NAMESPACE=opea-system" >> $GITHUB_ENV
# don't set IMAGE_REPO to the outputs because outputs.image_repo may not be correct
# echo "IMAGE_REPO=${{ needs.image-build.outputs.image_repo }}" >> $GITHUB_ENV
echo "VERSION=${{ needs.image-build.outputs.image_tag }}" >> $GITHUB_ENV
- name: Cleanup existing GMC
run: |
.github/workflows/scripts/e2e/gmc_install.sh cleanup_gmc
- name: Install GMC
run: |
.github/workflows/scripts/e2e/gmc_install.sh install_gmc
56 changes: 0 additions & 56 deletions .github/workflows/image-build-on-push.yaml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/reuse-gmc-image-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ on:
runner_label:
required: false
type: string
default: 'xeon'
default: 'docker-build-xeon'
outputs:
image_repo:
description: "The image repository used for the image build"
value: ${{ jobs.image-build.outputs.docker_registry }}
value: ${{ jobs.image-build.outputs.image_repo }}
image_tag:
description: "The image tag used for the image build"
value: ${{ jobs.image-build.outputs.version }}
Expand All @@ -30,7 +30,7 @@ jobs:
image-build:
runs-on: ${{ inputs.runner_label }}
outputs:
docker_registry: ${{ steps.set_variables.outputs.DOCKER_REGISTRY }}
image_repo: ${{ steps.set_variables.outputs.IMAGE_REPO }}
version: ${{ steps.set_variables.outputs.VERSION }}
steps:
- name: Checkout out Repo
Expand All @@ -43,7 +43,7 @@ jobs:
run: |
echo "DOCKER_REGISTRY=${OPEA_IMAGE_REPO}opea" >> $GITHUB_ENV
echo "VERSION=${{ inputs.image_tag }}" >> $GITHUB_ENV
echo "DOCKER_REGISTRY=${OPEA_IMAGE_REPO}opea" >> $GITHUB_OUTPUT
echo "IMAGE_REPO=${OPEA_IMAGE_REPO}" >> $GITHUB_OUTPUT
echo "VERSION=${{ inputs.image_tag }}" >> $GITHUB_OUTPUT
- name: Build image and push
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/scripts/e2e/gmc_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

set -xe

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source ${DIR}/utils.sh

USER_ID=$(whoami)
LOG_PATH=/home/$(whoami)/logs
MOUNT_DIR=${KIND_MOUNT_DIR:-"/home/$USER_ID/.cache/huggingface/hub"}
TOKEN_DIR=${KIND_TOKEN_DIR:-"/home/$USER_ID/.cache/huggingface/token"}
IMAGE_REPO=${OPEA_IMAGE_REPO:-""}
VERSION=${VERSION:-"latest"}

function install_gmc() {
PLATFORM=${1:-"xeon"}
# Make sure you have to use image tag $VERSION for microservice-connector installation
echo "install microservice-connector on $PLATFORM, using repo $IMAGE_REPO and tag $VERSION"
echo "using namespace $SYSTEM_NAMESPACE"

init_gmc

kubectl apply -f $(pwd)/config/crd/bases/gmc.opea.io_gmconnectors.yaml
kubectl apply -f $(pwd)/config/rbac/gmc-manager-rbac.yaml
kubectl create configmap gmcyaml -n $SYSTEM_NAMESPACE --from-file $(pwd)/config/manifests
kubectl apply -f $(pwd)/config/manager/gmc-manager.yaml

# Wait until the gmc controller pod is ready
wait_until_pod_ready "gmc-controller" $SYSTEM_NAMESPACE "gmc-controller"
kubectl get pods -n $SYSTEM_NAMESPACE
}

function copy_manifests() {
# Copy manifest into gmc
mkdir -p $(pwd)/config/manifests
cp $(dirname $(pwd))/manifests/ChatQnA/*.yaml -p $(pwd)/config/manifests/
cp $(dirname $(pwd))/manifests/DocSum/xeon/docsum_llm.yaml -p $(pwd)/config/manifests/
cp $(dirname $(pwd))/manifests/DocSum/gaudi/docsum_gaudi_llm.yaml -p $(pwd)/config/manifests/
}

function init_gmc() {
# copy manifests
copy_manifests

# replace tag with for the gmc-router and gmc-manager image
sed -i "s|opea/\(.*\):latest|opea/\1:$VERSION|g" $(pwd)/config/gmcrouter/gmc-router.yaml
sed -i "s|opea/\(.*\):latest|opea/\1:$VERSION|g" $(pwd)/config/manager/gmc-manager.yaml
# replace the pull policy "IfNotPresent" with "Always"
sed -i "s#pullPolicy: IfNotPresent#pullPolicy: Always#g" $(pwd)/config/gmcrouter/gmc-router.yaml
sed -i "s#pullPolicy: IfNotPresent#pullPolicy: Always#g" $(pwd)/config/manager/gmc-manager.yaml

cp $(pwd)/config/gmcrouter/gmc-router.yaml -p $(pwd)/config/manifests/

# replace namespace for gmc-router and gmc-manager
sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" $(pwd)/config/manager/gmc-manager.yaml
sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" $(pwd)/config/rbac/gmc-manager-rbac.yaml
sed -i "s|name: system|name: $SYSTEM_NAMESPACE|g" $(pwd)/config/rbac/gmc-manager-rbac.yaml

# replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT"
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt/models#path: $MOUNT_DIR#g" {} \;
# replace the repository "image: opea/*" with "image: ${IMAGE_REPO}opea/"
find . -name '*.yaml' -type f -exec sed -i "s#image: opea/*#image: ${IMAGE_REPO}opea/#g" {} \;
find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: \"${IMAGE_REPO}opea/#g" {} \;
# set huggingface token
# find . -name '*.yaml' -type f -exec sed -i "s#insert-your-huggingface-token-here#$(cat $TOKEN_DIR)#g" {} \;
find . -name '*.yaml' -type f -exec sed -i "s#insert-your-huggingface-token-here#$(cat $TOKEN_DIR)#g" {} \;
}

function cleanup_gmc() {
echo "clean up microservice-connector"
if kubectl get namespace $SYSTEM_NAMESPACE > /dev/null 2>&1; then
echo "Deleting namespace: $SYSTEM_NAMESPACE"
kubectl delete namespace "$SYSTEM_NAMESPACE"
kubectl delete crd gmconnectors.gmc.opea.io
else
echo "Namespace $SYSTEM_NAMESPACE does not exist"
fi
}

#------MAIN-----------
if [ $# -eq 0 ]; then
echo "Usage: $0 <function_name>"
exit 1
fi
case "$1" in
install_gmc)
pushd microservices-connector
install_gmc
popd
;;
cleanup_gmc)
cleanup_gmc
;;
*)
echo "Unknown function: $1"
;;
esac
49 changes: 49 additions & 0 deletions .github/workflows/scripts/e2e/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

function wait_until_pod_ready() {
echo "Waiting for the $1 to be ready..."
max_retries=30
retry_count=0
while ! is_pod_ready $2 $3; do
if [ $retry_count -ge $max_retries ]; then
echo "$1 is not ready after waiting for a significant amount of time"
get_gmc_controller_logs
exit 1
fi
echo "$1 is not ready yet. Retrying in 30 seconds..."
sleep 30
output=$(kubectl get pods -n $2)
echo $output
retry_count=$((retry_count + 1))
done
}

function is_pod_ready() {
if [ "$2" == "gmc-controller" ]; then
pod_status=$(kubectl get pods -n $1 -o jsonpath='{.items[].status.conditions[?(@.type=="Ready")].status}')
else
pod_status=$(kubectl get pods -n $1 -l app=$2 -o jsonpath='{.items[].status.conditions[?(@.type=="Ready")].status}')
fi
if [ "$pod_status" == "True" ]; then
return 0
else
return 1
fi
}

function get_gmc_controller_logs() {
# Fetch the name of the pod with the app-name gmc-controller in the specified namespace
pod_name=$(kubectl get pods -n $SYSTEM_NAMESPACE -l control-plane=gmc-controller -o jsonpath='{.items[0].metadata.name}')

# Check if the pod name was found
if [ -z "$pod_name" ]; then
echo "No pod found with app-name gmc-controller in namespace $SYSTEM_NAMESPACE"
return 1
fi

# Get the logs of the found pod
echo "Fetching logs for pod $pod_name in namespace $SYSTEM_NAMESPACE..."
kubectl logs $pod_name -n $SYSTEM_NAMESPACE
}

0 comments on commit af2d0f5

Please sign in to comment.