-
Notifications
You must be signed in to change notification settings - Fork 142
201 lines (178 loc) · 6.84 KB
/
pr-dockerfile-path-scan.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# 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]
# 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:
Dockerfile-path-change-detection-in-GenAIComps:
runs-on: ubuntu-latest
steps:
- name: Clean Up Working Directory
run: sudo rm -rf ${{github.workspace}}/*
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Clone GenAIExamples
run: |
cd ..
git clone https://github.com/opea-project/GenAIExamples
- name: Check Dockerfile Paths in Readme
if: always()
run: |
set -e
shopt -s globstar
cd ${{github.workspace}}
is_use="FALSE"
used_files=""
merged_commit=$(git log -1 --format='%H')
changed_files="$(git diff --name-status --diff-filter=DR ${{ github.event.pull_request.base.sha }} ${merged_commit} -- '**/Dockerfile**' | cut -f2)"
if [ -n "$changed_files" ]; then
for file in $changed_files; do
if grep -q "$file" ./**/*.md; then
is_use="TRUE"
used_files+="$file "
fi
done
fi
if [[ "$is_use" == "TRUE" ]]; then
echo "Warning: Changed Dockerfile paths:"
echo "$used_files"
echo "Please modify the corresponding README in GenAIComps."
exit 1
fi
- name: Check Dockerfile path included in image build yaml
if: always()
run: |
set -e
shopt -s globstar
no_add="FALSE"
cd ${{github.workspace}}
Dockerfiles=$(find ./comps -name '*Dockerfile*'|sed 's/^\.\///')
if [ -n "$Dockerfiles" ]; then
for Dockerfile in $Dockerfiles; do
service=$(echo "$Dockerfile" | awk -F '/' '{print $2}')
yaml_file=${{github.workspace}}/.github/workflows/docker/compose/"$service"-compose
if ! grep -q "$Dockerfile" "$yaml_file"*yaml; then
echo "AR: Update $Dockerfile to .github/workflows/docker/compose/"$service"-compose.yaml. The yaml is used for release images build."
no_add="TRUE"
fi
done
fi
if [[ "$no_add" == "TRUE" ]]; then
exit 1
fi
- name: Check Dockerfile inside image build yaml exist in code
if: always()
run: |
shopt -s globstar
no_exist="FALSE"
cd ${{github.workspace}}
yamls=$(find .github/workflows/docker/compose/ -name '*.yaml')
if [ -n "$yamls" ]; then
for yaml in $yamls; do
dockerfiles=$(grep 'dockerfile:' "$yaml"|sed 's/dockerfile: //')
for dockerfile in $dockerfiles; do
if [[ "$dockerfile" == *"comps/"* ]]; then
if ! [ -e "$dockerfile" ]; then
# cat "$yaml"
echo "AR: The dockerfile path "$dockerfile" in "$yaml" does not exist, remove or update it."
no_exist="TRUE"
fi
fi
done
done
fi
if [[ "$no_exist" == "TRUE" ]]; then
exit 1
fi
Dockerfile-path-change-detection-in-GenAIExamples:
runs-on: ubuntu-latest
steps:
- name: Clean Up Working Directory
run: sudo rm -rf ${{github.workspace}}/*
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Clone repo GenAIExamples
run: |
cd ..
git clone https://github.com/opea-project/GenAIExamples
- name: Check for changed Dockerfile paths
run: |
set -e
shopt -s globstar
cd ${{github.workspace}}
is_use="FALSE"
used_files=""
merged_commit=$(git log -1 --format='%H')
changed_files="$(git diff --name-status --diff-filter=DR ${{ github.event.pull_request.base.sha }} ${merged_commit} -- '**/Dockerfile**' | cut -f2)"
if [ -n "$changed_files" ]; then
for file in $changed_files; do
matching_files=$(grep -rl "$file" ../GenAIExamples/**/*.md) || true
if [ -n "$matching_files" ]; then
is_use="TRUE"
used_files+="$file "
echo "Modified Dockerfile '$file' is referenced in:"
echo "$matching_files"
else
echo "Modified Dockerfile '$file' is not referenced"
fi
done
fi
if [[ "$is_use" == "TRUE" ]]; then
echo "Warning: Changed Dockerfile paths:"
echo "$used_files"
echo "Please modify the corresponding README in GenAIExamples repo and ask [email protected] for final confirmation."
exit 1
fi
check-image-and-service-names-in-compose-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 compose.yaml
run: |
pip install ruamel.yaml
cd ${{github.workspace}}
consistency="TRUE"
yamls=$(find .github/workflows/docker/compose/ -name '*-compose.yaml')
for build_yaml in $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
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