-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathEarthfile
82 lines (69 loc) · 2.66 KB
/
Earthfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
VERSION --wildcard-builds 0.8
PROJECT FormanceHQ/ledger
IMPORT github.com/formancehq/earthly:tags/v0.19.0 AS core
FROM core+base-image
postgres:
FROM postgres:15-alpine
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
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY --dir internal pkg cmd .
COPY main.go .
SAVE ARTIFACT /src
compile:
FROM +sources
ARG VERSION=latest
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}"
SAVE ARTIFACT main
build-image:
FROM core+final-image
ENTRYPOINT ["/bin/ledger"]
CMD ["serve"]
COPY --pass-args (+compile/main) /bin/ledger
ARG REPOSITORY=ghcr.io
ARG tag=latest
DO --pass-args core+SAVE_IMAGE --COMPONENT=ledger --REPOSITORY=${REPOSITORY} --TAG=$tag
deploy:
COPY (+sources/*) /src
LET tag=$(tar cf - /src | sha1sum | awk '{print $1}')
WAIT
BUILD --pass-args +build-image --tag=$tag
END
FROM --pass-args core+vcluster-deployer-image
RUN kubectl patch Versions.formance.com default -p "{\"spec\":{\"ledger\": \"${tag}\"}}" --type=merge
deploy-staging:
BUILD --pass-args core+deploy-staging
export-database-schema:
FROM +sources
RUN go install github.com/roerohan/wait-for-it@latest
WITH DOCKER --load=postgres:15-alpine=+postgres --pull schemaspy/schemaspy:6.2.4
RUN bash -c '
echo "Creating PG server...";
postgresContainerID=$(docker run -d --rm -e POSTGRES_USER=root -e POSTGRES_PASSWORD=root -e POSTGRES_DB=formance --net=host postgres:15-alpine);
wait-for-it -w 127.0.0.1:5432;
echo "Creating bucket...";
go run main.go buckets upgrade _default --postgres-uri "postgres://root:[email protected]:5432/formance?sslmode=disable";
echo "Exporting schemas...";
docker run --rm -u root \
-v ./docs/database:/output \
--net=host \
schemaspy/schemaspy:6.2.4 -u root -db formance -t pgsql11 -host 127.0.0.1 -port 5432 -p root -schemas _system,_default;
docker kill "$postgresContainerID";
'
END
SAVE ARTIFACT docs/database/_system/diagrams AS LOCAL docs/database/_system/diagrams
SAVE ARTIFACT docs/database/_default/diagrams AS LOCAL docs/database/_default/diagrams
openapi:
FROM core+base-image
WORKDIR /src
COPY openapi.yaml openapi.yaml
SAVE ARTIFACT ./openapi.yaml