build-and-push.yaml 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. name: Build and Push
  2. on: push
  3. env:
  4. registry: ghcr.io
  5. image-name: ${{ github.repository }}
  6. jobs:
  7. build-and-push:
  8. runs-on: ubuntu-latest
  9. permissions:
  10. contents: read
  11. packages: write
  12. steps:
  13. - name: Checkout Repository
  14. uses: actions/checkout@v3
  15. - name: Set up Docker Buildx
  16. uses: docker/setup-buildx-action@v2
  17. - name: Determine tags
  18. id: metadata
  19. uses: docker/metadata-action@v4
  20. with:
  21. images: ${{ env.registry }}/${{ env.image-name }}
  22. tags: |
  23. type=sha,prefix=,format=long
  24. type=schedule
  25. type=ref,event=branch
  26. type=ref,event=pr
  27. type=raw,value=latest,enable={{ is_default_branch }}
  28. - name: Log in to the Container registry
  29. uses: docker/login-action@v2.1.0
  30. with:
  31. registry: ${{ env.registry }}
  32. username: ${{ github.actor }}
  33. password: ${{ secrets.GITHUB_TOKEN }}
  34. - name: Build and push ${{ env.image-name }}
  35. uses: docker/build-push-action@v3
  36. with:
  37. push: true
  38. tags: ${{ steps.metadata.outputs.tags }}
  39. labels: ${{ steps.metadata.outputs.labels }}
  40. cache-from: type=gha
  41. cache-to: type=gha,mode=max
  42. concurrency:
  43. group: ${{ github.ref }}
  44. cancel-in-progress: true