From 790a548eb921db63732cd1baad744005e6060e65 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 6 Apr 2023 14:20:50 +0200 Subject: [PATCH] fix(ci): speed up docker build trying two things: - speed up arm build by allowing cross-comp from go instead of slow QEMU - take a stab at caching buildx layers, without infinite growth This fix was laready applied in https://github.com/ipfs/bifrost-gateway/commit/14cfa48bed514fb8b865d41df3cecb5f827e54ab and reduced build time from 20m to 3m. --- .github/workflows/docker-image.yml | 17 +++++++++++++++++ Dockerfile | 11 ++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 47c3754405e..520e3783380 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -31,6 +31,14 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Get tags id: tags run: | @@ -53,3 +61,12 @@ jobs: push: true file: ./Dockerfile tags: "${{ steps.tags.outputs.value }}" + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + - name: Move cache to limit growth + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/Dockerfile b/Dockerfile index 57e65071050..a252bc997d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,11 @@ -FROM golang:1.19.1-buster +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.19.1-buster LABEL maintainer="Steven Allen " +ARG TARGETPLATFORM +ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH + # Install deps RUN apt-get update && apt-get install -y \ libssl-dev \ @@ -24,7 +29,7 @@ ARG IPFS_PLUGINS # Also: fix getting HEAD commit hash via git rev-parse. RUN cd $SRC_DIR \ && mkdir -p .git/objects \ - && GOFLAGS=-buildvcs=false make build GOTAGS=openssl IPFS_PLUGINS=$IPFS_PLUGINS + && GOOS=$TARGETOS GOARCH=$TARGETARCH GOFLAGS=-buildvcs=false make build GOTAGS=openssl IPFS_PLUGINS=$IPFS_PLUGINS # Get su-exec, a very minimal tool for dropping privileges, # and tini, a very minimal init daemon for containers @@ -46,7 +51,7 @@ RUN set -eux; \ && chmod +x tini # Now comes the actual target image, which aims to be as small as possible. -FROM busybox:1.31.1-glibc +FROM --platform=${BUILDPLATFORM:-linux/amd64} busybox:1.31.1-glibc LABEL maintainer="Steven Allen " # Get the ipfs binary, entrypoint script, and TLS CAs from the build container.