Skip to content

Commit

Permalink
Add docker build job in manifest e2e workflow (opea-project#274)
Browse files Browse the repository at this point in the history
Signed-off-by: Yingchun Guo <[email protected]>
  • Loading branch information
daisy-ycguo committed Jun 13, 2024
1 parent 2a48601 commit c5f3095
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 17 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/image-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

name: Image Build
permissions: read-all
on:
workflow_call:
inputs:
image-repo:
required: false
type: string
image-tag:
required: true
type: string
mega-service:
required: true
type: string
runner_lable:
required: false
type: string
default: 'docker-build'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-image-build

jobs:
mega-image-build:
runs-on: ${{ inputs.runner_lable }}
steps:
- name: Checkout out Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Building MegaService Docker Image
id: build-megaservice-image
env:
IMAGE_REPO: ${{ inputs.image-repo }}
IMAGE_TAG: ${{ inputs.image-tag }}
mega-service: ${{ inputs.mega-service }}
run: |
.github/workflows/scripts/build_push.sh ${{ env.mega-service}}
18 changes: 14 additions & 4 deletions .github/workflows/manifest-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,17 @@ jobs:
run_matrix=$run_matrix"]}"
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT
manifest-test:
mega-image-build:
needs: job1
if: always() && ${{ needs.job1.outputs.run_matrix.include.length }} > 0
strategy:
matrix: ${{ fromJSON(needs.job1.outputs.run_matrix) }}
uses: ./.github/workflows/image-build.yaml
with:
image-tag: ${{ github.event.pull_request.head.sha }}
mega-service: "${{ matrix.example }}"

manifest-test:
needs: [job1, mega-image-build]
strategy:
matrix: ${{ fromJSON(needs.job1.outputs.run_matrix) }}
runs-on: ${{ matrix.hardware }}
Expand All @@ -79,12 +87,14 @@ jobs:

- name: Set variables
run: |
echo "IMAGE_REPO=${OPEA_IMAGE_REPO}/" >> $GITHUB_ENV
echo "IMAGE_TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
lower_example=$(echo "${{ matrix.example }}" | tr '[:upper:]' '[:lower:]')
echo "NAMESPACE=$lower_example-$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
echo "ROLLOUT_TIMEOUT_SECONDS=1800s" >> $GITHUB_ENV
echo "KUBECTL_TIMEOUT_SECONDS=60s" >> $GITHUB_ENV
echo "should_cleanup=false" >> $GITHUB_ENV
echo "skip_validate=false" >> $GITHUB_ENV
echo "skip_validate=true" >> $GITHUB_ENV
echo "NAMESPACE=$NAMESPACE"
- name: Initialize manifest testing
Expand All @@ -100,9 +110,9 @@ jobs:
echo "Testing ${{ matrix.example }}, waiting for pod ready..."
if kubectl rollout status deployment --namespace "$NAMESPACE" --timeout "$ROLLOUT_TIMEOUT_SECONDS"; then
echo "Testing manifests ${{ matrix.example }}, waiting for pod ready done!"
echo "skip_validate=false" >> $GITHUB_ENV
else
echo "Timeout waiting for pods in namespace $NAMESPACE to be ready!"
echo "skip_validate=true" >> $GITHUB_ENV
exit 1
fi
sleep 60
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/scripts/build_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

set -xe

IMAGE_REPO=${IMAGE_REPO:-$OPEA_IMAGE_REPO}
IMAGE_TAG=${IMAGE_TAG:-latest}

function getImagenameFromMega() {
echo $(echo "$1" | tr '[:upper:]' '[:lower:]')
}

function checkExist() {
IMAGE_NAME=$1
if [ $(curl -X GET http://localhost:5000/v2/opea/${IMAGE_NAME}/tags/list | grep -c ${IMAGE_TAG}) -ne 0 ]; then
echo "true"
else
echo "false"
fi
}

function docker_build() {
# check if if IMAGE_TAG is not "latest" and the image exists in the registry
if [ $IMAGE_TAG != "latest" && $(checkExist $1) == "true" ]; then
echo "Image ${IMAGE_REPO}opea/$1:$IMAGE_TAG already exists in the registry"
return
fi
# docker_build <service_name> <dockerfile>
if [ -z "$2" ]; then
DOCKERFILE_PATH=Dockerfile
else
DOCKERFILE_PATH=$2
fi
echo "Building ${IMAGE_REPO}opea/$1:$IMAGE_TAG using Dockerfile $DOCKERFILE_PATH"
# if https_proxy and http_proxy are set, pass them to docker build
if [ -z "$https_proxy" ]; then
docker build --no-cache -t ${IMAGE_REPO}opea/$1:$IMAGE_TAG -f $DOCKERFILE_PATH .
else
docker build --no-cache -t ${IMAGE_REPO}opea/$1:$IMAGE_TAG --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f $DOCKERFILE_PATH .
fi
docker push ${IMAGE_REPO}opea/$1:$IMAGE_TAG
docker rmi ${IMAGE_REPO}opea/$1:$IMAGE_TAG
}

# $1 is like "apple orange pear"
for MEGA_SVC in $1; do
case $MEGA_SVC in
"ChatQnA"|"CodeGen"|"CodeTrans"|"DocSum"|"SearchQnA")
cd $MEGA_SVC/docker
IMAGE_NAME="$(getImagenameFromMega $MEGA_SVC)"
docker_build ${IMAGE_NAME}
cd ui
docker_build ${IMAGE_NAME}-ui docker/Dockerfile
;;
"AudioQnA"|"SearchQnA"|"Translation"|"VisualQnA")
echo "Not supported yet"
exit 1
;;
*)
echo "Unknown function: $MEGA_SVC"
;;
esac
done
36 changes: 26 additions & 10 deletions ChatQnA/tests/test_manifest_on_xeon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ set -xe
USER_ID=$(whoami)
LOG_PATH=/home/$(whoami)/logs
MOUNT_DIR=/home/$USER_ID/charts-mnt
# IMAGE_REPO is $OPEA_IMAGE_REPO, or else ""
IMAGE_REPO=${OPEA_IMAGE_REPO:-amr-registry.caas.intel.com/aiops}
IMAGE_REPO=${IMAGE_REPO:-}
IMAGE_TAG=${IMAGE_TAG:-latest}

function init_chatqna() {
# executed under path manifest/chatqna/xeon
# replace the mount dir "path: /mnt" with "path: $CHART_MOUNT"
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt/models#path: $MOUNT_DIR#g" {} \;
# replace megaservice image tag
find . -name '*.yaml' -type f -exec sed -i "s#image: opea/chatqna:latest#image: opea/chatqna:${IMAGE_TAG}#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#\${HUGGINGFACEHUB_API_TOKEN}#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \;
}
Expand All @@ -32,15 +34,29 @@ function install_chatqna {
}

function validate_chatqna() {
max_retry=20
# make sure microservice retriever is ready
until curl http://retriever-svc.$NAMESPACE:7000/v1/retrieval -X POST \
-d '{"text":"What is the revenue of Nike in 2023?","embedding":"'"${your_embedding}"'"}' \
-H 'Content-Type: application/json'; do sleep 10; done

# try to curl retriever-svc for max_retry times
for ((i=1; i<=max_retry; i++))
do
curl http://retriever-svc.$NAMESPACE:7000/v1/retrieval -X POST \
-d '{"text":"What is the revenue of Nike in 2023?","embedding":"'"${your_embedding}"'"}' \
-H 'Content-Type: application/json' && break
sleep 10
done
# make sure microservice tgi-svc is ready
until curl http://tgi-svc.$NAMESPACE:9009/generate -X POST \
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}' \
-H 'Content-Type: application/json'; do sleep 10; done
for ((i=1; i<=max_retry; i++))
do
curl http://tgi-svc.$NAMESPACE:9009/generate -X POST \
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}' \
-H 'Content-Type: application/json' && break
sleep 10
done
# if i is bigger than max_retry, then exit with error
if [ $i -gt $max_retry ]; then
echo "Microservice failed, exit with error."
exit 1
fi

# check megaservice works
# generate a random logfile name to avoid conflict among multiple runners
Expand Down
8 changes: 5 additions & 3 deletions CodeGen/tests/test_manifest_on_xeon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ set -xe
USER_ID=$(whoami)
LOG_PATH=/home/$(whoami)/logs
MOUNT_DIR=/home/$USER_ID/charts-mnt
# IMAGE_REPO is $OPEA_IMAGE_REPO, or else ""
IMAGE_REPO=${OPEA_IMAGE_REPO:-amr-registry.caas.intel.com/aiops}
IMAGE_REPO=${IMAGE_REPO:-}
IMAGE_TAG=${IMAGE_TAG:-latest}

function init_codegen() {
# executed under path manifest/codegen/xeon
# replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT"
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt#path: $MOUNT_DIR#g" {} \;
# replace megaservice image tag
find . -name '*.yaml' -type f -exec sed -i "s#image: opea/codegen:latest#image: opea/codegen:${IMAGE_TAG}#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 /home/$USER_ID/.cache/huggingface/token)#g" {} \;
}
Expand Down

0 comments on commit c5f3095

Please sign in to comment.