build-container-image.yml 3.4 KB

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