docker-publish.yml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. schedule:
  8. - cron: '28 23 * * *'
  9. push:
  10. branches: [ main ]
  11. # Publish semver tags as releases.
  12. tags: [ 'v*.*.*' ]
  13. pull_request:
  14. branches: [ main ]
  15. env:
  16. # Use docker.io for Docker Hub if empty
  17. REGISTRY: ghcr.io
  18. # github.repository as <account>/<repo>
  19. IMAGE_NAME: ${{ github.repository }}
  20. jobs:
  21. build:
  22. runs-on: ubuntu-latest
  23. permissions:
  24. contents: read
  25. packages: write
  26. steps:
  27. - name: Checkout repository
  28. uses: actions/checkout@v4
  29. # Login against a Docker registry except on PR
  30. # https://github.com/docker/login-action
  31. - name: Log into registry ${{ env.REGISTRY }}
  32. if: github.event_name != 'pull_request'
  33. uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
  34. with:
  35. registry: ${{ env.REGISTRY }}
  36. username: ${{ github.actor }}
  37. password: ${{ secrets.GITHUB_TOKEN }}
  38. # Extract metadata (tags, labels) for Docker
  39. # https://github.com/docker/metadata-action
  40. - name: Extract Docker metadata
  41. id: meta
  42. uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
  43. with:
  44. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  45. # Build and push Docker image with Buildx (don't push on PR)
  46. # https://github.com/docker/build-push-action
  47. - name: Build and push Docker image
  48. uses: docker/build-push-action@a254f8ca60a858f3136a2f1f23a60969f2c402dd
  49. with:
  50. context: .
  51. push: ${{ github.event_name != 'pull_request' }}
  52. tags: ${{ steps.meta.outputs.tags }}
  53. labels: ${{ steps.meta.outputs.labels }}