Publish Docker images #1524
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: Publish Docker images | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| push_to_registry: | |
| name: Push Docker images to GHCR | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: read | |
| attestations: write | |
| id-token: write | |
| strategy: | |
| matrix: | |
| name: ["base","ubuntu","mpich"] | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@v4 | |
| - name: downcase REPO | |
| run: | | |
| echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} | |
| - name: Determine tag suffix | |
| id: tag_suffix | |
| run: | | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| echo "TAG_SUFFIX=${{ github.event.release.tag_name }}" >> $GITHUB_ENV | |
| else | |
| SHORT_HASH=$(git rev-parse --short HEAD) | |
| LATEST_RELEASE=$(git describe --tags --abbrev=0 || echo "latest") | |
| echo "TAG_SUFFIX=${LATEST_RELEASE}-${SHORT_HASH}" >> $GITHUB_ENV | |
| fi | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.REGISTRY }}/${{ env.REPO }}/${{ matrix.name }} | |
| tags: | | |
| type=raw,value=${{ env.TAG_SUFFIX }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and push Docker image | |
| id: push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile-${{ matrix.name }} # Builds the correct Dockerfile | |
| push: true | |
| tags: ${{ env.REGISTRY }}/${{ env.REPO }}/${{ matrix.name }}:${{ env.TAG_SUFFIX }} # Explicitly set tag | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # - name: Debug build output | |
| # run: | | |
| # docker images ${{ env.REGISTRY }}/${{ env.REPO }}/${{ matrix.name }} | |
| # - name: Debug attestation input | |
| # run: | | |
| # echo "Subject name: ${{ env.REGISTRY }}/${{ env.REPO }}/${{ matrix.name }}:${{ env.TAG_SUFFIX }}" | |
| # echo "Subject digest: ${{ steps.push.outputs.digest }}" | |
| # - name: Generate artifact attestation | |
| # uses: actions/attest-build-provenance@v2 | |
| # with: | |
| # subject-name: ${{ env.REGISTRY }}/${{ matrix.name }} | |
| # subject-digest: ${{ steps.push.outputs.digest }} | |
| # push-to-registry: true |