|
| 1 | +name: Build and Push Brev Tutorial Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - brev-reorg |
| 7 | + |
| 8 | +jobs: |
| 9 | + discover-tutorials: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + tutorials: ${{ steps.find-tutorials.outputs.tutorials }} |
| 13 | + steps: |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Find tutorial directories |
| 18 | + id: find-tutorials |
| 19 | + run: | |
| 20 | + tutorials=$(find . -maxdepth 1 -type d -name '*-tutorial' -printf '%f\n' | jq -R -s -c 'split("\n") | map(select(length > 0))') |
| 21 | + echo "tutorials=${tutorials}" >> $GITHUB_OUTPUT |
| 22 | + echo "Found tutorials: ${tutorials}" |
| 23 | +
|
| 24 | + build-and-push: |
| 25 | + needs: discover-tutorials |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + packages: write |
| 30 | + strategy: |
| 31 | + matrix: |
| 32 | + tutorial: ${{ fromJson(needs.discover-tutorials.outputs.tutorials) }} |
| 33 | + fail-fast: false |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout repository |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Get branch name |
| 40 | + run: echo "GIT_BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV |
| 41 | + |
| 42 | + - name: Set image name |
| 43 | + id: set-image |
| 44 | + run: | |
| 45 | + image_name="ghcr.io/${{ github.repository_owner }}/${{ matrix.tutorial }}" |
| 46 | + echo "image_name=${image_name,,}" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + - name: Check for HPCCM recipe |
| 49 | + id: check-hpccm |
| 50 | + run: | |
| 51 | + if [ -f "${{ matrix.tutorial }}/brev/docker-recipe.py" ]; then |
| 52 | + echo "has_hpccm=true" >> $GITHUB_OUTPUT |
| 53 | + else |
| 54 | + echo "has_hpccm=false" >> $GITHUB_OUTPUT |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Set up Python (for HPCCM) |
| 58 | + if: steps.check-hpccm.outputs.has_hpccm == 'true' |
| 59 | + uses: actions/setup-python@v4 |
| 60 | + with: |
| 61 | + python-version: '3.x' |
| 62 | + |
| 63 | + - name: Install HPCCM |
| 64 | + if: steps.check-hpccm.outputs.has_hpccm == 'true' |
| 65 | + run: | |
| 66 | + python -m pip install --upgrade pip |
| 67 | + pip install hpccm |
| 68 | +
|
| 69 | + - name: Generate Dockerfile from HPCCM recipe |
| 70 | + if: steps.check-hpccm.outputs.has_hpccm == 'true' |
| 71 | + run: | |
| 72 | + hpccm --recipe ${{ matrix.tutorial }}/brev/docker-recipe.py --format docker > ${{ matrix.tutorial }}/brev/dockerfile |
| 73 | +
|
| 74 | + - name: Log in to GitHub Container Registry |
| 75 | + uses: docker/login-action@v3 |
| 76 | + with: |
| 77 | + registry: ghcr.io |
| 78 | + username: ${{ github.actor }} |
| 79 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + |
| 81 | + - name: Build Docker image with Compose |
| 82 | + run: docker compose -f ${{ matrix.tutorial }}/brev/docker-compose.yml build |
| 83 | + |
| 84 | + - name: Tag Docker images |
| 85 | + run: | |
| 86 | + docker tag "${{ steps.set-image.outputs.image_name }}:${GIT_BRANCH_NAME}-latest" "${{ steps.set-image.outputs.image_name }}:${GIT_BRANCH_NAME}-latest" |
| 87 | + docker tag "${{ steps.set-image.outputs.image_name }}:${GIT_BRANCH_NAME}-latest" "${{ steps.set-image.outputs.image_name }}:${GIT_BRANCH_NAME}-git-${GITHUB_SHA::7}" |
| 88 | +
|
| 89 | + - name: Push Docker images |
| 90 | + run: | |
| 91 | + docker push "${{ steps.set-image.outputs.image_name }}:${GIT_BRANCH_NAME}-latest" |
| 92 | + docker push "${{ steps.set-image.outputs.image_name }}:${GIT_BRANCH_NAME}-git-${GITHUB_SHA::7}" |
0 commit comments