Skip to content

Commit

Permalink
Add docker build job in manifest e2e workflow
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 11, 2024
1 parent 4d36def commit 83cdf57
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 16 deletions.
38 changes: 35 additions & 3 deletions .github/workflows/manifest-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,36 @@ 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) }}
runs-on: docker-build
outputs:
image_tag: ${{ steps.build-megaservice-image.outputs.image_tag }}
image_repo: ${{ steps.build-megaservice-image.outputs.image_repo }}
steps:
- name: Checkout out Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set variables
run: |
echo "IMAGE_REPO=$OPEA_IMAGE_REPO" >> $GITHUB_ENV
echo "IMAGE_TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
- name: Building MegaService Docker Image
id: build-megaservice-image
run: |
.github/workflows/scripts/build_push.sh ${{ matrix.example }}
echo "image_repo=${{ env.IMAGE_REPO }}" >> $GITHUB_OUTPUT
echo "image_tag=${{ env.IMAGE_TAG }}" >> $GITHUB_OUTPUT
manifest-test:
needs: [job1, mega-image-build]
if: always() && ${{ needs.job1.outputs.run_matrix.include.length }} > 0
strategy:
matrix: ${{ fromJSON(needs.job1.outputs.run_matrix) }}
runs-on: ${{ matrix.hardware }}
Expand All @@ -68,6 +95,7 @@ jobs:
- name: E2e test manifest
run: |
echo "Matrix - manifest: ${{ matrix.example }}"
echo ${{needs.mega-image-build.outputs}}
- name: Clean Up Working Directory
run: sudo rm -rf ${{github.workspace}}/*
Expand All @@ -79,12 +107,16 @@ jobs:

- name: Set variables
run: |
echo ${{needs.mega-image-build.outputs.image_repo}}
echo ${{needs.mega-image-build.outputs.image_tag}}
echo "IMAGE_REPO=${{needs.mega-image-build.outputs.image_repo}}" >> $GITHUB_ENV
echo "IMAGE_TAG=${{needs.mega-image-build.outputs.image_tag}}" >> $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 +132,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
62 changes: 62 additions & 0 deletions .github/workflows/scripts/build_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

set -xe

echo "Using IMAGE_REPO=$IMAGE_REPO, IMAGE_TAG=$IMAGE_TAG"

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

function docker_build() {
# 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
}

case "$1" in
AudioQnA)
;;
ChatQnA)
cd ChatQnA/docker
docker_build chatqna
cd ../../ChatQnA/ui
docker_build chatqna-ui docker/Dockerfile
;;
CodeGen)
cd CodeGen/docker
docker_build codegen
cd ../../CodeGen/ui
docker_build codegen-ui docker/Dockerfile
;;
CodeTrans)
cd CodeGen/docker
docker_build codetrans
;;
DocSum)
cd DocSum/docker
docker_build docsum
;;
SearchQnA)
;;
Translation)
;;
VisualQnA)
;;
*)
echo "Unknown function: $1"
;;
esac
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 83cdf57

Please sign in to comment.