From 83cdf575e2e1f71ac6e350e6fd37a91b44ab10c7 Mon Sep 17 00:00:00 2001 From: Yingchun Guo Date: Tue, 11 Jun 2024 02:10:10 -0700 Subject: [PATCH] Add docker build job in manifest e2e workflow Signed-off-by: Yingchun Guo --- .github/workflows/manifest-e2e.yaml | 38 +++++++++++++-- .github/workflows/scripts/build_push.sh | 62 +++++++++++++++++++++++++ ChatQnA/tests/test_manifest_on_xeon.sh | 36 ++++++++++---- CodeGen/tests/test_manifest_on_xeon.sh | 8 ++-- 4 files changed, 128 insertions(+), 16 deletions(-) create mode 100755 .github/workflows/scripts/build_push.sh diff --git a/.github/workflows/manifest-e2e.yaml b/.github/workflows/manifest-e2e.yaml index 7e152c0f8f..28182ac3b3 100644 --- a/.github/workflows/manifest-e2e.yaml +++ b/.github/workflows/manifest-e2e.yaml @@ -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 }} @@ -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}}/* @@ -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 @@ -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 diff --git a/.github/workflows/scripts/build_push.sh b/.github/workflows/scripts/build_push.sh new file mode 100755 index 0000000000..d9c3a68a4b --- /dev/null +++ b/.github/workflows/scripts/build_push.sh @@ -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 + 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 diff --git a/ChatQnA/tests/test_manifest_on_xeon.sh b/ChatQnA/tests/test_manifest_on_xeon.sh index 489dedeb10..058dabcb7a 100755 --- a/ChatQnA/tests/test_manifest_on_xeon.sh +++ b/ChatQnA/tests/test_manifest_on_xeon.sh @@ -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" {} \; } @@ -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 diff --git a/CodeGen/tests/test_manifest_on_xeon.sh b/CodeGen/tests/test_manifest_on_xeon.sh index ffc71d5b7c..09a507c65f 100755 --- a/CodeGen/tests/test_manifest_on_xeon.sh +++ b/CodeGen/tests/test_manifest_on_xeon.sh @@ -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" {} \; }