docker.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. name: Publish Docker Images
  2. on:
  3. release:
  4. types:
  5. - published
  6. workflow_dispatch:
  7. inputs:
  8. tag:
  9. description: "The tag version you want to build"
  10. env:
  11. REGISTRY_IMAGE: ghcr.io/sagernet/sing-box
  12. jobs:
  13. build:
  14. runs-on: ubuntu-latest
  15. strategy:
  16. fail-fast: true
  17. matrix:
  18. platform:
  19. - linux/amd64
  20. - linux/arm/v6
  21. - linux/arm/v7
  22. - linux/arm64
  23. - linux/386
  24. - linux/ppc64le
  25. - linux/riscv64
  26. - linux/s390x
  27. steps:
  28. - name: Get commit to build
  29. id: ref
  30. run: |-
  31. if [[ -z "${{ github.event.inputs.tag }}" ]]; then
  32. ref="${{ github.ref_name }}"
  33. else
  34. ref="${{ github.event.inputs.tag }}"
  35. fi
  36. echo "ref=$ref"
  37. echo "ref=$ref" >> $GITHUB_OUTPUT
  38. - name: Checkout
  39. uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
  40. with:
  41. ref: ${{ steps.ref.outputs.ref }}
  42. fetch-depth: 0
  43. - name: Prepare
  44. run: |
  45. platform=${{ matrix.platform }}
  46. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  47. - name: Setup QEMU
  48. uses: docker/setup-qemu-action@v3
  49. - name: Setup Docker Buildx
  50. uses: docker/setup-buildx-action@v3
  51. - name: Login to GitHub Container Registry
  52. uses: docker/login-action@v3
  53. with:
  54. registry: ghcr.io
  55. username: ${{ github.repository_owner }}
  56. password: ${{ secrets.GITHUB_TOKEN }}
  57. - name: Docker meta
  58. id: meta
  59. uses: docker/metadata-action@v5
  60. with:
  61. images: ${{ env.REGISTRY_IMAGE }}
  62. - name: Build and push by digest
  63. id: build
  64. uses: docker/build-push-action@v6
  65. with:
  66. platforms: ${{ matrix.platform }}
  67. context: .
  68. build-args: |
  69. BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
  70. labels: ${{ steps.meta.outputs.labels }}
  71. outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
  72. - name: Export digest
  73. run: |
  74. mkdir -p /tmp/digests
  75. digest="${{ steps.build.outputs.digest }}"
  76. touch "/tmp/digests/${digest#sha256:}"
  77. - name: Upload digest
  78. uses: actions/upload-artifact@v4
  79. with:
  80. name: digests-${{ env.PLATFORM_PAIR }}
  81. path: /tmp/digests/*
  82. if-no-files-found: error
  83. retention-days: 1
  84. merge:
  85. runs-on: ubuntu-latest
  86. needs:
  87. - build
  88. steps:
  89. - name: Get commit to build
  90. id: ref
  91. run: |-
  92. if [[ -z "${{ github.event.inputs.tag }}" ]]; then
  93. ref="${{ github.ref_name }}"
  94. else
  95. ref="${{ github.event.inputs.tag }}"
  96. fi
  97. echo "ref=$ref"
  98. echo "ref=$ref" >> $GITHUB_OUTPUT
  99. if [[ $ref == *"-"* ]]; then
  100. latest=latest-beta
  101. else
  102. latest=latest
  103. fi
  104. echo "latest=$latest"
  105. echo "latest=$latest" >> $GITHUB_OUTPUT
  106. - name: Download digests
  107. uses: actions/download-artifact@v5
  108. with:
  109. path: /tmp/digests
  110. pattern: digests-*
  111. merge-multiple: true
  112. - name: Set up Docker Buildx
  113. uses: docker/setup-buildx-action@v3
  114. - name: Login to GitHub Container Registry
  115. uses: docker/login-action@v3
  116. with:
  117. registry: ghcr.io
  118. username: ${{ github.repository_owner }}
  119. password: ${{ secrets.GITHUB_TOKEN }}
  120. - name: Create manifest list and push
  121. working-directory: /tmp/digests
  122. run: |
  123. docker buildx imagetools create \
  124. -t "${{ env.REGISTRY_IMAGE }}:${{ steps.ref.outputs.latest }}" \
  125. -t "${{ env.REGISTRY_IMAGE }}:${{ steps.ref.outputs.ref }}" \
  126. $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
  127. - name: Inspect image
  128. run: |
  129. docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.ref.outputs.latest }}
  130. docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.ref.outputs.ref }}