Skip to content
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

refactor(Earthfile): reuse sources stage and optimize build process #498

Merged
merged 2 commits into from
Sep 26, 2024
Merged
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
31 changes: 14 additions & 17 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@
FROM core+base-image

sources:
FROM core+builder-image
CACHE --persist --sharing=shared /go/pkg
WORKDIR /src/pkg/client
COPY pkg/client/go.mod pkg/client/go.sum ./
RUN go mod download
WORKDIR /src
COPY go.mod go.sum .
COPY go.mod go.sum ./
RUN go mod download
COPY --dir internal pkg cmd .
COPY main.go .
SAVE ARTIFACT /src

generate:
FROM core+builder-image
FROM +sources
RUN apk update && apk add openjdk11
DO --pass-args core+GO_INSTALL --package=go.uber.org/mock/mockgen@latest
COPY (+sources/*) /src
WORKDIR /src
DO --pass-args core+GO_GENERATE
SAVE ARTIFACT internal AS LOCAL internal
SAVE ARTIFACT pkg AS LOCAL pkg
SAVE ARTIFACT cmd AS LOCAL cmd

compile:
FROM core+builder-image
COPY (+sources/*) /src
FROM +sources
WORKDIR /src
ARG VERSION=latest
DO --pass-args core+GO_COMPILE --VERSION=$VERSION
Expand All @@ -41,10 +45,8 @@
DO --pass-args core+SAVE_IMAGE --COMPONENT=ledger --REPOSITORY=${REPOSITORY} --TAG=$tag

tests:
FROM core+builder-image
FROM +sources
RUN go install github.com/onsi/ginkgo/v2/ginkgo@latest

COPY (+sources/*) /src
WORKDIR /src
COPY --dir --pass-args (+generate/*) .
COPY --dir test .
Expand All @@ -68,7 +70,7 @@
IF [ "$includeIntegrationTests" = "true" ]
SET goFlags="$goFlags -tags it"
WITH DOCKER --pull=postgres:15-alpine
RUN --mount type=cache,id=gopkgcache,target=${GOPATH}/pkg/mod \

Check failure on line 73 in Earthfile

View workflow job for this annotation

GitHub Actions / Tests

Error

The command WITH DOCKER RUN --privileged ginkgo -r -p $goFlags did not complete successfully. Exit code 1
--mount type=cache,id=gobuildcache,target=/root/.cache/go-build \
ginkgo -r -p $goFlags
END
Expand Down Expand Up @@ -98,10 +100,8 @@
BUILD --pass-args core+deploy-staging

lint:
FROM core+builder-image
COPY (+sources/*) /src
FROM +sources
WORKDIR /src
COPY --pass-args +tidy/go.* .
COPY --dir test .
DO --pass-args core+GO_LINT --ADDITIONAL_ARGUMENTS="--build-tags it"
SAVE ARTIFACT cmd AS LOCAL cmd
Expand All @@ -121,9 +121,8 @@
BUILD +generate-client

bench:
FROM core+builder-image
FROM +sources
DO --pass-args core+GO_INSTALL --package=golang.org/x/perf/cmd/benchstat@latest
COPY (+sources/*) /src
WORKDIR /src
COPY --dir test .
WORKDIR /src/test/performance
Expand Down Expand Up @@ -167,8 +166,7 @@
SAVE ARTIFACT ./openapi.yaml AS LOCAL ./openapi.yaml

tidy:
FROM core+builder-image
COPY --pass-args (+sources/src) /src
FROM +sources
WORKDIR /src
COPY --dir test .
DO --pass-args core+GO_TIDY
Expand All @@ -193,9 +191,8 @@
SAVE ARTIFACT client AS LOCAL ./pkg/client

export-database-schema:
FROM core+builder-image
FROM +sources
RUN go install github.com/roerohan/wait-for-it@latest
COPY (+sources/*) /src
WORKDIR /src/components/ledger
COPY --dir scripts scripts
WITH DOCKER --pull postgres:15-alpine --pull schemaspy/schemaspy:6.2.4
Expand Down
Loading