build-docker.yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. name: Docker
  2. on:
  3. push:
  4. paths-ignore:
  5. - "README.md"
  6. branches:
  7. - master
  8. env:
  9. IMAGE: zedeus/nitter
  10. jobs:
  11. tests:
  12. uses: ./.github/workflows/run-tests.yml
  13. secrets: inherit
  14. # Build each architecture natively (no emulation) and push by digest only.
  15. # The digests are stitched into a single multi-arch tag by the merge job.
  16. build:
  17. needs: [tests]
  18. strategy:
  19. fail-fast: false
  20. matrix:
  21. include:
  22. - runner: ubuntu-24.04
  23. platform: linux/amd64
  24. - runner: ubuntu-24.04-arm
  25. platform: linux/arm64
  26. runs-on: ${{ matrix.runner }}
  27. steps:
  28. - name: Prepare platform name
  29. run: echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV"
  30. env:
  31. platform: ${{ matrix.platform }}
  32. - uses: actions/checkout@v6
  33. - name: Set up Docker Buildx
  34. uses: docker/setup-buildx-action@v3
  35. with:
  36. version: latest
  37. - name: Login to DockerHub
  38. uses: docker/login-action@v3
  39. with:
  40. username: ${{ secrets.DOCKER_USERNAME }}
  41. password: ${{ secrets.DOCKER_PASSWORD }}
  42. - name: Build and push by digest
  43. id: build
  44. uses: docker/build-push-action@v6
  45. with:
  46. context: .
  47. file: ./Dockerfile
  48. platforms: ${{ matrix.platform }}
  49. outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
  50. # Attestations turn a single-platform push into a manifest index, which
  51. # breaks push-by-digest + the imagetools merge below. Disable them.
  52. provenance: false
  53. sbom: false
  54. - name: Export digest
  55. run: |
  56. mkdir -p "${{ runner.temp }}/digests"
  57. digest="${{ steps.build.outputs.digest }}"
  58. touch "${{ runner.temp }}/digests/${digest#sha256:}"
  59. - name: Upload digest
  60. uses: actions/upload-artifact@v4
  61. with:
  62. name: digests-${{ env.PLATFORM_PAIR }}
  63. path: ${{ runner.temp }}/digests/*
  64. if-no-files-found: error
  65. retention-days: 1
  66. # Combine the per-arch digests into one multi-arch manifest so that
  67. # `docker pull zedeus/nitter:latest` serves the right image on any CPU.
  68. merge:
  69. needs: [build]
  70. runs-on: ubuntu-24.04
  71. steps:
  72. - name: Download digests
  73. uses: actions/download-artifact@v4
  74. with:
  75. path: ${{ runner.temp }}/digests
  76. pattern: digests-*
  77. merge-multiple: true
  78. - name: Set up Docker Buildx
  79. uses: docker/setup-buildx-action@v3
  80. with:
  81. version: latest
  82. - name: Login to DockerHub
  83. uses: docker/login-action@v3
  84. with:
  85. username: ${{ secrets.DOCKER_USERNAME }}
  86. password: ${{ secrets.DOCKER_PASSWORD }}
  87. - name: Create manifest list and push
  88. working-directory: ${{ runner.temp }}/digests
  89. run: |
  90. # latest-arm64 is a backward-compat alias of the (now multi-arch)
  91. # latest tag, for users still pinned to the old ARM64-only image.
  92. # word splitting is intentional: one image ref arg per digest file
  93. # shellcheck disable=SC2046
  94. docker buildx imagetools create \
  95. -t ${{ env.IMAGE }}:latest \
  96. -t ${{ env.IMAGE }}:latest-arm64 \
  97. -t ${{ env.IMAGE }}:${{ github.sha }} \
  98. $(printf '${{ env.IMAGE }}@sha256:%s ' *)
  99. - name: Inspect image
  100. run: docker buildx imagetools inspect ${{ env.IMAGE }}:${{ github.sha }}