fix(ci): speed up docker build (#9800)

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
14cfa48bed
and reduced build time from 20m to 3m.
This commit is contained in:
Marcin Rataj 2023-04-06 20:53:52 +02:00 committed by GitHub
parent c6a59c9cc1
commit 6f08cdedc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -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

View File

@ -1,6 +1,11 @@
FROM golang:1.19.1-buster
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.19.1-buster
LABEL maintainer="Steven Allen <steven@stebalien.com>"
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 <steven@stebalien.com>"
# Get the ipfs binary, entrypoint script, and TLS CAs from the build container.