build-container-image.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. on:
  2. workflow_call:
  3. inputs:
  4. platforms:
  5. required: true
  6. type: string
  7. cache:
  8. type: boolean
  9. default: true
  10. use_native_arm64_builder:
  11. type: boolean
  12. push_to_images:
  13. type: string
  14. version_prerelease:
  15. type: string
  16. version_metadata:
  17. type: string
  18. flavor:
  19. type: string
  20. tags:
  21. type: string
  22. labels:
  23. type: string
  24. jobs:
  25. build-image:
  26. runs-on: ubuntu-latest
  27. steps:
  28. - uses: actions/checkout@v4
  29. - uses: docker/setup-qemu-action@v2
  30. if: contains(inputs.platforms, 'linux/arm64') && !inputs.use_native_arm64_builder
  31. - uses: docker/setup-buildx-action@v2
  32. id: buildx
  33. if: ${{ !(inputs.use_native_arm64_builder && contains(inputs.platforms, 'linux/arm64')) }}
  34. - name: Start a local Docker Builder
  35. if: inputs.use_native_arm64_builder && contains(inputs.platforms, 'linux/arm64')
  36. run: |
  37. docker run --rm -d --name buildkitd -p 1234:1234 --privileged moby/buildkit:latest --addr tcp://0.0.0.0:1234
  38. - uses: docker/setup-buildx-action@v2
  39. id: buildx-native
  40. if: inputs.use_native_arm64_builder && contains(inputs.platforms, 'linux/arm64')
  41. with:
  42. driver: remote
  43. endpoint: tcp://localhost:1234
  44. platforms: linux/amd64
  45. append: |
  46. - endpoint: tcp://${{ vars.DOCKER_BUILDER_HETZNER_ARM64_01_HOST }}:13865
  47. platforms: linux/arm64
  48. name: mastodon-docker-builder-arm64-01
  49. driver-opts:
  50. - servername=mastodon-docker-builder-arm64-01
  51. env:
  52. BUILDER_NODE_1_AUTH_TLS_CACERT: ${{ secrets.DOCKER_BUILDER_HETZNER_ARM64_01_CACERT }}
  53. BUILDER_NODE_1_AUTH_TLS_CERT: ${{ secrets.DOCKER_BUILDER_HETZNER_ARM64_01_CERT }}
  54. BUILDER_NODE_1_AUTH_TLS_KEY: ${{ secrets.DOCKER_BUILDER_HETZNER_ARM64_01_KEY }}
  55. - name: Log in to Docker Hub
  56. if: contains(inputs.push_to_images, 'tootsuite')
  57. uses: docker/login-action@v2
  58. with:
  59. username: ${{ secrets.DOCKERHUB_USERNAME }}
  60. password: ${{ secrets.DOCKERHUB_TOKEN }}
  61. - name: Log in to the Github Container registry
  62. if: contains(inputs.push_to_images, 'ghcr.io')
  63. uses: docker/login-action@v2
  64. with:
  65. registry: ghcr.io
  66. username: ${{ github.actor }}
  67. password: ${{ secrets.GITHUB_TOKEN }}
  68. - uses: docker/metadata-action@v4
  69. id: meta
  70. if: ${{ inputs.push_to_images != '' }}
  71. with:
  72. images: ${{ inputs.push_to_images }}
  73. flavor: ${{ inputs.flavor }}
  74. tags: ${{ inputs.tags }}
  75. labels: ${{ inputs.labels }}
  76. - uses: docker/build-push-action@v4
  77. with:
  78. context: .
  79. build-args: |
  80. MASTODON_VERSION_PRERELEASE=${{ inputs.version_prerelease }}
  81. MASTODON_VERSION_METADATA=${{ inputs.version_metadata }}
  82. platforms: ${{ inputs.platforms }}
  83. provenance: false
  84. builder: ${{ steps.buildx.outputs.name || steps.buildx-native.outputs.name }}
  85. push: ${{ inputs.push_to_images != '' }}
  86. tags: ${{ steps.meta.outputs.tags }}
  87. labels: ${{ steps.meta.outputs.labels }}
  88. cache-from: ${{ inputs.cache && 'type=gha' || '' }}
  89. cache-to: ${{ inputs.cache && 'type=gha,mode=max' || '' }}