|
1 | 1 | name: ftl-build builds |
2 | 2 | on: |
3 | | - pull_request: |
4 | | - paths: |
5 | | - - 'ftl-build/**' |
6 | | - - '.github/workflows/ftl-build.yml' |
7 | 3 | push: |
| 4 | + # Run on all branches and tags, but only if the ftl-build directory or the |
| 5 | + # workflow itself changed. This is to avoid running the workflow on |
| 6 | + # unrelated changes. |
| 7 | + # Note that including the branch filter is necessary as otherwise (paths and tags alone), |
| 8 | + # the workflow would not run on pushes to branches that do not have a tag sticked to them. |
8 | 9 | tags: |
9 | 10 | - "**" |
| 11 | + branches: |
| 12 | + - "**" |
10 | 13 | paths: |
11 | 14 | - 'ftl-build/**' |
12 | 15 | - '.github/workflows/ftl-build.yml' |
|
15 | 18 | # 1:30am UTC every Sunday, has no particular significance |
16 | 19 | - cron: "30 1 * * 0" |
17 | 20 |
|
| 21 | +env: |
| 22 | + DOCKER_REGISTRY_IMAGE: ${{ secrets.DOCKERHUB_NAMESPACE }}/ftl-build |
| 23 | + GITHUB_REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/ftl-build |
| 24 | + |
18 | 25 | jobs: |
19 | | - build: |
| 26 | + build-and-test: |
20 | 27 | runs-on: ubuntu-latest |
21 | 28 | strategy: |
22 | 29 | fail-fast: false |
23 | 30 | matrix: |
24 | | - ARCH: [aarch64, armv4t, armv5te, armv6hf, armv7hf, armv8a, x86_32, x86_64, x86_64-musl, riscv64] |
| 31 | + include: |
| 32 | + - platform: linux/amd64 |
| 33 | + container: alpine:3.18 |
| 34 | + - platform: linux/386 |
| 35 | + container: alpine:3.18 |
| 36 | + - platform: linux/arm/v5 |
| 37 | + container: debian:stretch-slim |
| 38 | + - platform: linux/arm/v6 |
| 39 | + container: debian:bullseye-slim |
| 40 | + - platform: linux/arm/v6 |
| 41 | + container: alpine:3.18 |
| 42 | + - platform: linux/arm/v7 |
| 43 | + container: alpine:3.18 |
| 44 | + - platform: linux/arm64/v8 |
| 45 | + container: alpine:3.18 |
| 46 | + - platform: linux/riscv64 |
| 47 | + container: alpine:edge |
| 48 | + env: |
| 49 | + context: ${{ startsWith(matrix.container, 'alpine') && 'alpine' || 'debian' }} |
25 | 50 | steps: |
26 | 51 | - |
27 | 52 | name: Checkout Repo |
28 | 53 | uses: actions/checkout@v3 |
29 | 54 | - |
30 | | - name: Set up Docker Buildx |
31 | | - uses: docker/setup-buildx-action@v2 |
32 | | - - |
33 | | - name: Docker meta |
| 55 | + name: Docker meta (Docker Hub and GitHub Container Registry) |
34 | 56 | id: meta |
35 | 57 | uses: docker/metadata-action@v4 |
36 | 58 | with: |
| 59 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
37 | 60 | images: | |
38 | | - ${{ secrets.DOCKERHUB_NAMESPACE }}/ftl-build,enable=${{ github.event_name != 'pull_request' }} |
39 | | - ghcr.io/${{ github.repository_owner }}/ftl-build,enable=${{ github.event_name != 'pull_request' }} |
40 | | - foo/bar,enable=${{ github.event_name == 'pull_request' }} |
41 | | - flavor: | |
42 | | - latest=false |
| 61 | + ${{ env.DOCKER_REGISTRY_IMAGE }},enable=${{ github.event_name != 'workflow_dispatch' }} |
| 62 | + ${{ env.GITHUB_REGISTRY_IMAGE }},enable=${{ github.event_name != 'workflow_dispatch' }} |
| 63 | + foo/bar,enable=${{ github.event_name == 'workflow_dispatch' }} |
43 | 64 | tags: | |
44 | | - type=ref,event=tag,suffix=-${{ matrix.ARCH }} |
45 | | - type=ref,event=branch,suffix=-${{ matrix.ARCH }},enable=${{ github.event_name != 'schedule' }} |
46 | | - type=ref,event=pr,suffix=-${{ matrix.ARCH }} |
47 | | - type=raw,value=${{matrix.ARCH}},enable=${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'schedule' }} |
48 | | - - |
49 | | - name: Login to DockerHub |
50 | | - if: github.event_name != 'pull_request' |
51 | | - uses: docker/login-action@v2 |
| 65 | + type=ref,event=branch,enable=${{ github.event_name != 'schedule' }} |
| 66 | + - |
| 67 | + name: Login to DockerHub and GitHub Container Registry |
| 68 | + uses: ./.github/actions/login-repo |
52 | 69 | with: |
53 | | - username: ${{ secrets.DOCKERHUB_USER }} |
54 | | - password: ${{ secrets.DOCKERHUB_PASS }} |
| 70 | + docker_username: ${{ secrets.DOCKERHUB_USER }} |
| 71 | + docker_password: ${{ secrets.DOCKERHUB_PASS }} |
| 72 | + ghcr_username: ${{ github.repository_owner }} |
| 73 | + ghcr_password: ${{ secrets.GITHUB_TOKEN }} |
55 | 74 | - |
56 | | - name: Login to GitHub Container Registry |
57 | | - if: github.event_name != 'pull_request' |
58 | | - uses: docker/login-action@v2 |
| 75 | + # Add support for more platforms with QEMU (optional) |
| 76 | + # https://github.com/docker/setup-qemu-action |
| 77 | + name: Set up QEMU |
| 78 | + uses: docker/setup-qemu-action@v2 |
59 | 79 | with: |
60 | | - registry: ghcr.io |
61 | | - username: ${{ github.repository_owner }} |
62 | | - password: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + platforms: all |
| 81 | + - |
| 82 | + name: Set up Docker Buildx |
| 83 | + uses: docker/setup-buildx-action@v2 |
63 | 84 | - |
64 | | - name: Build |
| 85 | + name: Build container and test-compile FTL |
65 | 86 | uses: docker/build-push-action@v4 |
66 | 87 | with: |
67 | | - context: ftl-build/${{ matrix.ARCH }}/. |
| 88 | + context: ftl-build/${{ env.context }} |
| 89 | + platforms: ${{ matrix.platform }} |
68 | 90 | push: false |
69 | 91 | target: tester |
70 | 92 | tags: ${{ steps.meta.outputs.tags }} |
71 | 93 | labels: ${{ steps.meta.outputs.labels }} |
72 | | - # Caching disabled for now... |
73 | | - # cache-from: type=gha,scope=${{ matrix.ARCH }} |
74 | | - # cache-to: type=gha,scope=${{ matrix.ARCH }},mode=max |
| 94 | + build-args: | |
| 95 | + CONTAINER=${{ matrix.container }} |
75 | 96 | - |
76 | | - name: Build (all-in) |
77 | | - if: matrix.ARCH == 'x86_64' |
| 97 | + name: Push builder target and push by digest (Docker Hub) |
| 98 | + id: build_docker |
78 | 99 | uses: docker/build-push-action@v4 |
79 | 100 | with: |
80 | | - context: ftl-build/${{ matrix.ARCH }}/. |
81 | | - push: false |
82 | | - target: tester-all-in |
83 | | - tags: ${{ steps.meta.outputs.tags }} |
| 101 | + context: ftl-build/${{ env.context }} |
| 102 | + platforms: ${{ matrix.platform }} |
| 103 | + push: ${{ github.event_name != 'workflow_dispatch' }} |
| 104 | + target: builder |
84 | 105 | labels: ${{ steps.meta.outputs.labels }} |
| 106 | + build-args: | |
| 107 | + CONTAINER=${{ matrix.container }} |
| 108 | + outputs: | |
| 109 | + type=image,name=${{ env.DOCKER_REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
85 | 110 | - |
86 | | - name: Push |
87 | | - if: github.event_name != 'pull_request' |
| 111 | + name: Push builder target and push by digest (GitHub Container Registry) |
| 112 | + id: build_ghcr |
88 | 113 | uses: docker/build-push-action@v4 |
89 | 114 | with: |
90 | | - context: ftl-build/${{ matrix.ARCH }}/. |
91 | | - push: true |
| 115 | + context: ftl-build/${{ env.context }} |
| 116 | + platforms: ${{ matrix.platform }} |
| 117 | + push: ${{ github.event_name != 'workflow_dispatch' }} |
92 | 118 | target: builder |
93 | | - tags: ${{ steps.meta.outputs.tags }} |
94 | 119 | labels: ${{ steps.meta.outputs.labels }} |
95 | | - # Caching disabled for now... |
96 | | - # cache-from: type=gha,scope=${{ matrix.ARCH }} |
97 | | - # cache-to: type=gha,scope=${{ matrix.ARCH }},mode=max |
| 120 | + build-args: | |
| 121 | + CONTAINER=${{ matrix.container }} |
| 122 | + outputs: | |
| 123 | + type=image,name=${{ env.GITHUB_REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 124 | + - |
| 125 | + name: Export digests |
| 126 | + run: | |
| 127 | + mkdir -p /tmp/digests/dockerhub/${{ env.context }} |
| 128 | + mkdir -p /tmp/digests/ghcr/${{ env.context }} |
| 129 | + digest_docker="${{ steps.build_docker.outputs.digest }}" |
| 130 | + touch "/tmp/digests/dockerhub/${{ env.context }}/${digest_docker#sha256:}" |
| 131 | + digest_ghcr="${{ steps.build_ghcr.outputs.digest }}" |
| 132 | + touch "/tmp/digests/ghcr/${{ env.context }}/${digest_ghcr#sha256:}" |
| 133 | + - |
| 134 | + name: Upload digest |
| 135 | + uses: actions/upload-artifact@v3 |
| 136 | + with: |
| 137 | + name: digests |
| 138 | + path: /tmp/digests/* |
| 139 | + if-no-files-found: error |
| 140 | + retention-days: 1 |
| 141 | + |
| 142 | + # Merge all the digests into a single file |
| 143 | + # If we would push immediately above, the individual runners would overwrite each other's images |
| 144 | + # https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners |
| 145 | + merge-and-deploy: |
| 146 | + runs-on: ubuntu-latest |
| 147 | + needs: |
| 148 | + - build-and-test |
| 149 | + steps: |
| 150 | + - |
| 151 | + name: Checkout Repo |
| 152 | + uses: actions/checkout@v3 |
| 153 | + - |
| 154 | + name: Download digests |
| 155 | + uses: actions/download-artifact@v3 |
| 156 | + with: |
| 157 | + name: digests |
| 158 | + path: /tmp/digests |
| 159 | + - |
| 160 | + name: Set up Docker Buildx |
| 161 | + uses: docker/setup-buildx-action@v2 |
| 162 | + - |
| 163 | + name: Login to DockerHub and GitHub Container Registry |
| 164 | + uses: ./.github/actions/login-repo |
| 165 | + with: |
| 166 | + docker_username: ${{ secrets.DOCKERHUB_USER }} |
| 167 | + docker_password: ${{ secrets.DOCKERHUB_PASS }} |
| 168 | + ghcr_username: ${{ github.repository_owner }} |
| 169 | + ghcr_password: ${{ secrets.GITHUB_TOKEN }} |
| 170 | + - |
| 171 | + name: Collect and push (Alpine, Docker Hub) |
| 172 | + uses: ./.github/actions/merge-and-push |
| 173 | + with: |
| 174 | + imagename: ${{ env.DOCKER_REGISTRY_IMAGE }} |
| 175 | + platform: alpine |
| 176 | + registry: dockerhub |
| 177 | + - |
| 178 | + name: Collect and push (Debian, Docker Hub) |
| 179 | + uses: ./.github/actions/merge-and-push |
| 180 | + with: |
| 181 | + imagename: ${{ env.DOCKER_REGISTRY_IMAGE }} |
| 182 | + platform: debian |
| 183 | + registry: dockerhub |
| 184 | + - |
| 185 | + name: Collect and push (Alpine, GitHub Container Registry) |
| 186 | + uses: ./.github/actions/merge-and-push |
| 187 | + with: |
| 188 | + imagename: ${{ env.GITHUB_REGISTRY_IMAGE }} |
| 189 | + platform: alpine |
| 190 | + registry: ghcr |
| 191 | + - |
| 192 | + name: Collect and push (Debian, GitHub Container Registry) |
| 193 | + uses: ./.github/actions/merge-and-push |
| 194 | + with: |
| 195 | + imagename: ${{ env.GITHUB_REGISTRY_IMAGE }} |
| 196 | + platform: debian |
| 197 | + registry: ghcr |
0 commit comments