build-container-image.yml 3.1 KB

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