docker-publish.yml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. name: Publish Docker Image
  2. on:
  3. release:
  4. types: [published]
  5. workflow_dispatch:
  6. inputs:
  7. tag:
  8. description: 'Tag to build and publish'
  9. required: true
  10. default: 'latest'
  11. env:
  12. REGISTRY: docker.io
  13. IMAGE_NAME: thesimplekid/cdk-mintd
  14. jobs:
  15. build-and-push:
  16. runs-on: ubuntu-latest
  17. permissions:
  18. contents: read
  19. packages: write
  20. steps:
  21. - name: Checkout repository
  22. uses: actions/checkout@v4
  23. - name: Set up Docker Buildx
  24. uses: docker/setup-buildx-action@v3
  25. - name: Login to Docker Hub
  26. uses: docker/login-action@v3
  27. with:
  28. username: ${{ secrets.DOCKERHUB_USERNAME }}
  29. password: ${{ secrets.DOCKERHUB_TOKEN }}
  30. - name: Extract metadata (tags, labels) for Docker
  31. id: meta
  32. uses: docker/metadata-action@v5
  33. with:
  34. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  35. tags: |
  36. type=raw,value=latest,enable=${{ github.event_name == 'release' }}
  37. type=semver,pattern={{version}}
  38. type=semver,pattern={{major}}.{{minor}}
  39. type=ref,event=branch
  40. type=ref,event=pr
  41. type=sha
  42. ${{ github.event.inputs.tag != '' && github.event.inputs.tag || '' }}
  43. - name: Build and push Docker image
  44. uses: docker/build-push-action@v5
  45. with:
  46. context: .
  47. push: true
  48. platforms: linux/amd64,linux/arm64
  49. tags: ${{ steps.meta.outputs.tags }}
  50. labels: ${{ steps.meta.outputs.labels }}
  51. cache-from: type=gha
  52. cache-to: type=gha,mode=max