Skip to content

ci: improve caching in Dockerfiles even more #4485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion gitops-server.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ RUN ssh-keyscan gitlab.com >> ~/.ssh/known_hosts

COPY Makefile /app/
WORKDIR /app
RUN go env -w GOCACHE=/go-cache
RUN --mount=type=cache,target=/gomod-cache \
go env -w GOMODCACHE=/gomod-cache
COPY go.* /app/
RUN go mod download
COPY core /app/core
Expand All @@ -39,7 +42,8 @@ COPY api /app/api
ARG GIT_COMMIT="_unset_"
ARG LDFLAGS="-X localbuild=true"

RUN --mount=type=cache,target=/root/.cache/go-build LDFLAGS=${LDFLAGS##-X localbuild=true} GIT_COMMIT=$GIT_COMMIT make gitops-server
RUN --mount=type=cache,target=/gomod-cache --mount=type=cache,target=/go-cache \
LDFLAGS=${LDFLAGS##-X localbuild=true} GIT_COMMIT=$GIT_COMMIT make gitops-server

# Distroless
FROM gcr.io/distroless/base@sha256:e9d0321de8927f69ce20e39bfc061343cce395996dfc1f0db6540e5145bc63a5 AS runtime
Expand Down
8 changes: 6 additions & 2 deletions gitops.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ RUN ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
COPY Makefile /app/
COPY tools /app/tools
WORKDIR /app
RUN go env -w GOCACHE=/go-cache
RUN go env -w GOMODCACHE=/gomod-cache
COPY go.* /app/
RUN go mod download
RUN --mount=type=cache,target=/gomod-cache \
go mod download
COPY . /app

# These are ARGS are defined here to minimise cache misses
Expand All @@ -25,7 +28,8 @@ COPY . /app
ARG LDFLAGS="-X localbuild=true"
ARG GIT_COMMIT="_unset_"

RUN LDFLAGS=$LDFLAGS GIT_COMMIT=$GIT_COMMIT make gitops
RUN --mount=type=cache,target=/gomod-cache --mount=type=cache,target=/go-cache \
LDFLAGS=$LDFLAGS GIT_COMMIT=$GIT_COMMIT make gitops

# Distroless
FROM gcr.io/distroless/base@sha256:e9d0321de8927f69ce20e39bfc061343cce395996dfc1f0db6540e5145bc63a5 AS runtime
Expand Down
Loading