Skip to content

Commit

Permalink
CI: Add check for conflict image build definition (#944)
Browse files Browse the repository at this point in the history
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
  • Loading branch information
lianhao authored Nov 27, 2024
1 parent c5b8cdd commit 0e94eec
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# this file should be run in the root of the repo
services:
llm-tgi:
intent-detection-tgi:
build:
dockerfile: comps/intent_detection/langchain/Dockerfile
image: ${REGISTRY:-opea}/llm-tgi:${TAG:-latest}
image: ${REGISTRY:-opea}/intent-detection-tgi:${TAG:-latest}
40 changes: 40 additions & 0 deletions .github/workflows/pr-check-duplicated-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

name: Check Duplicated Image

on:
pull_request:
branches: [main]
types: [opened, reopened, ready_for_review, synchronize]
paths:
- ".github/workflows/docker/compose/*.yaml"
- ".github/workflows/pr-check-duplicated-image.yml"
- ".github/workflows/scripts/check_duplicated_image.py"
workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
check-duplicated-image:
runs-on: ubuntu-latest
steps:
- name: Clean Up Working Directory
run: sudo rm -rf ${{github.workspace}}/*

- name: Checkout Repo
uses: actions/checkout@v4

- name: Check all the docker image build files
run: |
pip install PyYAML
cd ${{github.workspace}}
build_files=""
for f in `find .github/workflows/docker/compose/ -name '*.yaml'`; do
build_files="$build_files $f"
done
python3 .github/workflows/scripts/check_duplicated_image.py $build_files
shell: bash
63 changes: 63 additions & 0 deletions .github/workflows/scripts/check_duplicated_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import argparse
import os.path
import subprocess
import sys

import yaml

images = {}


def check_docker_compose_build_definition(file_path):
with open(file_path, "r") as f:
data = yaml.load(f, Loader=yaml.FullLoader)
for service in data["services"]:
if "build" in data["services"][service] and "image" in data["services"][service]:
bash_command = "echo " + data["services"][service]["image"]
image = (
subprocess.run(["bash", "-c", bash_command], check=True, capture_output=True)
.stdout.decode("utf-8")
.strip()
)
build = data["services"][service]["build"]
context = build.get("context", "")
dockerfile = os.path.normpath(
os.path.join(os.path.dirname(file_path), context, build.get("dockerfile", ""))
)
if not os.path.exists(dockerfile):
# dockerfile not exists in the current repo context, assume it's in 3rd party context
dockerfile = os.path.normpath(os.path.join(context, build.get("dockerfile", "")))
item = {"file_path": file_path, "service": service, "dockerfile": dockerfile}
if image in images and dockerfile != images[image]["dockerfile"]:
print("ERROR: !!! Found Conflicts !!!")
print(f"Image: {image}, Dockerfile: {dockerfile}, defined in Service: {service}, File: {file_path}")
print(
f"Image: {image}, Dockerfile: {images[image]['dockerfile']}, defined in Service: {images[image]['service']}, File: {images[image]['file_path']}"
)
sys.exit(1)
else:
# print(f"Add Image: {image} Dockerfile: {dockerfile}")
images[image] = item


def parse_arg():
parser = argparse.ArgumentParser(
description="Check for conflicts in image build definition in docker-compose.yml files"
)
parser.add_argument("files", nargs="+", help="list of files to be checked")
return parser.parse_args()


def main():
args = parse_arg()
for file_path in args.files:
check_docker_compose_build_definition(file_path)
print("SUCCESS: No Conlicts Found.")
return 0


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions comps/intent_detection/langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export TGI_LLM_ENDPOINT="http://${your_ip}:8008"

```bash
cd ../../../
docker build --no-cache -t opea/llm-tgi:latest -f comps/intent_detection/langchain/Dockerfile .
docker build --no-cache -t opea/intent-detection-tgi:latest -f comps/intent_detection/langchain/Dockerfile .
```

### 2.4 Run Docker with CLI (Option A)

```bash
docker run -it --name="intent-tgi-server" --net=host --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TGI_LLM_ENDPOINT=$TGI_LLM_ENDPOINT -e HUGGINGFACEHUB_API_TOKEN=$HUGGINGFACEHUB_API_TOKEN opea/llm-tgi:latest
docker run -it --name="intent-tgi-server" --net=host --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TGI_LLM_ENDPOINT=$TGI_LLM_ENDPOINT -e HUGGINGFACEHUB_API_TOKEN=$HUGGINGFACEHUB_API_TOKEN opea/intent-detection-tgi:latest
```

### 2.5 Run with Docker Compose (Option B)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
shm_size: 1g
command: --model-id ${LLM_MODEL_ID}
llm:
image: opea/llm-tgi:latest
image: opea/intent-detection-tgi:latest
container_name: intent-tgi-server
ports:
- "9000:9000"
Expand Down
4 changes: 2 additions & 2 deletions tests/intent_detection/test_intent_detection_langchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ip_address=$(hostname -I | awk '{print $1}')

function build_docker_images() {
cd $WORKPATH
docker build --no-cache -t opea/intent-detection:comps -f comps/intent_detection/langchain/Dockerfile .
docker build --no-cache -t opea/intent-detection-tgi:comps -f comps/intent_detection/langchain/Dockerfile .
}

function start_service() {
Expand All @@ -23,7 +23,7 @@ function start_service() {
export TGI_LLM_ENDPOINT="http://${ip_address}:${tgi_endpoint}"
intent_port=5043
unset http_proxy
docker run -d --name="test-comps-intent-server" -p ${intent_port}:9000 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TGI_LLM_ENDPOINT=$TGI_LLM_ENDPOINT -e HUGGINGFACEHUB_API_TOKEN=$HUGGINGFACEHUB_API_TOKEN opea/intent-detection:comps
docker run -d --name="test-comps-intent-server" -p ${intent_port}:9000 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TGI_LLM_ENDPOINT=$TGI_LLM_ENDPOINT -e HUGGINGFACEHUB_API_TOKEN=$HUGGINGFACEHUB_API_TOKEN opea/intent-detection-tgi:comps

# check whether tgi is fully ready
n=0
Expand Down

0 comments on commit 0e94eec

Please sign in to comment.