Docker: Move Git setup to after the repo copy and don't cache pip pac… #44
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: | |
| - brev-reorg | |
| jobs: | |
| discover-tutorials: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tutorials: ${{ steps.find-tutorials.outputs.tutorials }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Find tutorial directories | |
| id: find-tutorials | |
| run: | | |
| tutorials=$(find tutorials -mindepth 1 -maxdepth 1 -type d | 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: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| matrix: | |
| tutorial: ${{ fromJson(needs.discover-tutorials.outputs.tutorials) }} | |
| fail-fast: false | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # - name: Free up disk space | |
| # run: | | |
| # # Delete large pre-installed software in parallel for speed | |
| # sudo rm -rf /usr/local/lib/android & | |
| # sudo rm -rf /opt/hostedtoolcache/CodeQL & | |
| # sudo rm -rf /usr/share/dotnet & | |
| # wait | |
| # echo "Disk space after cleanup:" | |
| # df -h / | |
| - name: Get branch name and short SHA | |
| run: | | |
| echo "GIT_BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV | |
| echo "GIT_SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
| - name: Set image name | |
| id: set-image | |
| run: | | |
| image_name="ghcr.io/${{ github.repository_owner }}/$(basename ${{ matrix.tutorial }})-tutorial" | |
| echo "image_name=${image_name,,}" >> $GITHUB_OUTPUT | |
| - name: Check for HPCCM recipe | |
| id: check-hpccm | |
| run: | | |
| if [ -f "${{ matrix.tutorial }}/brev/docker-recipe.py" ]; then | |
| echo "has_hpccm=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_hpccm=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up Python (for HPCCM) | |
| if: steps.check-hpccm.outputs.has_hpccm == 'true' | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| - name: Install HPCCM | |
| if: steps.check-hpccm.outputs.has_hpccm == 'true' | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install hpccm | |
| - name: Generate Dockerfile from HPCCM recipe | |
| if: steps.check-hpccm.outputs.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 | |
| docker buildx bake \ | |
| --allow=fs.read=/home/runner \ | |
| --set "base.args.GIT_BRANCH_NAME=${{ env.GIT_BRANCH_NAME }}" \ | |
| --set "base.output=type=registry" \ | |
| --set "base.tags=${{ steps.set-image.outputs.image_name }}:${{ env.GIT_BRANCH_NAME }}-latest" \ | |
| --set "base.tags=${{ steps.set-image.outputs.image_name }}:${{ env.GIT_BRANCH_NAME }}-git-${{ env.GIT_SHORT_SHA }}" \ | |
| --set "base.cache-from=type=registry,ref=${{ steps.set-image.outputs.image_name }}:buildcache" \ | |
| --set "base.cache-to=type=registry,ref=${{ steps.set-image.outputs.image_name }}:buildcache,mode=max" \ | |
| --set "base.platform=linux/amd64" \ | |
| -f docker-compose.yml \ | |
| base | |
| - 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 |