|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +# This workflow uses actions that are not certified by GitHub. |
| 4 | +# They are provided by a third-party and are governed by |
| 5 | +# separate terms of service, privacy policy, and support |
| 6 | +# documentation. |
| 7 | + |
| 8 | +# GitHub recommends pinning actions to a commit SHA. |
| 9 | +# To get a newer version, you will need to update the SHA. |
| 10 | +# You can also reference a tag or branch, but the action may change without warning. |
| 11 | + |
| 12 | +# Please do not attempt to edit this flow without the direct consent from the DevOps team. This file is managed centrally. |
| 13 | + |
| 14 | +name: Publish Docker image |
| 15 | + |
| 16 | +on: |
| 17 | + push: |
| 18 | + branches: [ "main" ] |
| 19 | + |
| 20 | +jobs: |
| 21 | + push_to_registry: |
| 22 | + if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' |
| 23 | + name: Push Docker image to Docker Hub |
| 24 | + runs-on: ubuntu-latest |
| 25 | + permissions: |
| 26 | + packages: write |
| 27 | + contents: read |
| 28 | + attestations: write |
| 29 | + id-token: write |
| 30 | + steps: |
| 31 | + - name: Check out the repo |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Log in to Docker Hub |
| 35 | + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a |
| 36 | + with: |
| 37 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 38 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 39 | + |
| 40 | + - name: Set ENV variables |
| 41 | + run: | |
| 42 | + echo "REPO_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV |
| 43 | + |
| 44 | + - name: Use the custom ENV variable |
| 45 | + run: | |
| 46 | + echo $REPO_NAME |
| 47 | +
|
| 48 | + - name: Extract metadata (tags, labels) for Docker |
| 49 | + id: meta |
| 50 | + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 |
| 51 | + with: |
| 52 | + images: tazamaorg/${{ env.REPO_NAME }} |
| 53 | + tags: | |
| 54 | + type=raw,value=2.1.0 |
| 55 | +
|
| 56 | + - name: Build and push Docker image |
| 57 | + id: push |
| 58 | + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 |
| 59 | + with: |
| 60 | + context: . |
| 61 | + file: ./Dockerfile |
| 62 | + push: true |
| 63 | + tags: ${{ steps.meta.outputs.tags }} |
| 64 | + labels: ${{ steps.meta.outputs.labels }} |
| 65 | + build-args: GH_TOKEN=${{ secrets.GH_TOKEN }} |
| 66 | + |
| 67 | + - name: Generate artifact attestation |
| 68 | + uses: actions/attest-build-provenance@v1 |
| 69 | + with: |
| 70 | + subject-name: docker.io/tazamaorg/${{ env.REPO_NAME }} |
| 71 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 72 | + push-to-registry: false |
| 73 | + |
| 74 | + - name: Send Slack Notification |
| 75 | + env: |
| 76 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 77 | + run: | |
| 78 | + curl -X POST -H 'Content-type: application/json' --data '{"blocks": [{"type": "header","text": {"type": "plain_text","text": "New Dockerhub Image published :ship::ship:","emoji": true}},{"type": "section","fields": [{"type": "mrkdwn","text": "*Service:*\n${{ env.REPO_NAME }} "},{"type": "mrkdwn","text": "*Tazama Dockerhub:*\n<https://hub.docker.com/orgs/tazamaorg/repositories>"}]}]}' $SLACK_WEBHOOK_URL |
0 commit comments