Updates to the nvmath Python tutorial content #75
Workflow file for this run
This file contains hidden or 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
| name: Build and Push Brev Tutorial Docker Images | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| workflow_dispatch: | |
| jobs: | |
| discover-tutorials: | |
| runs-on: linux-amd64-cpu4 | |
| defaults: | |
| run: | |
| working-directory: ${{ github.workspace }} | |
| outputs: | |
| tutorials: ${{ steps.find-tutorials.outputs.tutorials }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Find tutorial directories | |
| id: find-tutorials | |
| run: | | |
| tutorials=$(brev/discover-tutorials.bash | jq -R -s -c 'split("\n") | map(select(length > 0))') | |
| echo "tutorials=${tutorials}" >> $GITHUB_OUTPUT | |
| echo "Found tutorials: ${tutorials}" | |
| build-and-push: | |
| needs: discover-tutorials | |
| runs-on: linux-amd64-cpu4 | |
| defaults: | |
| run: | |
| working-directory: ${{ github.workspace }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| actions: write | |
| statuses: write | |
| strategy: | |
| matrix: | |
| tutorial: ${{ fromJson(needs.discover-tutorials.outputs.tutorials) }} | |
| fail-fast: false | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set Git branch variables | |
| run: | | |
| GIT_BRANCH_NAME=${GITHUB_REF#refs/heads/} | |
| GIT_SHA=${{ github.sha }} | |
| GIT_SHORT_SHA=${GIT_SHA::7} | |
| echo "GIT_BRANCH_NAME=${GIT_BRANCH_NAME}" >> $GITHUB_ENV | |
| echo "GIT_SHA=${GIT_SHA}" >> $GITHUB_ENV | |
| echo "GIT_SHORT_SHA=${GIT_SHORT_SHA}" >> $GITHUB_ENV | |
| - name: Set image name and tutorial name | |
| run: | | |
| TUTORIAL_NAME=$(basename ${{ matrix.tutorial }}) | |
| IMAGE_NAME="ghcr.io/${{ github.repository_owner }}/${TUTORIAL_NAME}-tutorial" | |
| echo "IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV | |
| echo "TUTORIAL_NAME=${TUTORIAL_NAME}" >> $GITHUB_ENV | |
| - name: Check for HPCCM recipe | |
| run: | | |
| if [ -f "${{ matrix.tutorial }}/brev/docker-recipe.py" ]; then | |
| HAS_HPCCM=true | |
| else | |
| HAS_HPCCM=false | |
| fi | |
| echo "HAS_HPCCM=${HAS_HPCCM}" >> $GITHUB_ENV | |
| - name: Set up Python (for HPCCM) | |
| if: env.HAS_HPCCM == 'true' | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| - name: Install HPCCM | |
| if: env.HAS_HPCCM == 'true' | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install hpccm | |
| - name: Generate Dockerfile from HPCCM recipe | |
| if: env.HAS_HPCCM == 'true' | |
| run: | | |
| hpccm --recipe ${{ matrix.tutorial }}/brev/docker-recipe.py --format docker > ${{ matrix.tutorial }}/brev/dockerfile | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push Docker image (with retry) | |
| uses: nick-fields/retry@v3 | |
| env: | |
| DOCKER_BUILDKIT: 1 | |
| with: | |
| timeout_minutes: 60 | |
| max_attempts: 3 | |
| retry_wait_seconds: 30 | |
| command: | | |
| cd ${{ matrix.tutorial }}/brev | |
| # Tag the image as `latest` if we're on `main`. | |
| if [ "${GIT_BRANCH_NAME}" = "main" ]; then | |
| LATEST_TAG='--set "base.tags=${IMAGE_NAME}:latest"' | |
| else | |
| LATEST_TAG="" | |
| fi | |
| docker buildx bake \ | |
| --allow=fs.read=/home/runner \ | |
| --set "base.args.GIT_BRANCH_NAME=${GIT_BRANCH_NAME}" \ | |
| --set "base.output=type=registry" \ | |
| --set "base.tags=${IMAGE_NAME}:${GIT_BRANCH_NAME}-latest" \ | |
| --set "base.tags=${IMAGE_NAME}:${GIT_BRANCH_NAME}-git-${GIT_SHORT_SHA}" \ | |
| $LATEST_TAG \ | |
| --set "base.cache-from=type=registry,ref=${IMAGE_NAME}:buildcache" \ | |
| --set "base.cache-to=type=registry,ref=${IMAGE_NAME}:buildcache,mode=max" \ | |
| --set "base.platform=linux/amd64" \ | |
| -f docker-compose.yml \ | |
| base | |
| - name: Generate Docker Compose files | |
| run: | | |
| python3 brev/generate-tagged-docker-composes.py \ | |
| --image-tag "${GIT_BRANCH_NAME}-git-${GIT_SHORT_SHA}" \ | |
| --output-dir "artifacts/commit-specific" \ | |
| --tutorial "${TUTORIAL_NAME}" \ | |
| --type all | |
| python3 brev/generate-tagged-docker-composes.py \ | |
| --image-tag "${GIT_BRANCH_NAME}-latest" \ | |
| --output-dir "artifacts/branch-latest" \ | |
| --tutorial "${TUTORIAL_NAME}" \ | |
| --type all | |
| - name: Upload commit-specific docker-compose artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docker-compose-${{ env.TUTORIAL_NAME }}-${{ env.GIT_BRANCH_NAME }}-git-${{ env.GIT_SHORT_SHA }} | |
| path: artifacts/commit-specific/${{ env.TUTORIAL_NAME }}/ | |
| retention-days: 30 | |
| - name: Upload branch-latest docker-compose artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docker-compose-${{ env.TUTORIAL_NAME }}-${{ env.GIT_BRANCH_NAME }}-latest | |
| path: artifacts/branch-latest/${{ env.TUTORIAL_NAME }}/ | |
| retention-days: 30 | |
| - name: Create pending commit status for test | |
| run: | | |
| gh api \ | |
| --method POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| /repos/${{ github.repository }}/statuses/${GIT_SHA} \ | |
| -f state='pending' \ | |
| -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/workflows/test-brev-tutorial-docker-images.yml" \ | |
| -f description='Test started' \ | |
| -f context="test / ${TUTORIAL_NAME}" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Trigger test workflow | |
| run: | | |
| echo "Triggering test for tutorial: ${TUTORIAL_NAME}" | |
| gh workflow run test-brev-tutorial-docker-images.yml \ | |
| --ref ${{ github.ref_name }} \ | |
| -f tutorial=${TUTORIAL_NAME} \ | |
| -f git_sha=${GIT_SHA} \ | |
| -f workflow_run_id=${{ github.run_id }} | |
| echo "Test workflow triggered successfully" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Check disk space after build | |
| if: always() | |
| run: | | |
| echo "Disk space after build:" | |
| df -h / | |
| echo "" | |
| echo "Disk usage by directory:" | |
| du -sh /var/lib/docker/* 2>/dev/null || true | |
| du -sh /var/lib/buildkit/* 2>/dev/null || true |