builder-image.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. name: Builder Image
  2. on:
  3. schedule:
  4. - cron: "0 3 * * 1" # Every Monday at 3 AM
  5. push:
  6. paths:
  7. - "ci.Dockerfile"
  8. - ".github/workflows/builder-image.yml"
  9. env:
  10. REGISTRY_IMAGE: jguer/yay-builder
  11. jobs:
  12. build:
  13. runs-on: ubuntu-latest
  14. strategy:
  15. fail-fast: false
  16. matrix:
  17. platform:
  18. - linux/amd64
  19. - linux/arm/v7
  20. - linux/arm64
  21. steps:
  22. - name: Checkout repository
  23. uses: actions/checkout@v4
  24. - name: Set up QEMU
  25. uses: docker/setup-qemu-action@v3
  26. - name: Set up Docker Buildx
  27. uses: docker/setup-buildx-action@v3
  28. - name: Login to Docker Hub
  29. uses: docker/login-action@v3
  30. with:
  31. username: ${{ secrets.DOCKERHUB_USERNAME }}
  32. password: ${{ secrets.DOCKERHUB_TOKEN }}
  33. - name: Login to GitHub Container Registry
  34. uses: docker/login-action@v3
  35. with:
  36. registry: ghcr.io
  37. username: ${{ github.repository_owner }}
  38. password: ${{ secrets.GITHUB_TOKEN }}
  39. - name: Extract metadata for Docker
  40. id: meta
  41. uses: docker/metadata-action@v5
  42. with:
  43. images: |
  44. ${{ env.REGISTRY_IMAGE }}
  45. ghcr.io/${{ env.REGISTRY_IMAGE }}
  46. tags: |
  47. type=raw,value=latest
  48. type=sha,format=long
  49. - name: Build and push by digest
  50. id: build
  51. uses: docker/build-push-action@v5
  52. with:
  53. context: .
  54. file: ci.Dockerfile
  55. platforms: ${{ matrix.platform }}
  56. labels: ${{ steps.meta.outputs.labels }}
  57. outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
  58. - name: Export digest
  59. run: |
  60. mkdir -p /tmp/digests
  61. digest="${{ steps.build.outputs.digest }}"
  62. echo -n "$digest" > "/tmp/digests/$(echo "${{ matrix.platform }}" | tr '/' '_')"
  63. - name: Upload digest
  64. uses: actions/upload-artifact@v4
  65. with:
  66. name: digest-${{ matrix.platform == 'linux/amd64' && 'amd64' || matrix.platform == 'linux/arm/v7' && 'armv7' || 'arm64' }}
  67. path: /tmp/digests/*
  68. if-no-files-found: error
  69. retention-days: 1
  70. merge:
  71. needs: [build]
  72. runs-on: ubuntu-latest
  73. steps:
  74. - name: Download digests
  75. uses: actions/download-artifact@v4
  76. with:
  77. pattern: digest-*
  78. merge-multiple: true
  79. path: /tmp/digests
  80. - name: Set up Docker Buildx
  81. uses: docker/setup-buildx-action@v3
  82. - name: Login to Docker Hub
  83. uses: docker/login-action@v3
  84. with:
  85. username: ${{ secrets.DOCKERHUB_USERNAME }}
  86. password: ${{ secrets.DOCKERHUB_TOKEN }}
  87. - name: Login to GitHub Container Registry
  88. uses: docker/login-action@v3
  89. with:
  90. registry: ghcr.io
  91. username: ${{ github.repository_owner }}
  92. password: ${{ secrets.GITHUB_TOKEN }}
  93. - name: Extract metadata for Docker
  94. id: meta
  95. uses: docker/metadata-action@v5
  96. with:
  97. images: |
  98. ${{ env.REGISTRY_IMAGE }}
  99. ghcr.io/${{ env.REGISTRY_IMAGE }}
  100. tags: |
  101. type=raw,value=latest
  102. type=sha,format=long
  103. - name: Create and push manifest list
  104. env:
  105. DOCKER_CLI_EXPERIMENTAL: enabled
  106. run: |
  107. # Extract tags
  108. TAGS=$(echo '${{ steps.meta.outputs.tags }}' | xargs -I {} echo "-t {}")
  109. # Create a manifest list using the image digests from /tmp/digests/*
  110. DIGESTS=$(for file in /tmp/digests/*; do
  111. echo -n "${{ env.REGISTRY_IMAGE }}@$(cat $file) "
  112. done)
  113. # Create the manifest list with the collected tags and digests
  114. docker buildx imagetools create $TAGS $DIGESTS
  115. # Push to GitHub Container Registry
  116. GHCR_TAGS=$(echo '${{ steps.meta.outputs.tags }}' | sed 's|^|ghcr.io/${{ env.REGISTRY_IMAGE }}:|g' | xargs -I {} echo "-t {}")
  117. docker buildx imagetools create $GHCR_TAGS $DIGESTS
  118. - name: Inspect image
  119. run: |
  120. docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}