Skip to content

Commit cd2c6e4

Browse files
committed
fix: repeating repo updates
1 parent 9a77a8d commit cd2c6e4

File tree

4 files changed

+29
-76
lines changed

4 files changed

+29
-76
lines changed

.github/workflows/pi_build.yml

Lines changed: 20 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -131,31 +131,20 @@ jobs:
131131
HEAD_REF: ${{ needs.configure-branch-name.outputs.gh_head_ref }}
132132
strategy:
133133
matrix:
134-
include: ${{ fromJson(needs.pi-matrix.outputs.include) }}
134+
app: ${{ fromJson(needs.pi-matrix.outputs.app) }}
135135
steps:
136136
- name: Checkout repository
137137
uses: actions/checkout@v4
138138
with:
139139
token: ${{ secrets.GH_TOKEN }}
140-
repository: '${{ github.repository_owner }}/refinery-${{ matrix.parent_image_type }}-parent-image'
140+
repository: '${{ github.repository_owner }}/refinery-submodule-parent-images'
141141
fetch-depth: 0
142-
submodules: 'true'
143142

144143
- name: Set up Python
145144
uses: actions/setup-python@v5
146145
with:
147146
python-version: ${{ env.PYTHON_VERSION }}
148147

149-
- name: Install Dependencies
150-
if: matrix.parent_image_type != 'next'
151-
run: python -m pip install pip-tools
152-
153-
- name: Compile Requirements
154-
run: |
155-
cd ${{ github.workspace }}/submodules/parent-images
156-
git checkout ${{ env.HEAD_REF }}
157-
pip-compile requirements/${{ matrix.parent_image_type }}-requirements.in
158-
159148
- name: Clone cicd-deployment-scripts
160149
run: git clone https://oauth2:${{ secrets.GH_TOKEN }}@github.com/code-kern-ai/cicd-deployment-scripts.git
161150

@@ -169,49 +158,44 @@ jobs:
169158
170159
git checkout -b ${{ env.HEAD_REF }} || git checkout ${{ env.HEAD_REF }}
171160
git pull origin ${{ env.HEAD_REF }} || true
172-
173-
- name: Compile Requirements (Python)
174-
if: matrix.parent_image_type != 'next'
175-
run: |
176-
cd ${{ github.workspace }}/submodules/parent-images
177-
git checkout ${{ env.HEAD_REF }}
178-
pip-compile --quiet \
179-
--output-file ${{ github.workspace }}/${{ matrix.app }}/requirements/${{ matrix.parent_image_type }}-requirements.txt \
180-
requirements/${{ matrix.parent_image_type }}-requirements.in
181161
182-
- name: Compile Requirements (Next)
183-
if: matrix.parent_image_type == 'next'
162+
- name: Update parent requirements
184163
run: |
185-
cd ${{ github.workspace }}
186-
jq --slurp '.[0] * .[1]' \
187-
package.json \
188-
${{ matrix.app }}/package.json \
189-
> package.json.tmp
190-
mv package.json.tmp ${{ matrix.app }}/package.json
164+
cd ${{ github.workspace }}/${{ matrix.app }}
165+
REQUIREMENTS_FILES=$(ls requirements/*.txt)
166+
for requirement_file in $REQUIREMENTS_FILES; do
167+
cp ${{ github.workspace }}/refinery-submodule-parent-images/$requirement_file $requirement_file
168+
done
191169
192170
- name: Perform Edit/Git Operations (Python)
193-
if: matrix.parent_image_type != 'next'
194171
run: |
195172
cd ${{ github.workspace }}/${{ matrix.app }}
196173
197174
bash ${{ github.workspace }}/cicd-deployment-scripts/pi/edit_dockerfile.sh \
198175
-i "${{ env.PARENT_IMAGE_NAME }}" \
199-
-t "${{ matrix.parent_image_type }}" \
200176
-l "${{ env.HEAD_REF }}" \
201177
-r "${{ env.DOCKERHUB_CONTAINER_REGISTRY }}" \
202178
-d "${{ env.DOCKERFILE }}"
203179
204180
bash ${{ github.workspace }}/cicd-deployment-scripts/pi/edit_dockerfile.sh \
205181
-i "${{ env.PARENT_IMAGE_NAME }}" \
206-
-t "${{ matrix.parent_image_type }}" \
207182
-l "${{ env.HEAD_REF }}" \
208183
-r "${{ env.DOCKERHUB_CONTAINER_REGISTRY }}" \
209184
-d "dev.${{ env.DOCKERFILE }}"
185+
186+
if [ -f "gpu.${{ env.DOCKERFILE }}" ]; then
187+
bash ${{ github.workspace }}/cicd-deployment-scripts/pi/edit_dockerfile.sh \
188+
-i "${{ env.PARENT_IMAGE_NAME }}" \
189+
-l "${{ env.HEAD_REF }}" \
190+
-r "${{ env.DOCKERHUB_CONTAINER_REGISTRY }}" \
191+
-d "gpu.${{ env.DOCKERFILE }}"
192+
fi
210193
211-
git add requirements/${{ matrix.parent_image_type }}-requirements.txt ${{ env.DOCKERFILE }} dev.${{ env.DOCKERFILE }}
212-
git commit -m "ci: update ${{ matrix.parent_image_type }}-requirements.txt and Dockerfile" || true
194+
git add requirements/*.txt ${{ env.DOCKERFILE }} dev.${{ env.DOCKERFILE }}
195+
if [ -f "gpu.${{ env.DOCKERFILE }}" ]; then git add gpu.${{ env.DOCKERFILE }}; fi
196+
git commit -m "ci: update requirements and Dockerfile" || true
213197
git push origin ${{ env.HEAD_REF }}
214-
echo "::notice::${{ matrix.app }} - updated ${{ matrix.parent_image_type }}-requirements.txt"
198+
echo "::notice::${{ matrix.app }} - updated requirement files and ${{ env.DOCKERFILE }}s"
215199
216200
export exitcode=0
217201
pip-compile --quiet \
@@ -234,35 +218,3 @@ jobs:
234218
--base dev \
235219
--head ${{ env.HEAD_REF }} \
236220
--repo ${{ github.repository_owner }}/${{ matrix.app }} || true
237-
238-
- name: Perform Edit/Git Operations (Next)
239-
if: matrix.parent_image_type == 'next'
240-
run: |
241-
cd ${{ github.workspace }}/${{ matrix.app }}
242-
243-
bash ${{ github.workspace }}/cicd-deployment-scripts/pi/edit_dockerfile.sh \
244-
-i "${{ env.PARENT_IMAGE_NAME }}" \
245-
-t "${{ matrix.parent_image_type }}" \
246-
-l "${{ env.HEAD_REF }}" \
247-
-r "${{ env.DOCKERHUB_CONTAINER_REGISTRY }}" \
248-
-d "${{ env.DOCKERFILE }}"
249-
250-
bash ${{ github.workspace }}/cicd-deployment-scripts/pi/edit_dockerfile.sh \
251-
-i "${{ env.PARENT_IMAGE_NAME }}" \
252-
-t "${{ matrix.parent_image_type }}" \
253-
-l "${{ env.HEAD_REF }}" \
254-
-r "${{ env.DOCKERHUB_CONTAINER_REGISTRY }}" \
255-
-d "dev.${{ env.DOCKERFILE }}"
256-
257-
git add package.json
258-
git commit -m "ci: update ${{ matrix.parent_image_type }} package.json" || true
259-
git push origin ${{ env.HEAD_REF }}
260-
echo "::notice::${{ matrix.app }} - updated ${{ matrix.parent_image_type }} package.json"
261-
262-
gh pr create --draft \
263-
--title "test: parent image updates" \
264-
--body "${{ github.event.pull_request.body }}" \
265-
--base dev \
266-
--head ${{ env.HEAD_REF }} \
267-
--repo ${{ github.repository_owner }}/${{ matrix.app }} || true
268-

.github/workflows/pi_matrix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
PYTHON_VERSION: ${{ vars.PYTHON_VERSION }}
4444
outputs:
4545
parent_image_type: ${{ steps.generate-matrix.outputs.parent_image_type }}
46-
include: ${{ steps.generate-matrix.outputs.include }}
46+
app: ${{ steps.generate-matrix.outputs.app }}
4747
steps:
4848
- name: Checkout Repository
4949
uses: actions/checkout@v4

pi/edit_dockerfile.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
set -e
44

55
PARENT_IMAGE_NAME="refinery-parent-images"
6-
PARENT_IMAGE_TYPE=""
76
RELEASE_TAG=""
87
DOCKER_REGISTRY="kernai"
98
DOCKERFILE="Dockerfile"
109

11-
while getopts i:t:l:r:d: flag
10+
while getopts i:l:r:d: flag
1211
do
1312
case "${flag}" in
1413
i) PARENT_IMAGE_NAME=${OPTARG};;
15-
t) PARENT_IMAGE_TYPE=$(echo ${OPTARG} | sed 's|_|-|g');;
1614
l) RELEASE_TAG=${OPTARG};;
1715
r) DOCKER_REGISTRY=${OPTARG};;
1816
d) DOCKERFILE=${OPTARG};;
@@ -21,6 +19,7 @@ done
2119

2220
grep "${DOCKER_REGISTRY}/${PARENT_IMAGE_NAME}" $DOCKERFILE | while read -r line ; do
2321
PI_EXISTING_TAG=$(echo $line | sed 's|FROM ||g' | cut -d ':' -f 2)
22+
PARENT_IMAGE_TYPE=$(echo $PI_EXISTING_TAG | cut -d '-' -f 2-)
2423
PI_EXISTING_IMAGE="${DOCKER_REGISTRY}/${PARENT_IMAGE_NAME}:${PI_EXISTING_TAG}"
2524
PI_NEW_IMAGE="${DOCKER_REGISTRY}/${PARENT_IMAGE_NAME}:${RELEASE_TAG}-${PARENT_IMAGE_TYPE}"
2625

pi/matrix.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ elif [ -n $PARENT_IMAGE_TYPE ]; then
3939
fi
4040

4141
PARENT_IMAGE_TYPES=""
42-
INCLUDES=""
42+
UPDATE_APPS=""
4343
for parent_image_type in "${UPDATED_PARENT_TYPES[@]}"; do
4444
PARENT_IMAGE_TYPES+="\"$parent_image_type\","
4545
if [ $EDIT_DOCKERFILE = true ]; then
@@ -48,11 +48,13 @@ for parent_image_type in "${UPDATED_PARENT_TYPES[@]}"; do
4848
eval 'APP_REPOS=( "${'$(echo ${parent_image_type} | sed "s|-|_|g")'[@]}" )'
4949
fi
5050
for app in "${APP_REPOS[@]}"; do
51-
INCLUDES+='{ "parent_image_type": "'${parent_image_type}'", "app": "'${app}'" },'
51+
if [[ ! "$UPDATE_APPS" == *"$app"* ]]; then
52+
UPDATE_APPS+='"'$app'",'
53+
fi
5254
done
5355
done
5456

55-
MATRIX='{"include": ['${INCLUDES::-1}']}'
57+
MATRIX='['${UPDATE_APPS::-1}']'
5658
echo $MATRIX | jq -C --indent 2 '.'
57-
echo "include=[${INCLUDES::-1}]" >> $GITHUB_OUTPUT
59+
echo "app=[${UPDATE_APPS::-1}]" >> $GITHUB_OUTPUT
5860
echo "parent_image_type=[${PARENT_IMAGE_TYPES::-1}]" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)