Skip to content

Commit 7eef4bf

Browse files
authored
Build Cache Optimization (#1402)
* don't copy if we mount the files anyway * use newer alpine version * cache apk pkgs * changeing workdir is not needed in ziggoimg * cache some more * preload go modules
1 parent ca74978 commit 7eef4bf

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

.github/workflows/makefile.yml

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ jobs:
5555
with:
5656
go-version-file: go.mod
5757

58+
- name: Download dependencies
59+
run: go mod download
60+
if: matrix.go == true
61+
5862
- name: Set up Docker Buildx
5963
uses: docker/setup-buildx-action@v3
6064
if: matrix.docker == true

Dockerfile

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
# ----------- stage: ca-certs
44
# get newest certificates in seperate stage for caching
5-
FROM --platform=$BUILDPLATFORM alpine:3.16 AS ca-certs
6-
RUN apk add --no-cache ca-certificates
5+
FROM --platform=$BUILDPLATFORM alpine:3 AS ca-certs
6+
RUN --mount=type=cache,target=/var/cache/apk \
7+
apk update && \
8+
apk add ca-certificates
79

810
# update certificates and use the apk ones if update fails
911
RUN --mount=type=cache,target=/etc/ssl/certs \
@@ -16,17 +18,15 @@ FROM --platform=$BUILDPLATFORM ghcr.io/kwitsch/ziggoimg AS build
1618
ARG VERSION
1719
ARG BUILD_TIME
1820

19-
# set working directory
20-
WORKDIR /go/src
21-
2221
# download packages
23-
COPY go.mod go.sum ./
24-
RUN --mount=type=cache,target=/go/pkg \
22+
# bind mount go.mod and go.sum
23+
# use cache for go packages
24+
RUN --mount=type=bind,source=go.sum,target=go.sum \
25+
--mount=type=bind,source=go.mod,target=go.mod \
26+
--mount=type=cache,target=/root/.cache/go-build \
27+
--mount=type=cache,target=/go/pkg \
2528
go mod download
2629

27-
# add source
28-
COPY . .
29-
3030
# setup go
3131
ENV GO_SKIP_GENERATE=1\
3232
GO_BUILD_FLAGS="-tags static -v " \
@@ -35,6 +35,8 @@ ENV GO_SKIP_GENERATE=1\
3535
BIN_OUT_DIR="/bin"
3636

3737
# build binary
38+
# bind mount source code
39+
# use cache for go packages
3840
RUN --mount=type=bind,target=. \
3941
--mount=type=cache,target=/root/.cache/go-build \
4042
--mount=type=cache,target=/go/pkg \

0 commit comments

Comments
 (0)