|
| 1 | +name: Docker |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ 'main' ] |
| 6 | + tags: [ 'v*' ] |
| 7 | + pull_request: |
| 8 | + branches: [ 'main' ] |
| 9 | + |
| 10 | +env: |
| 11 | + REGISTRY: ghcr.io |
| 12 | + IMAGE_NAME: ${{ github.repository }} |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-push-image: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + packages: write |
| 20 | + id-token: write |
| 21 | + |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v3 |
| 24 | + |
| 25 | + - name: Setup Docker buildx |
| 26 | + uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325 # v2.2.1 |
| 27 | + |
| 28 | + - name: Log into registry ${{ env.REGISTRY }} |
| 29 | + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 |
| 30 | + if: github.event_name != 'pull_request' |
| 31 | + with: |
| 32 | + registry: ${{ env.REGISTRY }} |
| 33 | + username: ${{ github.actor }} |
| 34 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - name: Extract Docker metadata |
| 37 | + id: meta |
| 38 | + uses: docker/metadata-action@57396166ad8aefe6098280995947635806a0e6ea # v4.1.1 |
| 39 | + with: |
| 40 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 41 | + |
| 42 | + - name: Build and push Docker image |
| 43 | + id: build-and-push |
| 44 | + uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # v3.2.0 |
| 45 | + with: |
| 46 | + context: . |
| 47 | + push: ${{ github.event_name != 'pull_request' }} |
| 48 | + tags: ${{ steps.meta.outputs.tags }} |
| 49 | + labels: ${{ steps.meta.outputs.labels }} |
| 50 | + |
| 51 | + # Sign the Docker image |
| 52 | + - name: Install cosign |
| 53 | + if: github.event_name != 'pull_request' |
| 54 | + uses: sigstore/cosign-installer@9becc617647dfa20ae7b1151972e9b3a2c338a2b #v2.8.1 |
| 55 | + - name: Sign the published Docker image |
| 56 | + if: github.event_name != 'pull_request' |
| 57 | + env: |
| 58 | + COSIGN_EXPERIMENTAL: "true" |
| 59 | + run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }} |
0 commit comments