docker-publish.yml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. name: Publish Docker Image AMD64
  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: cashubtc/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. # Build and push AMD64 image with architecture suffix
  44. - name: Build and push Docker image
  45. uses: docker/build-push-action@v5
  46. with:
  47. context: .
  48. push: true
  49. platforms: linux/amd64
  50. tags: ${{ steps.meta.outputs.tags }}-amd64
  51. labels: ${{ steps.meta.outputs.labels }}
  52. cache-from: type=gha
  53. cache-to: type=gha,mode=max
  54. # Create and push multi-arch manifest if both images exist
  55. - name: Create and push multi-arch manifest
  56. run: |
  57. # For each tag in the metadata output
  58. echo "${{ steps.meta.outputs.tags }}" | while read -r tag; do
  59. # Check if ARM64 image exists
  60. if docker manifest inspect $tag-arm64 >/dev/null 2>&1; then
  61. # Create manifest
  62. docker manifest create $tag \
  63. $tag-amd64 \
  64. $tag-arm64
  65. # Annotate the manifest with architecture specific information
  66. docker manifest annotate $tag $tag-amd64 --arch amd64
  67. docker manifest annotate $tag $tag-arm64 --arch arm64
  68. # Push the manifest
  69. docker manifest push $tag
  70. else
  71. echo "ARM64 image not found for $tag, skipping manifest creation"
  72. fi
  73. done