docker.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. name: Docker
  2. on:
  3. push:
  4. branches: ["master"]
  5. tags: ["docker/*"]
  6. pull_request:
  7. branches: ["master"]
  8. schedule:
  9. - cron: "13 13 * * 3"
  10. concurrency:
  11. group: ${{ github.workflow }}-${{ github.ref }}
  12. cancel-in-progress: true
  13. jobs:
  14. ############
  15. # Building #
  16. ############
  17. build:
  18. strategy:
  19. fail-fast: false
  20. matrix:
  21. dist: ["alpine", "debian"]
  22. arch:
  23. - amd64
  24. - arm32v6
  25. - arm32v7
  26. - arm64v8
  27. - i386
  28. - ppc64le
  29. - s390x
  30. runs-on: ubuntu-latest
  31. steps:
  32. - uses: actions/checkout@v6
  33. with:
  34. fetch-depth: 0 # for correct image labeling via `git describe --tags`
  35. # TODO: Try remove once `moby/buildkit` image upgrades its default QEMU version.
  36. - uses: docker/setup-qemu-action@v3
  37. - uses: docker/setup-buildx-action@v3
  38. - name: Detect correct Git ref for image build
  39. id: git
  40. uses: actions/github-script@v8
  41. with:
  42. script: |
  43. let out = {ref: 'HEAD', ver: ''};
  44. if ('${{ github.ref }}'.startsWith('refs/tags/docker/')) {
  45. out.ref = '${{ github.ref }}'.substring(17).split('-')[0];
  46. out.ver = out.ref;
  47. }
  48. return out;
  49. - name: Verify Git ref matches Makefile version
  50. run: |
  51. test "${{ fromJSON(steps.git.outputs.result).ref }}" \
  52. == "$(grep -m1 'COTURN_VER ?=' Makefile | cut -d'=' -f2 | tr -d ' ')"
  53. working-directory: docker/coturn/
  54. if: ${{ github.event_name == 'push'
  55. && startsWith(github.ref, 'refs/tags/docker/') }}
  56. - run: make docker.image no-cache=yes
  57. dockerfile=${{ matrix.dist }}
  58. platform=linux/${{ matrix.arch }}
  59. ref=${{ fromJSON(steps.git.outputs.result).ref }}
  60. tag=build-${{ github.run_number }}-${{ matrix.dist }}-${{ matrix.arch }}
  61. working-directory: docker/coturn/
  62. - run: make docker.tar to-file=.cache/image.tar
  63. tags=build-${{ github.run_number }}-${{ matrix.dist }}-${{ matrix.arch }}
  64. working-directory: docker/coturn/
  65. - uses: actions/upload-artifact@v6
  66. with:
  67. name: ${{ matrix.dist }}-${{ matrix.arch }}-${{ github.run_number }}
  68. path: docker/coturn/.cache/image.tar
  69. retention-days: 1
  70. ###########
  71. # Testing #
  72. ###########
  73. changelog:
  74. if: ${{ github.event_name == 'push'
  75. && (startsWith(github.ref, 'refs/tags/')
  76. || github.ref == 'refs/heads/master') }}
  77. runs-on: ubuntu-latest
  78. steps:
  79. - uses: actions/checkout@v6
  80. if: ${{ startsWith(github.ref, 'refs/tags/') }}
  81. - name: Parse semver versions from Git tag
  82. id: semver
  83. uses: actions-ecosystem/action-regex-match@v2
  84. with:
  85. text: ${{ github.ref }}
  86. regex: '^refs/tags/docker/(((([0-9]+)\.[0-9]+)\.[0-9]+)-(.+))$'
  87. if: ${{ startsWith(github.ref, 'refs/tags/') }}
  88. - name: Ensure CHANGELOG date is today
  89. run: |
  90. today="$(date '+%Y-%m-%d')"
  91. changelog="$(grep -E '^## \[${{ steps.semver.outputs.group1 }}\] ·' \
  92. CHANGELOG.md \
  93. | cut -d' ' -f4 | tr -d ' ')"
  94. echo "Changelog: $changelog"
  95. echo "Today: $today"
  96. [ "$changelog" = "$today" ]
  97. working-directory: docker/coturn/
  98. if: ${{ startsWith(github.ref, 'refs/tags/') }}
  99. test:
  100. needs: ["build"]
  101. strategy:
  102. fail-fast: false
  103. matrix:
  104. dist: ["alpine", "debian"]
  105. arch:
  106. - amd64
  107. - arm32v6
  108. - arm32v7
  109. - arm64v8
  110. - i386
  111. - ppc64le
  112. - s390x
  113. # TODO: Try remove on new QEMU or Coturn versions.
  114. # Temporarily exclude `alpine` on `s390x` arch, as QEMU emulation
  115. # currently times out and fails the CI.
  116. exclude:
  117. - dist: alpine
  118. arch: s390x
  119. runs-on: ubuntu-latest
  120. steps:
  121. - uses: actions/checkout@v6
  122. - uses: docker/setup-qemu-action@v3
  123. - run: make npm.install
  124. working-directory: docker/coturn/
  125. - name: Detect correct Git version for image tests
  126. id: git
  127. uses: actions/github-script@v8
  128. with:
  129. script: |
  130. let out = {ref: 'HEAD', ver: ''};
  131. if ('${{ github.ref }}'.startsWith('refs/tags/docker/')) {
  132. out.ref = '${{ github.ref }}'.substring(17).split('-')[0];
  133. out.ver = out.ref;
  134. }
  135. return out;
  136. - uses: actions/download-artifact@v7
  137. with:
  138. name: ${{ matrix.dist }}-${{ matrix.arch }}-${{ github.run_number }}
  139. path: docker/coturn/.cache/
  140. - run: make docker.untar from-file=.cache/image.tar
  141. working-directory: docker/coturn/
  142. - run: make test.docker
  143. platform=linux/${{ matrix.arch }}
  144. tag=build-${{ github.run_number }}-${{ matrix.dist }}-${{ matrix.arch }}
  145. env:
  146. COTURN_VERSION: ${{ fromJSON(steps.git.outputs.result).ver }}
  147. working-directory: docker/coturn/
  148. #############
  149. # Releasing #
  150. #############
  151. push:
  152. if: ${{ github.event_name == 'push'
  153. && github.repository_owner == 'coturn'
  154. && (startsWith(github.ref, 'refs/tags/')
  155. || github.ref == 'refs/heads/master') }}
  156. needs: ["build", "changelog", "test"]
  157. strategy:
  158. fail-fast: false
  159. max-parallel: 1
  160. matrix:
  161. registry: ["docker.io", "ghcr.io", "quay.io"]
  162. dist: ["alpine", "debian"]
  163. runs-on: ubuntu-latest
  164. steps:
  165. - uses: actions/checkout@v6
  166. - name: Parse Docker image name from Git repository name
  167. id: image
  168. uses: actions-ecosystem/action-regex-match@v2
  169. with:
  170. text: ${{ github.repository }}
  171. regex: '^${{ github.repository_owner }}/(.+)$'
  172. - name: Parse semver versions from Git tag
  173. id: semver
  174. uses: actions-ecosystem/action-regex-match@v2
  175. with:
  176. text: ${{ github.ref }}
  177. regex: '^refs/tags/docker/(((([0-9]+)\.[0-9]+)\.[0-9]+)-(.+))$'
  178. if: ${{ startsWith(github.ref, 'refs/tags/') }}
  179. - name: Form main Docker image tag
  180. id: docker
  181. run: echo "tag=${{ (startsWith(github.ref, 'refs/tags/')
  182. && steps.semver.outputs.group1)
  183. || 'edge' }}-${{ matrix.dist }}"
  184. >> $GITHUB_OUTPUT
  185. - uses: actions/download-artifact@v7
  186. with:
  187. path: docker/coturn/.cache/
  188. - name: Login to ${{ matrix.registry }} container registry
  189. uses: docker/login-action@v3
  190. with:
  191. registry: ${{ matrix.registry }}
  192. username: ${{ (matrix.registry == 'docker.io'
  193. && secrets.DOCKERHUB_BOT_USER)
  194. || (matrix.registry == 'quay.io'
  195. && secrets.QUAYIO_ROBOT_USERNAME)
  196. || github.repository_owner }}
  197. password: ${{ (matrix.registry == 'docker.io'
  198. && secrets.DOCKERHUB_BOT_PASS)
  199. || (matrix.registry == 'quay.io'
  200. && secrets.QUAYIO_ROBOT_TOKEN)
  201. || secrets.GITHUB_TOKEN }}
  202. - name: Tag and push single-platform images
  203. run: |
  204. for arch in amd64 \
  205. arm32v6 \
  206. arm32v7 \
  207. arm64v8 \
  208. i386 \
  209. ppc64le \
  210. s390x
  211. do
  212. make docker.untar \
  213. from-file=.cache/${{ matrix.dist }}-$arch-${{ github.run_number }}/image.tar
  214. make docker.tags \
  215. of=build-${{ github.run_number }}-${{ matrix.dist }}-$arch \
  216. tags=${{ steps.docker.outputs.tag }}-$arch \
  217. registries=${{ matrix.registry }}
  218. make docker.push \
  219. tags=${{ steps.docker.outputs.tag }}-$arch \
  220. registries=${{ matrix.registry }}
  221. done
  222. working-directory: docker/coturn/
  223. - name: Tag and push multi-platform images
  224. run: make docker.manifest push=yes
  225. registries=${{ matrix.registry }}
  226. of='${{ steps.docker.outputs.tag }}-amd64
  227. ${{ steps.docker.outputs.tag }}-arm32v6
  228. ${{ steps.docker.outputs.tag }}-arm32v7
  229. ${{ steps.docker.outputs.tag }}-arm64v8
  230. ${{ steps.docker.outputs.tag }}-i386
  231. ${{ steps.docker.outputs.tag }}-ppc64le
  232. ${{ steps.docker.outputs.tag }}-s390x'
  233. tags=${{ (!startsWith(github.ref, 'refs/tags/')
  234. && steps.docker.outputs.tag)
  235. || '' }}
  236. env:
  237. DOCKERFILE: ${{ matrix.dist }} # for correct `tags` auto-detection
  238. working-directory: docker/coturn/
  239. # On GitHub Container Registry README is automatically updated on pushes.
  240. - name: Update README on Docker Hub
  241. uses: christian-korneck/update-container-description-action@v1
  242. with:
  243. provider: dockerhub
  244. destination_container_repo: ${{ github.repository_owner }}/${{ steps.image.outputs.group1 }}
  245. readme_file: docker/coturn/README.md
  246. env:
  247. DOCKER_USER: ${{ secrets.DOCKERHUB_BOT_USER }}
  248. DOCKER_PASS: ${{ secrets.DOCKERHUB_BOT_PASS }}
  249. if: ${{ startsWith(github.ref, 'refs/tags/')
  250. && matrix.registry == 'docker.io' }}
  251. - name: Update README on Quay.io
  252. uses: christian-korneck/update-container-description-action@v1
  253. with:
  254. provider: quay
  255. destination_container_repo: ${{ matrix.registry }}/${{ github.repository_owner }}/${{ steps.image.outputs.group1 }}
  256. readme_file: docker/coturn/README.md
  257. env:
  258. DOCKER_APIKEY: ${{ secrets.QUAYIO_API_TOKEN }}
  259. if: ${{ startsWith(github.ref, 'refs/tags/')
  260. && matrix.registry == 'quay.io' }}
  261. release-github:
  262. name: release (GitHub)
  263. if: ${{ github.event_name == 'push'
  264. && github.repository_owner == 'coturn'
  265. && startsWith(github.ref, 'refs/tags/') }}
  266. needs: ["push"]
  267. runs-on: ubuntu-latest
  268. steps:
  269. - uses: actions/checkout@v6
  270. - name: Parse semver versions from Git tag
  271. id: semver
  272. uses: actions-ecosystem/action-regex-match@v2
  273. with:
  274. text: ${{ github.ref }}
  275. regex: '^refs/tags/docker/(((([0-9]+)\.[0-9]+)\.[0-9]+)-(.+))$'
  276. - name: Parse CHANGELOG link
  277. id: changelog
  278. run: echo "link=${{ github.server_url }}/${{ github.repository }}/blob/docker/${{ steps.semver.outputs.group1 }}/docker/coturn/CHANGELOG.md#$(sed -n '/^## \[${{ steps.semver.outputs.group1 }}\]/{s/^## \[\(.*\)\][^0-9]*\([0-9].*\)/\1--\2/;s/[^0-9a-z-]*//g;p;}' CHANGELOG.md)"
  279. >> $GITHUB_OUTPUT
  280. working-directory: docker/coturn/
  281. - name: Create GitHub release
  282. uses: softprops/action-gh-release@v2
  283. with:
  284. name: docker/${{ steps.semver.outputs.group1 }}
  285. body: |
  286. `${{ steps.semver.outputs.group1 }}` Docker image version of ${{ steps.semver.outputs.group2 }} Coturn release.
  287. [Docker Hub](https://hub.docker.com/r/coturn/coturn) | [GitHub Container Registry](https://github.com/orgs/coturn/packages/container/package/coturn) | [Quay.io](https://quay.io/repository/coturn/coturn)
  288. [Changelog](${{ steps.changelog.outputs.link }})