Skip to content

Commit d13133d

Browse files
authored
caching docker builds (#2423)
* caching * add cache to workflow * address build error - trying to acces internal * fix build errors: access
1 parent 3090969 commit d13133d

12 files changed

+69
-16
lines changed

.github/workflows/backend-ee-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ jobs:
5959
platforms: linux/amd64,linux/arm64
6060
tags: ${{ steps.docker-meta.outputs.tags }}
6161
labels: ${{ steps.docker-meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max
6264
build-args: |
6365
COMMIT_SHA=${{ github.sha }}
6466
VERSION=${{ steps.meta.outputs.version }}

.github/workflows/drift-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ jobs:
5959
platforms: linux/amd64,linux/arm64
6060
tags: ${{ steps.docker-meta.outputs.tags }}
6161
labels: ${{ steps.docker-meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max
6264
build-args: |
6365
COMMIT_SHA=${{ github.sha }}
6466
VERSION=${{ steps.meta.outputs.version }}

.github/workflows/taco-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ jobs:
187187
platforms: linux/amd64,linux/arm64
188188
tags: ${{ steps.docker-meta.outputs.tags }}
189189
labels: ${{ steps.docker-meta.outputs.labels }}
190+
cache-from: type=gha
191+
cache-to: type=gha,mode=max
190192
build-args: |
191193
COMMIT_SHA=${{ github.sha }}
192194
VERSION=${{ steps.meta.outputs.version }}

.github/workflows/ui-release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ jobs:
6060
platforms: linux/amd64,linux/arm64
6161
tags: ${{ steps.docker-meta.outputs.tags }}
6262
labels: ${{ steps.docker-meta.outputs.labels }}
63+
cache-from: type=gha
64+
cache-to: type=gha,mode=max
6365
build-args: |
6466
COMMIT_SHA=${{ github.sha }}
6567
VERSION=${{ steps.meta.outputs.version }}

Dockerfile_backend

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ RUN echo "commit sha: ${COMMIT_SHA}"
55
# Set the working directory
66
WORKDIR $GOPATH/src/github.com/diggerhq/digger
77

8+
# Copy go.mod/go.sum first for better layer caching
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
812
# Copy all required source, blacklist files that are not required through `.dockerignore`
913
COPY . .
1014

@@ -16,7 +20,9 @@ RUN go version
1620
# https://github.com/ethereum/go-ethereum/issues/2738
1721
# Build static binary "-getmode=vendor" does not work with go-ethereum
1822

19-
RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o backend_exe ./backend/
23+
RUN --mount=type=cache,target=/root/.cache/go-build \
24+
--mount=type=cache,target=/go/pkg/mod \
25+
go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o backend_exe ./backend/
2026

2127
# Multi-stage build will just copy the binary to an alpine image.
2228
FROM ubuntu:24.04 as runner

Dockerfile_backend_ee

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ RUN echo "commit sha: ${COMMIT_SHA}"
55
# Set the working directory
66
WORKDIR $GOPATH/src/github.com/diggerhq/digger
77

8+
# Copy go.mod/go.sum first for better layer caching
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
812
# Copy all required source, blacklist files that are not required through `.dockerignore`
913
COPY . .
1014

@@ -16,7 +20,9 @@ RUN go version
1620
# https://github.com/ethereum/go-ethereum/issues/2738
1721
# Build static binary "-getmode=vendor" does not work with go-ethereum
1822

19-
RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o backend_exe ./ee/backend/
23+
RUN --mount=type=cache,target=/root/.cache/go-build \
24+
--mount=type=cache,target=/go/pkg/mod \
25+
go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o backend_exe ./ee/backend/
2026

2127
# Multi-stage build will just copy the binary to an alpine image.
2228
FROM ubuntu:24.04 as runner

Dockerfile_bg_projects_refresh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ RUN echo "commit sha: ${COMMIT_SHA}"
55
# Set the working directory
66
WORKDIR $GOPATH/src/github.com/diggerhq/digger
77

8+
# Copy go.mod/go.sum first for better layer caching
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
812
# Copy all required source, blacklist files that are not required through `.dockerignore`
913
COPY . .
1014

11-
RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o projects_refresh_exe ./background/projects-refresh-service
15+
RUN --mount=type=cache,target=/root/.cache/go-build \
16+
--mount=type=cache,target=/go/pkg/mod \
17+
go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o projects_refresh_exe ./background/projects-refresh-service
1218

1319
# Multi-stage build will just copy the binary to an alpine image.
1420
FROM ubuntu:24.04 as runner

Dockerfile_drift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ RUN echo "commit sha: ${COMMIT_SHA}"
55
# Set the working directory
66
WORKDIR $GOPATH/src/github.com/diggerhq/digger
77

8+
# Copy go.mod/go.sum first for better layer caching
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
812
# Copy all required source, blacklist files that are not required through `.dockerignore`
913
COPY . .
1014

@@ -16,7 +20,9 @@ RUN go version
1620
# https://github.com/ethereum/go-ethereum/issues/2738
1721
# Build static binary "-getmode=vendor" does not work with go-ethereum
1822

19-
RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o drift_exe ./drift/
23+
RUN --mount=type=cache,target=/root/.cache/go-build \
24+
--mount=type=cache,target=/go/pkg/mod \
25+
go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o drift_exe ./drift/
2026

2127
# Multi-stage build will just copy the binary to an alpine image.
2228
FROM ubuntu:24.04 AS runner

Dockerfile_tasks

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ RUN echo "commit sha: ${COMMIT_SHA}"
55
# Set the working directory
66
WORKDIR $GOPATH/src/github.com/diggerhq/digger
77

8+
# Copy go.mod/go.sum first for better layer caching
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
812
# Copy all required source, blacklist files that are not required through `.dockerignore`
913
COPY . .
1014

@@ -16,7 +20,9 @@ RUN go version
1620
# https://github.com/ethereum/go-ethereum/issues/2738
1721
# Build static binary "-getmode=vendor" does not work with go-ethereum
1822

19-
RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o tasks_exe ./backend/tasks
23+
RUN --mount=type=cache,target=/root/.cache/go-build \
24+
--mount=type=cache,target=/go/pkg/mod \
25+
go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o tasks_exe ./backend/tasks
2026

2127
# Multi-stage build will just copy the binary to an alpine image.
2228
FROM ubuntu:24.04 as runner

Dockerfile_ui

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,33 @@ FROM node:20-alpine AS builder
44
WORKDIR /app
55

66
# Copy package files
7-
COPY ui/package.json ./
7+
COPY ui/package.json ui/package-lock.json ./
88

99
# Install dependencies first
1010
# npm will automatically install correct platform-specific binaries (amd64 or arm64)
11-
RUN npm install && \
11+
RUN --mount=type=cache,target=/root/.npm \
12+
npm ci && \
1213
npm cache clean --force
1314

1415
# Copy source code (node_modules excluded via .dockerignore)
1516
COPY ui/ ./
1617

1718
# Build the application (with node adapter)
18-
RUN npm run build
19+
RUN --mount=type=cache,target=/root/.npm \
20+
npm run build
1921

2022
# Production stage
2123
FROM node:20-alpine
2224

2325
WORKDIR /app
2426

2527
# Copy package file
26-
COPY ui/package.json ./
28+
COPY ui/package.json ui/package-lock.json ./
2729

2830
# Install production dependencies only
2931
# npm will automatically install correct platform-specific binaries (amd64 or arm64)
30-
RUN npm install --omit=dev && \
32+
RUN --mount=type=cache,target=/root/.npm \
33+
npm ci --omit=dev && \
3134
npm cache clean --force
3235

3336
# Copy built application and server entry from builder

0 commit comments

Comments
 (0)