diff --git a/.github/workflows/pr-gate.yml b/.github/workflows/pr-gate.yml index de59790f0..1d54fc0b9 100644 --- a/.github/workflows/pr-gate.yml +++ b/.github/workflows/pr-gate.yml @@ -17,8 +17,13 @@ jobs: with: submodules: "true" + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build Docker image id: build uses: docker/build-push-action@v6 with: context: . + cache-from: type=gha,scope=pr-gate + cache-to: type=gha,mode=max,scope=pr-gate diff --git a/CHANGELOG.md b/CHANGELOG.md index ab3ee05da..9815c1831 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- Improved Docker build performance by enabling BuildKit cache mounts for Yarn and Go steps and by reusing Docker layer caches in the PR gate workflow. [#1094](https://github.com/sourcebot-dev/sourcebot/pull/1094) + ## [4.16.7] - 2026-04-03 ### Fixed diff --git a/Dockerfile b/Dockerfile index 66bc3489c..9c909bae2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# syntax=docker/dockerfile:1 +# syntax=docker/dockerfile:1.7 # ------ Global scope variables ------ # Set of global build arguments. @@ -24,9 +24,13 @@ FROM go-alpine AS zoekt-builder RUN apk add --no-cache ca-certificates WORKDIR /zoekt COPY vendor/zoekt/go.mod vendor/zoekt/go.sum ./ -RUN go mod download +RUN --mount=type=cache,id=sourcebot-go-mod-cache,target=/go/pkg/mod \ + --mount=type=cache,id=sourcebot-go-build-cache,target=/root/.cache/go-build \ + go mod download COPY vendor/zoekt ./ -RUN CGO_ENABLED=0 GOOS=linux go build -o /cmd/ ./cmd/... +RUN --mount=type=cache,id=sourcebot-go-mod-cache,target=/go/pkg/mod \ + --mount=type=cache,id=sourcebot-go-build-cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 GOOS=linux go build -o /cmd/ ./cmd/... # ------------------------- # ------ Build shared libraries ------ @@ -40,10 +44,14 @@ COPY ./packages/schemas ./packages/schemas COPY ./packages/shared ./packages/shared COPY ./packages/queryLanguage ./packages/queryLanguage -RUN yarn workspace @sourcebot/db install -RUN yarn workspace @sourcebot/schemas install -RUN yarn workspace @sourcebot/shared install -RUN yarn workspace @sourcebot/query-language install +RUN --mount=type=cache,id=sourcebot-yarn-cache,sharing=locked,target=/app/.yarn/cache \ + yarn workspace @sourcebot/db install +RUN --mount=type=cache,id=sourcebot-yarn-cache,sharing=locked,target=/app/.yarn/cache \ + yarn workspace @sourcebot/schemas install +RUN --mount=type=cache,id=sourcebot-yarn-cache,sharing=locked,target=/app/.yarn/cache \ + yarn workspace @sourcebot/shared install +RUN --mount=type=cache,id=sourcebot-yarn-cache,sharing=locked,target=/app/.yarn/cache \ + yarn workspace @sourcebot/query-language install # ------------------------------------ # ------ Build Web ------ @@ -89,7 +97,8 @@ COPY --from=shared-libs-builder /app/packages/shared ./packages/shared COPY --from=shared-libs-builder /app/packages/queryLanguage ./packages/queryLanguage # Fixes arm64 timeouts -RUN yarn workspace @sourcebot/web install +RUN --mount=type=cache,id=sourcebot-yarn-cache,sharing=locked,target=/app/.yarn/cache \ + yarn workspace @sourcebot/web install ENV NEXT_TELEMETRY_DISABLED=1 RUN yarn workspace @sourcebot/web build @@ -126,7 +135,8 @@ COPY --from=shared-libs-builder /app/packages/db ./packages/db COPY --from=shared-libs-builder /app/packages/schemas ./packages/schemas COPY --from=shared-libs-builder /app/packages/shared ./packages/shared COPY --from=shared-libs-builder /app/packages/queryLanguage ./packages/queryLanguage -RUN yarn workspace @sourcebot/backend install +RUN --mount=type=cache,id=sourcebot-yarn-cache,sharing=locked,target=/app/.yarn/cache \ + yarn workspace @sourcebot/backend install RUN yarn workspace @sourcebot/backend build # Upload source maps to Sentry if we have the necessary build-time args.