Skip to content

Commit

Permalink
fix(ci): speed up docker build
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lidel committed Apr 6, 2023
1 parent 1958510 commit 790a548
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
FROM golang:1.19.1-buster
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.19.1-buster
LABEL maintainer="Steven Allen <[email protected]>"

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

# Install deps
RUN apt-get update && apt-get install -y \
libssl-dev \
Expand All @@ -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
Expand All @@ -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 <[email protected]>"

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

0 comments on commit 790a548

Please sign in to comment.