Skip to content

Commit c5f3095

Browse files
authored
Add docker build job in manifest e2e workflow (#274)
Signed-off-by: Yingchun Guo <[email protected]>
1 parent 2a48601 commit c5f3095

File tree

5 files changed

+151
-17
lines changed

5 files changed

+151
-17
lines changed

.github/workflows/image-build.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Image Build
5+
permissions: read-all
6+
on:
7+
workflow_call:
8+
inputs:
9+
image-repo:
10+
required: false
11+
type: string
12+
image-tag:
13+
required: true
14+
type: string
15+
mega-service:
16+
required: true
17+
type: string
18+
runner_lable:
19+
required: false
20+
type: string
21+
default: 'docker-build'
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-image-build
25+
26+
jobs:
27+
mega-image-build:
28+
runs-on: ${{ inputs.runner_lable }}
29+
steps:
30+
- name: Checkout out Repo
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Building MegaService Docker Image
36+
id: build-megaservice-image
37+
env:
38+
IMAGE_REPO: ${{ inputs.image-repo }}
39+
IMAGE_TAG: ${{ inputs.image-tag }}
40+
mega-service: ${{ inputs.mega-service }}
41+
run: |
42+
.github/workflows/scripts/build_push.sh ${{ env.mega-service}}

.github/workflows/manifest-e2e.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,17 @@ jobs:
5757
run_matrix=$run_matrix"]}"
5858
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT
5959
60-
manifest-test:
60+
mega-image-build:
6161
needs: job1
62-
if: always() && ${{ needs.job1.outputs.run_matrix.include.length }} > 0
62+
strategy:
63+
matrix: ${{ fromJSON(needs.job1.outputs.run_matrix) }}
64+
uses: ./.github/workflows/image-build.yaml
65+
with:
66+
image-tag: ${{ github.event.pull_request.head.sha }}
67+
mega-service: "${{ matrix.example }}"
68+
69+
manifest-test:
70+
needs: [job1, mega-image-build]
6371
strategy:
6472
matrix: ${{ fromJSON(needs.job1.outputs.run_matrix) }}
6573
runs-on: ${{ matrix.hardware }}
@@ -79,12 +87,14 @@ jobs:
7987

8088
- name: Set variables
8189
run: |
90+
echo "IMAGE_REPO=${OPEA_IMAGE_REPO}/" >> $GITHUB_ENV
91+
echo "IMAGE_TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
8292
lower_example=$(echo "${{ matrix.example }}" | tr '[:upper:]' '[:lower:]')
8393
echo "NAMESPACE=$lower_example-$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
8494
echo "ROLLOUT_TIMEOUT_SECONDS=1800s" >> $GITHUB_ENV
8595
echo "KUBECTL_TIMEOUT_SECONDS=60s" >> $GITHUB_ENV
8696
echo "should_cleanup=false" >> $GITHUB_ENV
87-
echo "skip_validate=false" >> $GITHUB_ENV
97+
echo "skip_validate=true" >> $GITHUB_ENV
8898
echo "NAMESPACE=$NAMESPACE"
8999
90100
- name: Initialize manifest testing
@@ -100,9 +110,9 @@ jobs:
100110
echo "Testing ${{ matrix.example }}, waiting for pod ready..."
101111
if kubectl rollout status deployment --namespace "$NAMESPACE" --timeout "$ROLLOUT_TIMEOUT_SECONDS"; then
102112
echo "Testing manifests ${{ matrix.example }}, waiting for pod ready done!"
113+
echo "skip_validate=false" >> $GITHUB_ENV
103114
else
104115
echo "Timeout waiting for pods in namespace $NAMESPACE to be ready!"
105-
echo "skip_validate=true" >> $GITHUB_ENV
106116
exit 1
107117
fi
108118
sleep 60
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# Copyright (C) 2024 Intel Corporation
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set -xe
6+
7+
IMAGE_REPO=${IMAGE_REPO:-$OPEA_IMAGE_REPO}
8+
IMAGE_TAG=${IMAGE_TAG:-latest}
9+
10+
function getImagenameFromMega() {
11+
echo $(echo "$1" | tr '[:upper:]' '[:lower:]')
12+
}
13+
14+
function checkExist() {
15+
IMAGE_NAME=$1
16+
if [ $(curl -X GET http://localhost:5000/v2/opea/${IMAGE_NAME}/tags/list | grep -c ${IMAGE_TAG}) -ne 0 ]; then
17+
echo "true"
18+
else
19+
echo "false"
20+
fi
21+
}
22+
23+
function docker_build() {
24+
# check if if IMAGE_TAG is not "latest" and the image exists in the registry
25+
if [ $IMAGE_TAG != "latest" && $(checkExist $1) == "true" ]; then
26+
echo "Image ${IMAGE_REPO}opea/$1:$IMAGE_TAG already exists in the registry"
27+
return
28+
fi
29+
# docker_build <service_name> <dockerfile>
30+
if [ -z "$2" ]; then
31+
DOCKERFILE_PATH=Dockerfile
32+
else
33+
DOCKERFILE_PATH=$2
34+
fi
35+
echo "Building ${IMAGE_REPO}opea/$1:$IMAGE_TAG using Dockerfile $DOCKERFILE_PATH"
36+
# if https_proxy and http_proxy are set, pass them to docker build
37+
if [ -z "$https_proxy" ]; then
38+
docker build --no-cache -t ${IMAGE_REPO}opea/$1:$IMAGE_TAG -f $DOCKERFILE_PATH .
39+
else
40+
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 .
41+
fi
42+
docker push ${IMAGE_REPO}opea/$1:$IMAGE_TAG
43+
docker rmi ${IMAGE_REPO}opea/$1:$IMAGE_TAG
44+
}
45+
46+
# $1 is like "apple orange pear"
47+
for MEGA_SVC in $1; do
48+
case $MEGA_SVC in
49+
"ChatQnA"|"CodeGen"|"CodeTrans"|"DocSum"|"SearchQnA")
50+
cd $MEGA_SVC/docker
51+
IMAGE_NAME="$(getImagenameFromMega $MEGA_SVC)"
52+
docker_build ${IMAGE_NAME}
53+
cd ui
54+
docker_build ${IMAGE_NAME}-ui docker/Dockerfile
55+
;;
56+
"AudioQnA"|"SearchQnA"|"Translation"|"VisualQnA")
57+
echo "Not supported yet"
58+
exit 1
59+
;;
60+
*)
61+
echo "Unknown function: $MEGA_SVC"
62+
;;
63+
esac
64+
done

ChatQnA/tests/test_manifest_on_xeon.sh

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ set -xe
66
USER_ID=$(whoami)
77
LOG_PATH=/home/$(whoami)/logs
88
MOUNT_DIR=/home/$USER_ID/charts-mnt
9-
# IMAGE_REPO is $OPEA_IMAGE_REPO, or else ""
10-
IMAGE_REPO=${OPEA_IMAGE_REPO:-amr-registry.caas.intel.com/aiops}
9+
IMAGE_REPO=${IMAGE_REPO:-}
10+
IMAGE_TAG=${IMAGE_TAG:-latest}
1111

1212
function init_chatqna() {
1313
# executed under path manifest/chatqna/xeon
1414
# replace the mount dir "path: /mnt" with "path: $CHART_MOUNT"
1515
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt/models#path: $MOUNT_DIR#g" {} \;
16+
# replace megaservice image tag
17+
find . -name '*.yaml' -type f -exec sed -i "s#image: opea/chatqna:latest#image: opea/chatqna:${IMAGE_TAG}#g" {} \;
1618
# replace the repository "image: opea/*" with "image: $IMAGE_REPO/opea/"
17-
find . -name '*.yaml' -type f -exec sed -i "s#image: opea/*#image: $IMAGE_REPO/opea/#g" {} \;
19+
find . -name '*.yaml' -type f -exec sed -i "s#image: opea/*#image: ${IMAGE_REPO}opea/#g" {} \;
1820
# set huggingface token
1921
find . -name '*.yaml' -type f -exec sed -i "s#\${HUGGINGFACEHUB_API_TOKEN}#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \;
2022
}
@@ -32,15 +34,29 @@ function install_chatqna {
3234
}
3335

3436
function validate_chatqna() {
37+
max_retry=20
3538
# make sure microservice retriever is ready
36-
until curl http://retriever-svc.$NAMESPACE:7000/v1/retrieval -X POST \
37-
-d '{"text":"What is the revenue of Nike in 2023?","embedding":"'"${your_embedding}"'"}' \
38-
-H 'Content-Type: application/json'; do sleep 10; done
39-
39+
# try to curl retriever-svc for max_retry times
40+
for ((i=1; i<=max_retry; i++))
41+
do
42+
curl http://retriever-svc.$NAMESPACE:7000/v1/retrieval -X POST \
43+
-d '{"text":"What is the revenue of Nike in 2023?","embedding":"'"${your_embedding}"'"}' \
44+
-H 'Content-Type: application/json' && break
45+
sleep 10
46+
done
4047
# make sure microservice tgi-svc is ready
41-
until curl http://tgi-svc.$NAMESPACE:9009/generate -X POST \
42-
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}' \
43-
-H 'Content-Type: application/json'; do sleep 10; done
48+
for ((i=1; i<=max_retry; i++))
49+
do
50+
curl http://tgi-svc.$NAMESPACE:9009/generate -X POST \
51+
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}' \
52+
-H 'Content-Type: application/json' && break
53+
sleep 10
54+
done
55+
# if i is bigger than max_retry, then exit with error
56+
if [ $i -gt $max_retry ]; then
57+
echo "Microservice failed, exit with error."
58+
exit 1
59+
fi
4460

4561
# check megaservice works
4662
# generate a random logfile name to avoid conflict among multiple runners

CodeGen/tests/test_manifest_on_xeon.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ set -xe
66
USER_ID=$(whoami)
77
LOG_PATH=/home/$(whoami)/logs
88
MOUNT_DIR=/home/$USER_ID/charts-mnt
9-
# IMAGE_REPO is $OPEA_IMAGE_REPO, or else ""
10-
IMAGE_REPO=${OPEA_IMAGE_REPO:-amr-registry.caas.intel.com/aiops}
9+
IMAGE_REPO=${IMAGE_REPO:-}
10+
IMAGE_TAG=${IMAGE_TAG:-latest}
1111

1212
function init_codegen() {
1313
# executed under path manifest/codegen/xeon
1414
# replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT"
1515
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt#path: $MOUNT_DIR#g" {} \;
16+
# replace megaservice image tag
17+
find . -name '*.yaml' -type f -exec sed -i "s#image: opea/codegen:latest#image: opea/codegen:${IMAGE_TAG}#g" {} \;
1618
# replace the repository "image: opea/*" with "image: $IMAGE_REPO/opea/"
17-
find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: \"$IMAGE_REPO/opea/#g" {} \;
19+
find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: \"${IMAGE_REPO}opea/#g" {} \;
1820
# set huggingface token
1921
find . -name '*.yaml' -type f -exec sed -i "s#insert-your-huggingface-token-here#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \;
2022
}

0 commit comments

Comments
 (0)