11name : Build and Push Brev Tutorial Docker Images
22
3+ on :
4+ push :
5+ branches :
6+ - main
7+ pull_request :
8+ workflow_dispatch :
9+
310jobs :
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 }}
0 commit comments