Skip to content

Commit

Permalink
Check image and service names and Dockerfile in build.yaml (opea-proj…
Browse files Browse the repository at this point in the history
…ect#1209)

Signed-off-by: ZePan110 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ZePan110 and pre-commit-ci[bot] authored Nov 28, 2024
1 parent 907b30b commit e8cffc6
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 42 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/pr-dockerfile-path-and-build-yaml-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

name: Compose file and dockerfile path checking

on:
pull_request:
branches: [main]
types: [opened, reopened, ready_for_review, synchronize]

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

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

- name: Clone Repo GenAIComps
run: |
cd ..
git clone https://github.com/opea-project/GenAIComps.git
- name: Check for Missing Dockerfile Paths in GenAIComps
run: |
cd ${{github.workspace}}
miss="FALSE"
while IFS=: read -r file line content; do
dockerfile_path=$(echo "$content" | awk -F '-f ' '{print $2}' | awk '{print $1}')
if [[ ! -f "../GenAIComps/${dockerfile_path}" ]]; then
miss="TRUE"
echo "Missing Dockerfile: GenAIComps/${dockerfile_path} (Referenced in GenAIExamples/${file}:${line})"
fi
done < <(grep -Ern 'docker build .* -f comps/.+/Dockerfile' --include='*.md' .)
if [[ "$miss" == "TRUE" ]]; then
exit 1
fi
shell: bash

check-Dockerfile-in-build-yamls:
runs-on: ubuntu-latest
steps:
- name: Clean Up Working Directory
run: sudo rm -rf ${{github.workspace}}/*

- name: Checkout Repo GenAIExamples
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check Dockerfile path included in image build yaml
if: always()
run: |
set -e
shopt -s globstar
no_add="FALSE"
cd ${{github.workspace}}
Dockerfiles=$(realpath $(find ./ -name '*Dockerfile*'))
if [ -n "$Dockerfiles" ]; then
for dockerfile in $Dockerfiles; do
service=$(echo "$dockerfile" | awk -F '/GenAIExamples/' '{print $2}' | awk -F '/' '{print $2}')
cd ${{github.workspace}}/$service/docker_image_build
all_paths=$(realpath $(awk ' /context:/ { context = $2 } /dockerfile:/ { dockerfile = $2; combined = context "/" dockerfile; gsub(/\/+/, "/", combined); if (index(context, ".") > 0) {print combined}}' build.yaml) 2> /dev/null || true )
if ! echo "$all_paths" | grep -q "$dockerfile"; then
echo "AR: Update $dockerfile to GenAIExamples/$service/docker_image_build/build.yaml. The yaml is used for release images build."
no_add="TRUE"
fi
done
fi
if [[ "$no_add" == "TRUE" ]]; then
exit 1
fi
check-image-and-service-names-in-build-yaml:
runs-on: ubuntu-latest
steps:
- name: Clean Up Working Directory
run: sudo rm -rf ${{github.workspace}}/*

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

- name: Check name agreement in build.yaml
run: |
pip install ruamel.yaml
cd ${{github.workspace}}
consistency="TRUE"
build_yamls=$(find . -name 'build.yaml')
for build_yaml in $build_yamls; do
message=$(python3 .github/workflows/scripts/check-name-agreement.py "$build_yaml")
if [[ "$message" != *"consistent"* ]]; then
consistency="FALSE"
echo "Inconsistent service name and image name found in file $build_yaml."
echo "$message"
fi
done
if [[ "$consistency" == "FALSE" ]]; then
echo "Please ensure that the service and image names are consistent in build.yaml, otherwise we cannot guarantee that your image will be published correctly."
exit 1
fi
shell: bash
Original file line number Diff line number Diff line change
@@ -1,47 +1,14 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

name: Check Paths and Hyperlinks
name: Check hyperlinks and relative path validity

on:
pull_request:
branches: [main]
types: [opened, reopened, ready_for_review, synchronize]

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

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

- name: Clone Repo GenAIComps
run: |
cd ..
git clone https://github.com/opea-project/GenAIComps.git
- name: Check for Missing Dockerfile Paths in GenAIComps
run: |
cd ${{github.workspace}}
miss="FALSE"
while IFS=: read -r file line content; do
dockerfile_path=$(echo "$content" | awk -F '-f ' '{print $2}' | awk '{print $1}')
if [[ ! -f "../GenAIComps/${dockerfile_path}" ]]; then
miss="TRUE"
echo "Missing Dockerfile: GenAIComps/${dockerfile_path} (Referenced in GenAIExamples/${file}:${line})"
fi
done < <(grep -Ern 'docker build .* -f comps/.+/Dockerfile' --include='*.md' .)
if [[ "$miss" == "TRUE" ]]; then
exit 1
fi
shell: bash

check-the-validity-of-hyperlinks-in-README:
runs-on: ubuntu-latest
steps:
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/scripts/check-name-agreement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import argparse

from ruamel.yaml import YAML


def parse_yaml_file(file_path):
yaml = YAML()
with open(file_path, "r") as file:
data = yaml.load(file)
return data


def check_service_image_consistency(data):
inconsistencies = []
for service_name, service_details in data.get("services", {}).items():
image_name = service_details.get("image", "")
# Extract the image name part after the last '/'
image_name_part = image_name.split("/")[-1].split(":")[0]
# Check if the service name is a substring of the image name part
if service_name not in image_name_part:
# Get the line number of the service name
line_number = service_details.lc.line + 1
inconsistencies.append((service_name, image_name, line_number))
return inconsistencies


def main():
parser = argparse.ArgumentParser(description="Check service name and image name consistency in a YAML file.")
parser.add_argument("file_path", type=str, help="The path to the YAML file.")
args = parser.parse_args()

data = parse_yaml_file(args.file_path)

inconsistencies = check_service_image_consistency(data)
if inconsistencies:
for service_name, image_name, line_number in inconsistencies:
print(f"Service name: {service_name}, Image name: {image_name}, Line number: {line_number}")
else:
print("All consistent")


if __name__ == "__main__":
main()
12 changes: 12 additions & 0 deletions AudioQnA/docker_image_build/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ services:
context: ../
dockerfile: ./Dockerfile
image: ${REGISTRY:-opea}/audioqna:${TAG:-latest}
audioqna-ui:
build:
context: ../ui
dockerfile: ./docker/Dockerfile
extends: audioqna
image: ${REGISTRY:-opea}/audioqna-ui:${TAG:-latest}
audioqna-multilang:
build:
context: ../
dockerfile: ./Dockerfile.multilang
extends: audioqna
image: ${REGISTRY:-opea}/audioqna-multilang:${TAG:-latest}
whisper-gaudi:
build:
context: GenAIComps
Expand Down
9 changes: 9 additions & 0 deletions GraphRAG/docker_image_build/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ services:
context: ../ui
dockerfile: ./docker/Dockerfile
image: ${REGISTRY:-opea}/graphrag-ui:${TAG:-latest}
graphrag-react-ui:
build:
args:
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
no_proxy: ${no_proxy}
context: ../ui
dockerfile: ./docker/Dockerfile.react
image: ${REGISTRY:-opea}/graphrag-react-ui:${TAG:-latest}
5 changes: 5 additions & 0 deletions Text2Image/docker_image_build/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ services:
context: GenAIComps
dockerfile: comps/text2image/Dockerfile
image: ${REGISTRY:-opea}/text2image:${TAG:-latest}
text2image-ui:
build:
context: ../ui
dockerfile: ./docker/Dockerfile
image: ${REGISTRY:-opea}/text2image-ui:${TAG:-latest}
16 changes: 8 additions & 8 deletions Text2Image/ui/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
},
"devDependencies": {
"@fortawesome/free-solid-svg-icons": "6.2.0",
"@playwright/test": "^1.48.0",
"@playwright/test": "^1.33.0",
"@sveltejs/adapter-auto": "1.0.0-next.75",
"@sveltejs/adapter-static": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/kit": "^1.30.4",
"@tailwindcss/typography": "0.5.7",
"@types/debug": "4.1.7",
"@types/node": "^20.12.13",
Expand All @@ -29,20 +28,21 @@
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-neverthrow": "1.1.4",
"eslint-plugin-svelte3": "^4.0.0",
"postcss": "^8.4.31",
"postcss-load-config": "^4.0.1",
"postcss-preset-env": "^8.3.2",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.7.0",
"prettier-plugin-tailwindcss": "^0.3.0",
"svelte": "^4.0.0",
"svelte-check": "^3.0.0",
"svelte": "^3.59.1",
"svelte-check": "^2.7.1",
"svelte-fa": "3.0.3",
"svelte-preprocess": "^6.0.2",
"svelte-preprocess": "^4.10.7",
"tailwindcss": "^3.1.5",
"tslib": "^2.3.1",
"typescript": "^5.0.0",
"vite": "^5.0.0"
"typescript": "^4.7.4",
"vite": "^4.5.2"
},
"type": "module",
"dependencies": {
Expand Down

0 comments on commit e8cffc6

Please sign in to comment.