Skip to content

Commit 9236902

Browse files
cursoragentmsukkari
andcommitted
chore(docker): speed up builds with BuildKit caches
Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
1 parent afbe045 commit 9236902

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

.github/workflows/pr-gate.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ jobs:
1717
with:
1818
submodules: "true"
1919

20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
2023
- name: Build Docker image
2124
id: build
2225
uses: docker/build-push-action@v6
2326
with:
2427
context: .
28+
cache-from: type=gha,scope=pr-gate
29+
cache-to: type=gha,mode=max,scope=pr-gate

Dockerfile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# syntax=docker/dockerfile:1
1+
# syntax=docker/dockerfile:1.7
22
# ------ Global scope variables ------
33

44
# Set of global build arguments.
@@ -24,9 +24,13 @@ FROM go-alpine AS zoekt-builder
2424
RUN apk add --no-cache ca-certificates
2525
WORKDIR /zoekt
2626
COPY vendor/zoekt/go.mod vendor/zoekt/go.sum ./
27-
RUN go mod download
27+
RUN --mount=type=cache,id=sourcebot-go-mod-cache,target=/go/pkg/mod \
28+
--mount=type=cache,id=sourcebot-go-build-cache,target=/root/.cache/go-build \
29+
go mod download
2830
COPY vendor/zoekt ./
29-
RUN CGO_ENABLED=0 GOOS=linux go build -o /cmd/ ./cmd/...
31+
RUN --mount=type=cache,id=sourcebot-go-mod-cache,target=/go/pkg/mod \
32+
--mount=type=cache,id=sourcebot-go-build-cache,target=/root/.cache/go-build \
33+
CGO_ENABLED=0 GOOS=linux go build -o /cmd/ ./cmd/...
3034
# -------------------------
3135

3236
# ------ Build shared libraries ------
@@ -40,10 +44,14 @@ COPY ./packages/schemas ./packages/schemas
4044
COPY ./packages/shared ./packages/shared
4145
COPY ./packages/queryLanguage ./packages/queryLanguage
4246

43-
RUN yarn workspace @sourcebot/db install
44-
RUN yarn workspace @sourcebot/schemas install
45-
RUN yarn workspace @sourcebot/shared install
46-
RUN yarn workspace @sourcebot/query-language install
47+
RUN --mount=type=cache,id=sourcebot-yarn-cache,target=/app/.yarn/cache \
48+
yarn workspace @sourcebot/db install
49+
RUN --mount=type=cache,id=sourcebot-yarn-cache,target=/app/.yarn/cache \
50+
yarn workspace @sourcebot/schemas install
51+
RUN --mount=type=cache,id=sourcebot-yarn-cache,target=/app/.yarn/cache \
52+
yarn workspace @sourcebot/shared install
53+
RUN --mount=type=cache,id=sourcebot-yarn-cache,target=/app/.yarn/cache \
54+
yarn workspace @sourcebot/query-language install
4755
# ------------------------------------
4856

4957
# ------ Build Web ------
@@ -89,7 +97,8 @@ COPY --from=shared-libs-builder /app/packages/shared ./packages/shared
8997
COPY --from=shared-libs-builder /app/packages/queryLanguage ./packages/queryLanguage
9098

9199
# Fixes arm64 timeouts
92-
RUN yarn workspace @sourcebot/web install
100+
RUN --mount=type=cache,id=sourcebot-yarn-cache,target=/app/.yarn/cache \
101+
yarn workspace @sourcebot/web install
93102

94103
ENV NEXT_TELEMETRY_DISABLED=1
95104
RUN yarn workspace @sourcebot/web build
@@ -126,7 +135,8 @@ COPY --from=shared-libs-builder /app/packages/db ./packages/db
126135
COPY --from=shared-libs-builder /app/packages/schemas ./packages/schemas
127136
COPY --from=shared-libs-builder /app/packages/shared ./packages/shared
128137
COPY --from=shared-libs-builder /app/packages/queryLanguage ./packages/queryLanguage
129-
RUN yarn workspace @sourcebot/backend install
138+
RUN --mount=type=cache,id=sourcebot-yarn-cache,target=/app/.yarn/cache \
139+
yarn workspace @sourcebot/backend install
130140
RUN yarn workspace @sourcebot/backend build
131141

132142
# Upload source maps to Sentry if we have the necessary build-time args.

0 commit comments

Comments
 (0)