@cryptotaxi247 / kubo / commits / 6f08cdedc

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 https://github.com/ipfs/bifrost-gateway/commit/14cfa48bed514fb8b865d41df3cecb5f827e54ab and reduced build time from 20m to 3m.

Marcin Rataj committed Apr 6, 2023 at 20:53 UTC 6f08cdedc0c79424d487407a591a88697060b2ea
2 files changed +25 -3
.github/workflows/docker-image.yml
+17
@@ -31,6 +31,14 @@ jobs:
31 - name: Set up Docker Buildx
32 uses: docker/setup-buildx-action@v1
33
34 + - name: Cache Docker layers
35 + uses: actions/cache@v3
36 + with:
37 + path: /tmp/.buildx-cache
38 + key: ${{ runner.os }}-buildx-${{ github.sha }}
39 + restore-keys: |
40 + ${{ runner.os }}-buildx-
41 +
42 - name: Get tags
43 id: tags
44 run: |
@@ -53,3 +61,12 @@ jobs:
61 push: true
62 file: ./Dockerfile
63 tags: "${{ steps.tags.outputs.value }}"
64 + cache-from: type=local,src=/tmp/.buildx-cache
65 + cache-to: type=local,dest=/tmp/.buildx-cache-new
66 +
67 + # https://github.com/docker/build-push-action/issues/252
68 + # https://github.com/moby/buildkit/issues/1896
69 + - name: Move cache to limit growth
70 + run: |
71 + rm -rf /tmp/.buildx-cache
72 + mv /tmp/.buildx-cache-new /tmp/.buildx-cache
Dockerfile
+8 -3
@@ -1,6 +1,11 @@
1 -FROM golang:1.19.1-buster
1 +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.19.1-buster
2 LABEL maintainer="Steven Allen <steven@stebalien.com>"
3
4 +ARG TARGETPLATFORM
5 +ARG BUILDPLATFORM
6 +ARG TARGETOS
7 +ARG TARGETARCH
8 +
9 # Install deps
10 RUN apt-get update && apt-get install -y \
11 libssl-dev \
@@ -24,7 +29,7 @@ ARG IPFS_PLUGINS
29 # Also: fix getting HEAD commit hash via git rev-parse.
30 RUN cd $SRC_DIR \
31 && mkdir -p .git/objects \
27 - && GOFLAGS=-buildvcs=false make build GOTAGS=openssl IPFS_PLUGINS=$IPFS_PLUGINS
32 + && GOOS=$TARGETOS GOARCH=$TARGETARCH GOFLAGS=-buildvcs=false make build GOTAGS=openssl IPFS_PLUGINS=$IPFS_PLUGINS
33
34 # Get su-exec, a very minimal tool for dropping privileges,
35 # and tini, a very minimal init daemon for containers
@@ -46,7 +51,7 @@ RUN set -eux; \
51 && chmod +x tini
52
53 # Now comes the actual target image, which aims to be as small as possible.
49 -FROM busybox:1.31.1-glibc
54 +FROM --platform=${BUILDPLATFORM:-linux/amd64} busybox:1.31.1-glibc
55 LABEL maintainer="Steven Allen <steven@stebalien.com>"
56
57 # Get the ipfs binary, entrypoint script, and TLS CAs from the build container.