Skip to content

Commit

Permalink
feat: make correct use of cache mounts (speedup local pre-commit by ~5)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 24, 2024
1 parent c8a1687 commit 991641e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ IMPORT github.com/formancehq/earthly:tags/v0.17.1 AS core

FROM core+base-image

CACHE --persist --sharing=shared /go
CACHE --persist --sharing=shared /root/.cache/golangci-lint
CACHE --sharing=shared --id go-mod-cache /go/pkg/mod
CACHE --sharing=shared --id golangci-cache /root/.cache/golangci-lint
CACHE --sharing=shared --id go-cache /root/.cache/go-build

sources:
FROM core+builder-image
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
WORKDIR /src/pkg/client
COPY pkg/client/go.mod pkg/client/go.sum ./
RUN go mod download
Expand All @@ -22,6 +25,8 @@ sources:

generate:
FROM core+builder-image
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
RUN apk update && apk add openjdk11
RUN go install go.uber.org/mock/[email protected]
RUN go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest
Expand All @@ -34,9 +39,10 @@ generate:

compile:
FROM +sources
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
WORKDIR /src
ARG VERSION=latest
RUN go build
RUN go build -o main -ldflags="-X ${GIT_PATH}/cmd.Version=${VERSION} \
-X ${GIT_PATH}/cmd.BuildDate=$(date +%s) \
-X ${GIT_PATH}/cmd.Commit=${EARTHLY_BUILD_SHA}"
Expand All @@ -53,6 +59,8 @@ build-image:

tests:
FROM +tidy
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
RUN go install github.com/onsi/ginkgo/v2/ginkgo@latest
COPY --dir --pass-args (+generate/*) .

Expand Down Expand Up @@ -107,7 +115,12 @@ deploy-staging:
lint:
#todo: get config from core
FROM +tidy
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
CACHE --id golangci-cache /root/.cache/golangci-lint

RUN golangci-lint run --fix --build-tags it --timeout 5m

SAVE ARTIFACT cmd AS LOCAL cmd
SAVE ARTIFACT internal AS LOCAL internal
SAVE ARTIFACT pkg AS LOCAL pkg
Expand Down Expand Up @@ -176,6 +189,8 @@ openapi-markdown:

tidy:
FROM +sources
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build
WORKDIR /src
COPY --dir test .
RUN go mod tidy
Expand Down Expand Up @@ -211,5 +226,9 @@ export-database-schema:

export-docs-events:
FROM +tidy
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build

RUN go run tools/docs/events/main.go --write-dir docs/events

SAVE ARTIFACT docs/events AS LOCAL docs/events
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,4 @@ require (
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
)

0 comments on commit 991641e

Please sign in to comment.