build-container-image.yml 3.0 KB

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