Skip to content

Commit 6f08cde

Browse files
authored
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 ipfs-inactive/bifrost-gateway@14cfa48 and reduced build time from 20m to 3m.
1 parent c6a59c9 commit 6f08cde

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

.github/workflows/docker-image.yml

+17
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ jobs:
3131
- name: Set up Docker Buildx
3232
uses: docker/setup-buildx-action@v1
3333

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+
3442
- name: Get tags
3543
id: tags
3644
run: |
@@ -53,3 +61,12 @@ jobs:
5361
push: true
5462
file: ./Dockerfile
5563
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
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
FROM golang:1.19.1-buster
1+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.19.1-buster
22
LABEL maintainer="Steven Allen <steven@stebalien.com>"
33

4+
ARG TARGETPLATFORM
5+
ARG BUILDPLATFORM
6+
ARG TARGETOS
7+
ARG TARGETARCH
8+
49
# Install deps
510
RUN apt-get update && apt-get install -y \
611
libssl-dev \
@@ -24,7 +29,7 @@ ARG IPFS_PLUGINS
2429
# Also: fix getting HEAD commit hash via git rev-parse.
2530
RUN cd $SRC_DIR \
2631
&& 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
2833

2934
# Get su-exec, a very minimal tool for dropping privileges,
3035
# and tini, a very minimal init daemon for containers
@@ -46,7 +51,7 @@ RUN set -eux; \
4651
&& chmod +x tini
4752

4853
# 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
5055
LABEL maintainer="Steven Allen <steven@stebalien.com>"
5156

5257
# Get the ipfs binary, entrypoint script, and TLS CAs from the build container.

0 commit comments

Comments
 (0)