docker-publish.yml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. name: Docker
  2. # This workflow uses actions that are not certified by GitHub.
  3. # They are provided by a third-party and are governed by
  4. # separate terms of service, privacy policy, and support
  5. # documentation.
  6. on:
  7. push:
  8. branches: [ "master" ]
  9. pull_request:
  10. branches: [ "master" ]
  11. env:
  12. # Use docker.io for Docker Hub if empty
  13. REGISTRY: ghcr.io
  14. # github.repository as <account>/<repo>
  15. IMAGE_NAME: ${{ github.repository }}
  16. jobs:
  17. build:
  18. runs-on: ubuntu-latest
  19. permissions:
  20. contents: read
  21. packages: write
  22. # This is used to complete the identity challenge
  23. # with sigstore/fulcio when running outside of PRs.
  24. id-token: write
  25. steps:
  26. - name: Checkout repository
  27. uses: actions/checkout@v3
  28. # Install the cosign tool except on PR
  29. # https://github.com/sigstore/cosign-installer
  30. - name: Install cosign
  31. if: github.event_name != 'pull_request'
  32. uses: sigstore/cosign-installer@v3
  33. - name: Setup Docker buildx
  34. uses: docker/setup-buildx-action@v2
  35. # Login against a Docker registry except on PR
  36. # https://github.com/docker/login-action
  37. - name: Log into registry ${{ env.REGISTRY }}
  38. if: github.event_name != 'pull_request'
  39. uses: docker/login-action@v2
  40. with:
  41. registry: ${{ env.REGISTRY }}
  42. username: ${{ github.actor }}
  43. password: ${{ secrets.GITHUB_TOKEN }}
  44. # Extract metadata (tags, labels) for Docker
  45. # https://github.com/docker/metadata-action
  46. - name: Extract Docker metadata
  47. id: meta
  48. uses: docker/metadata-action@v4
  49. with:
  50. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  51. # Build and push Docker image with Buildx (don't push on PR)
  52. # https://github.com/docker/build-push-action
  53. - name: Build and push Docker image
  54. id: build-and-push
  55. uses: docker/build-push-action@v4
  56. with:
  57. file: ./contrib/docker/Dockerfile
  58. push: ${{ github.event_name != 'pull_request' }}
  59. tags: ${{ steps.meta.outputs.tags }}
  60. labels: ${{ steps.meta.outputs.labels }}
  61. cache-from: type=gha
  62. cache-to: type=gha,mode=max
  63. # Sign the resulting Docker image digest except on PRs.
  64. # This will only write to the public Rekor transparency log when the Docker
  65. # repository is public to avoid leaking data. If you would like to publish
  66. # transparency data even for private images, pass --force to cosign below.
  67. # https://github.com/sigstore/cosign
  68. - name: Sign the published Docker image
  69. if: ${{ github.event_name != 'pull_request' }}
  70. # This step uses the identity token to provision an ephemeral certificate
  71. # against the sigstore community Fulcio instance.
  72. run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push.outputs.digest }}