From 9854a2e01cc154eb834e7e7399cd4cbbceb49f62 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Thu, 7 Nov 2024 08:16:43 +0100 Subject: [PATCH] Use multi-arch Docker images (#93) --- .github/workflows/build.yml | 58 +++++++++++++++++++++++-------------- Dockerfile | 56 +++++++++++++++++++++-------------- Makefile | 9 ++++-- go.mod | 4 +-- 4 files changed, 78 insertions(+), 49 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 116071e..be449a3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,8 +17,8 @@ on: jobs: docker: - name: Docker - timeout-minutes: 20 + name: Docker (${{ matrix.branch }}) + timeout-minutes: 50 strategy: fail-fast: false @@ -29,7 +29,6 @@ jobs: - master - release-branch.go1.23 - release-branch.go1.22 - - release-branch.go1.21 runs-on: ${{ matrix.os }} @@ -43,45 +42,54 @@ jobs: - name: Setup QEMU uses: docker/setup-qemu-action@v3 + - name: Login into Docker registries + if: github.event_name != 'pull_request' + run: | + docker login --username aleksi --password ${{ secrets.DOCKERHUB_TOKEN }} + docker login ghcr.io --username aleksi --password ${{ secrets.GITHUB_TOKEN }} + - name: Start BuildKit builder run: make docker-up - - name: Build Docker images + - name: Build Docker images for PR + if: github.event_name == 'pull_request' run: make docker-build - # skip push for PRs - # move to `publish` job - # TODO https://github.com/AlekSi/golang-tip/issues/8 - - - name: Login into Docker registries + - name: Build Docker images for Docker Hub if: github.event_name != 'pull_request' - run: | - docker login --username aleksi --password ${{ secrets.DOCKERHUB_TOKEN }} - docker login ghcr.io --username aleksi --password ${{ secrets.GITHUB_TOKEN }} + run: make docker-build + env: + DOCKER_PLATFORM: linux/amd64,linux/arm64 + DOCKER_OUTPUT: type=image,push=true + DOCKER_TAG: aleksi/golang-tip:${{ env.GO_BRANCH }} - - name: Upload Docker images + - name: Build Docker images for ghcr.io if: github.event_name != 'pull_request' - run: | - docker tag golang-tip:${{ env.GO_BRANCH }} aleksi/golang-tip:${{ env.GO_BRANCH }} - docker tag golang-tip:${{ env.GO_BRANCH }} ghcr.io/aleksi/golang-tip:${{ env.GO_BRANCH }} - docker push aleksi/golang-tip:${{ env.GO_BRANCH }} - docker push ghcr.io/aleksi/golang-tip:${{ env.GO_BRANCH }} + run: make docker-build + env: + DOCKER_PLATFORM: linux/amd64,linux/arm64 + DOCKER_OUTPUT: type=image,push=true + DOCKER_TAG: ghcr.io/aleksi/golang-tip:${{ env.GO_BRANCH }} + + # skip push for PRs + # move to `publish` job + # TODO https://github.com/AlekSi/golang-tip/issues/8 targz: - name: TarGz - timeout-minutes: 20 + name: TarGz (${{ matrix.branch }}, ${{ matrix.os }}, ${{ matrix.goroot }}) + timeout-minutes: 10 strategy: fail-fast: false matrix: os: - ubuntu-22.04 - - macos-12 + - macos-13 + - macos-15 branch: - master - release-branch.go1.23 - release-branch.go1.22 - - release-branch.go1.21 goroot: - /usr/local/go - /tmp/golang-tip @@ -96,6 +104,12 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: false + - name: Build .tar.gz file run: make targz-build diff --git a/Dockerfile b/Dockerfile index 485ebb8..8b84135 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,51 @@ -FROM golang:1.22.6 +# syntax=docker/dockerfile:1 + +ARG GO_BRANCH + + +FROM --platform=$BUILDPLATFORM golang:1.23.2 AS prepare RUN git clone https://go.googlesource.com/go /tmp/golang-tip -# make sure that following steps are not cached; -# mostly for local testing, not for GitHub Actions -ARG CACHEBUST=1 -RUN echo "$CACHEBUST" + +FROM golang:1.23.2 ARG GO_BRANCH -RUN test -n "$GO_BRANCH" ENV GOLANG_VERSION=${GO_BRANCH} -RUN cd /tmp/golang-tip && \ - git reset --hard && \ - git clean -xdf && \ - git remote prune origin && \ - git checkout "$GO_BRANCH" && \ - git pull +COPY --from=prepare /tmp/golang-tip /tmp/golang-tip + +RUN <