|
| 1 | +name: docker-publish |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '32 11 * * *' |
| 6 | + push: |
| 7 | + branches: [ "main" ] |
| 8 | + # Publish semver tags as releases. |
| 9 | + tags: [ 'v*.*.*' ] |
| 10 | + pull_request: |
| 11 | + branches: [ "main" ] |
| 12 | + |
| 13 | +env: |
| 14 | + # Use docker.io for Docker Hub if empty |
| 15 | + REGISTRY: ghcr.io |
| 16 | + # github.repository as <account>/<repo> |
| 17 | + IMAGE_NAME: ${{ github.repository }} |
| 18 | + |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + packages: write |
| 27 | + # This is used to complete the identity challenge |
| 28 | + # with sigstore/fulcio when running outside of PRs. |
| 29 | + id-token: write |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v3 |
| 34 | + |
| 35 | + # Install the cosign tool except on PR |
| 36 | + # https://github.com/sigstore/cosign-installer |
| 37 | + - name: Install cosign |
| 38 | + if: github.event_name != 'pull_request' |
| 39 | + uses: sigstore/cosign-installer@b3413d484cc23cf8778c3d2aa361568d4eb54679 |
| 40 | + with: |
| 41 | + cosign-release: 'v1.9.0' |
| 42 | + |
| 43 | + |
| 44 | + # Workaround: https://github.com/docker/build-push-action/issues/461 |
| 45 | + - name: Setup Docker buildx |
| 46 | + uses: docker/setup-buildx-action@dc7b9719a96d48369863986a06765841d7ea23f6 |
| 47 | + |
| 48 | + # Login against a Docker registry except on PR |
| 49 | + # https://github.com/docker/login-action |
| 50 | + - name: Log into registry ${{ env.REGISTRY }} |
| 51 | + if: github.event_name != 'pull_request' |
| 52 | + uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b |
| 53 | + with: |
| 54 | + registry: ${{ env.REGISTRY }} |
| 55 | + username: ${{ github.actor }} |
| 56 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + # Extract metadata (tags, labels) for Docker |
| 59 | + # https://github.com/docker/metadata-action |
| 60 | + - name: Extract Docker metadata |
| 61 | + id: meta |
| 62 | + uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a |
| 63 | + with: |
| 64 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 65 | + |
| 66 | + # Build and push Docker image with Buildx (don't push on PR) |
| 67 | + # https://github.com/docker/build-push-action |
| 68 | + - name: Build and push Docker image |
| 69 | + id: build-and-push |
| 70 | + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a |
| 71 | + with: |
| 72 | + context: . |
| 73 | + push: ${{ github.event_name != 'pull_request' }} |
| 74 | + tags: ${{ steps.meta.outputs.tags }} |
| 75 | + labels: ${{ steps.meta.outputs.labels }} |
| 76 | + |
| 77 | + # Sign the resulting Docker image digest except on PRs. |
| 78 | + # This will only write to the public Rekor transparency log when the Docker |
| 79 | + # repository is public to avoid leaking data. If you would like to publish |
| 80 | + # transparency data even for private images, pass --force to cosign below. |
| 81 | + # https://github.com/sigstore/cosign |
| 82 | + - name: Sign the published Docker image |
| 83 | + if: ${{ github.event_name != 'pull_request' }} |
| 84 | + env: |
| 85 | + COSIGN_EXPERIMENTAL: "true" |
| 86 | + # This step uses the identity token to provision an ephemeral certificate |
| 87 | + # against the sigstore community Fulcio instance. |
| 88 | + run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }} |
0 commit comments