docker-publish.yml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. # Publish semver tags as releases.
  9. tags: [ 'v*.*.*' ]
  10. env:
  11. # Use docker.io for Docker Hub if empty
  12. REGISTRY: docker.io
  13. # github.repository as <account>/<repo>
  14. IMAGE_NAME: byaidu/pdf2zh
  15. jobs:
  16. build:
  17. runs-on: ubuntu-latest
  18. permissions:
  19. contents: read
  20. packages: write
  21. # This is used to complete the identity challenge
  22. # with sigstore/fulcio when running outside of PRs.
  23. id-token: write
  24. steps:
  25. - name: Checkout repository
  26. uses: actions/checkout@v4
  27. # Install the cosign tool except on PR
  28. # https://github.com/sigstore/cosign-installer
  29. # Set up BuildKit Docker container builder to be able to build
  30. # multi-platform images and export cache
  31. # https://github.com/docker/setup-buildx-action
  32. - name: Set up Docker Buildx
  33. uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
  34. # Login against a Docker registry except on PR
  35. # https://github.com/docker/login-action
  36. - name: Log into registry ${{ env.REGISTRY }}
  37. if: github.event_name != 'pull_request'
  38. uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
  39. with:
  40. registry: ${{ env.REGISTRY }}
  41. username: ${{ secrets.DOCKER_USERNAME }}
  42. password: ${{ secrets.DOCKER_PASSWORD }}
  43. # Extract metadata (tags, labels) for Docker
  44. # https://github.com/docker/metadata-action
  45. - name: Extract Docker metadata
  46. id: meta
  47. uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
  48. with:
  49. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  50. # Build and push Docker image with Buildx (don't push on PR)
  51. # https://github.com/docker/build-push-action
  52. - name: Build and push Docker image
  53. id: build-and-push
  54. uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
  55. with:
  56. context: .
  57. push: ${{ github.event_name != 'pull_request' }}
  58. tags: ${{ steps.meta.outputs.tags }}
  59. labels: ${{ steps.meta.outputs.labels }}
  60. cache-from: type=gha
  61. cache-to: type=gha,mode=max