forked from opea-project/GenAIExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check image and service names and Dockerfile in build.yaml (opea-proj…
…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
1 parent
907b30b
commit e8cffc6
Showing
7 changed files
with
190 additions
and
42 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
.github/workflows/pr-dockerfile-path-and-build-yaml-scan.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
35 changes: 1 addition & 34 deletions
35
.github/workflows/pr-path-detection.yml → .github/workflows/pr-link-path-scan.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters