Skip to content

Commit 6b6a08d

Browse files
authored
Add minimal containers and ports clean up before test (#1291)
Signed-off-by: chensuyue <suyue.chen@intel.com>
1 parent 0b23cba commit 6b6a08d

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

.github/workflows/_run-docker-compose.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ jobs:
111111
ref: ${{ needs.get-test-case.outputs.CHECKOUT_REF }}
112112
fetch-depth: 0
113113

114+
- name: Clean up container before test
115+
shell: bash
116+
run: |
117+
docker ps
118+
cd ${{ github.workspace }}/${{ inputs.example }}
119+
export test_case=${{ matrix.test_case }}
120+
export hardware=${{ inputs.hardware }}
121+
bash ${{ github.workspace }}/.github/workflows/scripts/docker_compose_clean_up.sh "containers"
122+
bash ${{ github.workspace }}/.github/workflows/scripts/docker_compose_clean_up.sh "ports"
123+
docker ps
124+
114125
- name: Run test
115126
shell: bash
116127
env:
@@ -131,21 +142,14 @@ jobs:
131142
if [[ "$IMAGE_REPO" == "" ]]; then export IMAGE_REPO="${OPEA_IMAGE_REPO}opea"; fi
132143
if [ -f ${test_case} ]; then timeout 30m bash ${test_case}; else echo "Test script {${test_case}} not found, skip test!"; fi
133144
134-
- name: Clean up container
145+
- name: Clean up container after test
135146
shell: bash
136147
if: cancelled() || failure()
137148
run: |
138-
cd ${{ github.workspace }}/${{ inputs.example }}/docker_compose
139-
test_case=${{ matrix.test_case }}
140-
flag=${test_case%_on_*}
141-
flag=${flag#test_}
142-
yaml_file=$(find . -type f -wholename "*${{ inputs.hardware }}/${flag}.yaml")
143-
echo $yaml_file
144-
container_list=$(cat $yaml_file | grep container_name | cut -d':' -f2)
145-
for container_name in $container_list; do
146-
cid=$(docker ps -aq --filter "name=$container_name")
147-
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
148-
done
149+
cd ${{ github.workspace }}/${{ inputs.example }}
150+
export test_case=${{ matrix.test_case }}
151+
export hardware=${{ inputs.hardware }}
152+
bash ${{ github.workspace }}/.github/workflows/scripts/docker_compose_clean_up.sh "containers"
149153
docker system prune -f
150154
docker rmi $(docker images --filter reference="*:5000/*/*" -q) || true
151155

.github/workflows/manual-docker-clean.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
clean_list:
1414
default: ""
1515
description: "docker command to clean"
16-
required: true
16+
required: false
1717
type: string
1818

1919
jobs:
@@ -24,6 +24,8 @@ jobs:
2424
run: |
2525
docker ps
2626
if [ "${{ inputs.clean_list }}" ]; then
27+
echo "----------stop and remove containers----------"
2728
docker stop ${{ inputs.clean_list }} && docker rm ${{ inputs.clean_list }}
29+
echo "----------container removed----------"
2830
docker ps
2931
fi

.github/workflows/push-image-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- "**.py"
1111
- "**Dockerfile*"
1212
- "**docker_image_build/build.yaml"
13+
- "**/ui/**"
1314

1415
concurrency:
1516
group: ${{ github.workflow }}-${{ github.ref }}-on-push
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Copyright (C) 2024 Intel Corporation
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# The test machine used by several opea projects, so the test scripts can't use `docker compose down` to clean up
6+
# the all the containers, ports and networks directly.
7+
# So we need to use the following script to minimize the impact of the clean up.
8+
9+
test_case=${test_case:-"test_compose_on_gaudi.sh"}
10+
hardware=${hardware:-"gaudi"}
11+
flag=${test_case%_on_*}
12+
flag=${flag#test_}
13+
yaml_file=$(find . -type f -wholename "*${hardware}/${flag}.yaml")
14+
echo $yaml_file
15+
16+
case "$1" in
17+
containers)
18+
echo "Stop and remove all containers used by the services in $yaml_file ..."
19+
containers=$(cat $yaml_file | grep container_name | cut -d':' -f2)
20+
for container_name in $containers; do
21+
cid=$(docker ps -aq --filter "name=$container_name")
22+
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
23+
done
24+
;;
25+
ports)
26+
echo "Release all ports used by the services in $yaml_file ..."
27+
pip install jq yq
28+
ports=$(yq '.services[].ports[] | split(":")[0]' $yaml_file | grep -o '[0-9a-zA-Z_-]\+')
29+
echo "$ports"
30+
for port in $ports; do
31+
if [[ $port =~ [a-zA-Z_-] ]]; then
32+
port=$(grep -E "export $port=" tests/$test_case | cut -d'=' -f2)
33+
fi
34+
echo $port
35+
cid=$(docker ps --filter "publish=${port}" --format "{{.ID}}")
36+
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
37+
done
38+
;;
39+
*)
40+
echo "Unknown function: $1"
41+
;;
42+
esac

CodeGen/tests/test_compose_on_rocm.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
32
# Copyright (C) 2024 Intel Corporation
43
# SPDX-License-Identifier: Apache-2.0
54

0 commit comments

Comments
 (0)