Skip to content

Commit d12c7bc

Browse files
committed
CI: Generate commit-specific and branch-latest docker compose files, move away from a temporary "generated" branch for syllabi files, and cleanup intermediate variables in the GitHub workflow.
1 parent 67c352f commit d12c7bc

File tree

5 files changed

+359
-191
lines changed

5 files changed

+359
-191
lines changed

.github/workflows/build-brev-tutorial-docker-images.yml

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
name: Build and Push Brev Tutorial Docker Images
22

3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
310
jobs:
411
discover-tutorials:
512
runs-on: linux-amd64-cpu4
@@ -41,40 +48,43 @@ jobs:
4148

4249
- name: Set Git branch variables
4350
run: |
44-
echo "GIT_BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
45-
echo "GIT_SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
51+
GIT_BRANCH_NAME=${GITHUB_REF#refs/heads/}
52+
GIT_SHA=${{ github.sha }}
53+
GIT_SHORT_SHA=${GIT_SHA::7}
54+
echo "GIT_BRANCH_NAME=${GIT_BRANCH_NAME}" >> $GITHUB_ENV
55+
echo "GIT_SHA=${GIT_SHA}" >> $GITHUB_ENV
56+
echo "GIT_SHORT_SHA=${GIT_SHORT_SHA}" >> $GITHUB_ENV
4657
4758
- name: Set image name and tutorial name
48-
id: set-image
4959
run: |
50-
tutorial_name=$(basename ${{ matrix.tutorial }})
51-
image_name="ghcr.io/${{ github.repository_owner }}/${tutorial_name}-tutorial"
52-
echo "image_name=${image_name,,}" >> $GITHUB_OUTPUT
53-
echo "tutorial_name=${tutorial_name}" >> $GITHUB_OUTPUT
60+
TUTORIAL_NAME=$(basename ${{ matrix.tutorial }})
61+
IMAGE_NAME="ghcr.io/${{ github.repository_owner }}/${TUTORIAL_NAME}-tutorial"
62+
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV
63+
echo "TUTORIAL_NAME=${TUTORIAL_NAME}" >> $GITHUB_ENV
5464
5565
- name: Check for HPCCM recipe
56-
id: check-hpccm
5766
run: |
5867
if [ -f "${{ matrix.tutorial }}/brev/docker-recipe.py" ]; then
59-
echo "has_hpccm=true" >> $GITHUB_OUTPUT
68+
HAS_HPCCM=true
6069
else
61-
echo "has_hpccm=false" >> $GITHUB_OUTPUT
70+
HAS_HPCCM=false
6271
fi
72+
echo "HAS_HPCCM=${HAS_HPCCM}" >> $GITHUB_ENV
6373
6474
- name: Set up Python (for HPCCM)
65-
if: steps.check-hpccm.outputs.has_hpccm == 'true'
75+
if: env.HAS_HPCCM == 'true'
6676
uses: actions/setup-python@v4
6777
with:
6878
python-version: '3.x'
6979

7080
- name: Install HPCCM
71-
if: steps.check-hpccm.outputs.has_hpccm == 'true'
81+
if: env.HAS_HPCCM == 'true'
7282
run: |
7383
python -m pip install --upgrade pip
7484
pip install hpccm
7585
7686
- name: Generate Dockerfile from HPCCM recipe
77-
if: steps.check-hpccm.outputs.has_hpccm == 'true'
87+
if: env.HAS_HPCCM == 'true'
7888
run: |
7989
hpccm --recipe ${{ matrix.tutorial }}/brev/docker-recipe.py --format docker > ${{ matrix.tutorial }}/brev/dockerfile
8090
@@ -100,45 +110,74 @@ jobs:
100110
cd ${{ matrix.tutorial }}/brev
101111
102112
# Tag the image as `latest` if we're on `main`.
103-
if [ "${{ env.GIT_BRANCH_NAME }}" = "main" ]; then
104-
LATEST_TAG='--set "base.tags=${{ steps.set-image.outputs.image_name }}:latest"'
113+
if [ "${GIT_BRANCH_NAME}" = "main" ]; then
114+
LATEST_TAG='--set "base.tags=${IMAGE_NAME}:latest"'
105115
else
106116
LATEST_TAG=""
107117
fi
108118
109119
docker buildx bake \
110120
--allow=fs.read=/home/runner \
111-
--set "base.args.GIT_BRANCH_NAME=${{ env.GIT_BRANCH_NAME }}" \
121+
--set "base.args.GIT_BRANCH_NAME=${GIT_BRANCH_NAME}" \
112122
--set "base.output=type=registry" \
113-
--set "base.tags=${{ steps.set-image.outputs.image_name }}:${{ env.GIT_BRANCH_NAME }}-latest" \
114-
--set "base.tags=${{ steps.set-image.outputs.image_name }}:${{ env.GIT_BRANCH_NAME }}-git-${{ env.GIT_SHORT_SHA }}" \
123+
--set "base.tags=${IMAGE_NAME}:${GIT_BRANCH_NAME}-latest" \
124+
--set "base.tags=${IMAGE_NAME}:${GIT_BRANCH_NAME}-git-${GIT_SHORT_SHA}" \
115125
$LATEST_TAG \
116-
--set "base.cache-from=type=registry,ref=${{ steps.set-image.outputs.image_name }}:buildcache" \
117-
--set "base.cache-to=type=registry,ref=${{ steps.set-image.outputs.image_name }}:buildcache,mode=max" \
126+
--set "base.cache-from=type=registry,ref=${IMAGE_NAME}:buildcache" \
127+
--set "base.cache-to=type=registry,ref=${IMAGE_NAME}:buildcache,mode=max" \
118128
--set "base.platform=linux/amd64" \
119129
-f docker-compose.yml \
120130
base
121131
132+
- name: Generate Docker Compose files
133+
run: |
134+
python3 brev/generate-tagged-docker-composes.py \
135+
--image-tag "${GIT_BRANCH_NAME}-git-${GIT_SHORT_SHA}" \
136+
--output-dir "artifacts/commit-specific" \
137+
--tutorial "${TUTORIAL_NAME}" \
138+
--type all
139+
140+
python3 brev/generate-tagged-docker-composes.py \
141+
--image-tag "${GIT_BRANCH_NAME}-latest" \
142+
--output-dir "artifacts/branch-latest" \
143+
--tutorial "${TUTORIAL_NAME}" \
144+
--type all
145+
146+
- name: Upload commit-specific docker-compose artifacts
147+
uses: actions/upload-artifact@v4
148+
with:
149+
name: docker-compose-${{ env.TUTORIAL_NAME }}-${{ env.GIT_BRANCH_NAME }}-git-${{ env.GIT_SHORT_SHA }}
150+
path: artifacts/commit-specific/${{ env.TUTORIAL_NAME }}/
151+
retention-days: 30
152+
153+
- name: Upload branch-latest docker-compose artifacts
154+
uses: actions/upload-artifact@v4
155+
with:
156+
name: docker-compose-${{ env.TUTORIAL_NAME }}-${{ env.GIT_BRANCH_NAME }}-latest
157+
path: artifacts/branch-latest/${{ env.TUTORIAL_NAME }}/
158+
retention-days: 30
159+
122160
- name: Create pending commit status for test
123161
run: |
124162
gh api \
125163
--method POST \
126164
-H "Accept: application/vnd.github+json" \
127-
/repos/${{ github.repository }}/statuses/${{ github.sha }} \
165+
/repos/${{ github.repository }}/statuses/${GIT_SHA} \
128166
-f state='pending' \
129167
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/workflows/test-brev-tutorial-docker-images.yml" \
130168
-f description='Test started' \
131-
-f context='test / ${{ steps.set-image.outputs.tutorial_name }}'
169+
-f context="test / ${TUTORIAL_NAME}"
132170
env:
133171
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134172

135173
- name: Trigger test workflow
136174
run: |
137-
echo "Triggering test for tutorial: ${{ steps.set-image.outputs.tutorial_name }}"
175+
echo "Triggering test for tutorial: ${TUTORIAL_NAME}"
138176
gh workflow run test-brev-tutorial-docker-images.yml \
139177
--ref ${{ github.ref_name }} \
140-
-f tutorial=${{ steps.set-image.outputs.tutorial_name }} \
141-
-f commit_sha=${{ github.sha }}
178+
-f tutorial=${TUTORIAL_NAME} \
179+
-f git_sha=${GIT_SHA} \
180+
-f workflow_run_id=${{ github.run_id }}
142181
echo "Test workflow triggered successfully"
143182
env:
144183
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/generate-syllabi-docker-composes.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

.github/workflows/test-brev-tutorial-docker-images.yml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ on:
77
description: 'Tutorial name to test'
88
required: true
99
type: string
10-
commit_sha:
11-
description: 'Commit SHA to update status for'
10+
git_sha:
11+
description: 'Git commit SHA to update status for'
12+
required: true
13+
type: string
14+
workflow_run_id:
15+
description: 'Workflow run ID to download artifacts from'
1216
required: true
1317
type: string
1418

@@ -32,6 +36,23 @@ jobs:
3236
- name: Checkout repository
3337
uses: actions/checkout@v4
3438

39+
- name: Set Git branch variables
40+
run: |
41+
GIT_BRANCH_NAME=${GITHUB_REF#refs/heads/}
42+
GIT_SHA=${{ inputs.git_sha }}
43+
GIT_SHORT_SHA=${GIT_SHA:0:7}
44+
echo "GIT_BRANCH_NAME=${GIT_BRANCH_NAME}" >> $GITHUB_ENV
45+
echo "GIT_SHA=${GIT_SHA}" >> $GITHUB_ENV
46+
echo "GIT_SHORT_SHA=${GIT_SHORT_SHA}" >> $GITHUB_ENV
47+
48+
- name: Download commit-specific Docker Compose artifact
49+
uses: dawidd6/action-download-artifact@v2
50+
with:
51+
workflow: build-brev-tutorial-docker-images.yml
52+
run_id: ${{ inputs.workflow_run_id }}
53+
name: docker-compose-${{ inputs.tutorial }}-${{ env.GIT_BRANCH_NAME }}-git-${{ env.GIT_SHORT_SHA }}
54+
path: artifacts/commit-specific/${{ inputs.tutorial }}/
55+
3556
- name: Log in to GitHub Container Registry
3657
uses: docker/login-action@v3
3758
with:
@@ -42,15 +63,15 @@ jobs:
4263
- name: Test Docker Compose
4364
id: test
4465
run: |
45-
./brev/test-docker-compose.bash "tutorials/${{ inputs.tutorial }}/brev/docker-compose.yml"
66+
./brev/test-docker-compose.bash "artifacts/commit-specific/${{ inputs.tutorial }}/brev/docker-compose.yml"
4667
4768
- name: Update commit status to success
4869
if: success()
4970
run: |
5071
gh api \
5172
--method POST \
5273
-H "Accept: application/vnd.github+json" \
53-
/repos/${{ github.repository }}/statuses/${{ inputs.commit_sha }} \
74+
/repos/${{ github.repository }}/statuses/${GIT_SHA} \
5475
-f state='success' \
5576
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
5677
-f description='Tests passed' \
@@ -64,7 +85,7 @@ jobs:
6485
gh api \
6586
--method POST \
6687
-H "Accept: application/vnd.github+json" \
67-
/repos/${{ github.repository }}/statuses/${{ inputs.commit_sha }} \
88+
/repos/${{ github.repository }}/statuses/${GIT_SHA} \
6889
-f state='failure' \
6990
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
7091
-f description='Tests failed' \

brev/generate-syllabi-docker-composes.py

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)