listener image build on workflow_dispatch by ShubhamTiwary914 #8
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 Listener Image and push to Dockerhub | |
| run-name: listener image build on ${{ github.event_name }} by ${{ github.actor }} | |
| on: | |
| push: | |
| branches: | |
| - 'master' | |
| paths: | |
| - 'services/listener/**' | |
| workflow_dispatch: | |
| jobs: | |
| build-listener: | |
| name: Push Listener's Image to DockerHub | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: read | |
| attestations: write | |
| id-token: write | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@v5 | |
| - name: Set Go path | |
| run: echo "GOPATH=${{ github.workspace }}/.go" >> $GITHUB_ENV | |
| - name: Cache Go modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ${{ github.workspace }}/.go/pkg/mod | |
| ${{ github.workspace }}/.go/bin | |
| key: go-mod-${{ runner.os }}-${{ hashFiles('**/go.sum') }} | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USER }} | |
| password: ${{ secrets.DOCKERHUB_PASS }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: extractor | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ secrets.LISTENER_IMAGE }} | |
| - name: Build and push Docker image | |
| id: push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./services/listener | |
| file: ./services/listener/Dockerfile | |
| push: true | |
| tags: | | |
| ${{ secrets.LISTENER_IMAGE }}:latest | |
| labels: ${{ steps.extractor.outputs.labels }} | |
| - name: Generate artifact attestation | |
| uses: actions/attest-build-provenance@v3 | |
| with: | |
| subject-name: index.docker.io/${{ secrets.LISTENER_IMAGE }} | |
| subject-digest: ${{ steps.push.outputs.digest }} | |
| push-to-registry: false |