-
Notifications
You must be signed in to change notification settings - Fork 4
/
Earthfile
176 lines (154 loc) · 5.49 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
VERSION 0.8
PROJECT FormanceHQ/payments
IMPORT github.com/formancehq/earthly:tags/v0.19.0 AS core
FROM core+base-image
postgres:
FROM postgres:15-alpine
sources:
WORKDIR src
WORKDIR /src
COPY go.* .
COPY --dir cmd pkg internal tools .
COPY main.go .
SAVE ARTIFACT /src
compile-plugins:
FROM core+builder-image
COPY (+sources/*) /src
COPY (+compile-configs/configs.json) /src/internal/connectors/plugins/configs.json
WORKDIR /src/internal/connectors/plugins/public
RUN printf "package public\n\n" > list.go
RUN printf "import (\n" >> list.go
FOR c IN $(ls -d */ | sed 's#/##')
RUN printf " _ \"github.com/formancehq/payments/internal/connectors/plugins/public/$c\"\n" >> list.go
END
RUN printf ")\n" >> list.go
SAVE ARTIFACT /src/internal/connectors/plugins/public/list.go /list.go
compile-configs:
FROM core+builder-image
COPY (+sources/*) /src
WORKDIR /src/internal/connectors/plugins/public
FOR c IN $(ls -d */ | sed 's#/##')
RUN echo "{\"$c\":" >> raw_configs.json
RUN cat /src/internal/connectors/plugins/public/$c/config.json >> raw_configs.json
RUN echo "}" >> raw_configs.json
END
RUN jq --slurp 'add' raw_configs.json > configs.json
SAVE ARTIFACT /src/internal/connectors/plugins/public/configs.json /configs.json
compile:
FROM core+builder-image
COPY (+sources/*) /src
COPY (+compile-configs/configs.json) /src/internal/connectors/plugins/configs.json
COPY (+compile-plugins/list.go) /src/internal/connectors/plugins/public/list.go
WORKDIR /src
ARG VERSION=latest
DO --pass-args core+GO_COMPILE --VERSION=$VERSION
build-image:
FROM core+final-image
ENTRYPOINT ["/bin/payments"]
CMD ["serve"]
COPY (+compile/main) /bin/payments
FOR c IN $(ls /plugins/*)
RUN chmod +x $c
END
ARG REPOSITORY=ghcr.io
ARG tag=latest
DO core+SAVE_IMAGE --COMPONENT=payments --REPOSITORY=${REPOSITORY} --TAG=$tag
tests:
FROM +tidy
COPY (+sources/*) /src
WORKDIR /src
ARG includeIntegrationTests="true"
ENV CGO_ENABLED=1 # required for -race
LET goFlags="-race"
IF [ "$includeIntegrationTests" = "true" ]
COPY (+compile-configs/configs.json) /src/internal/connectors/plugins/configs.json
COPY (+compile-plugins/list.go) /src/internal/connectors/plugins/public/list.go
SET goFlags="$goFlags -tags it"
WITH DOCKER --load=postgres:15-alpine=+postgres
RUN go test $goFlags ./...
END
ELSE
WITH DOCKER --pull=postgres:15-alpine
DO --pass-args +GO_TESTS
END
END
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\":{\"payments\": \"${tag}\"}}" --type=merge
deploy-staging:
BUILD --pass-args core+deploy-staging
lint:
FROM core+builder-image
COPY (+sources/*) /src
COPY --pass-args +tidy/go.* .
WORKDIR /src
DO --pass-args core+GO_LINT
COPY (+compile-plugins/list.go) .
COPY (+compile-configs/configs.json) .
SAVE ARTIFACT cmd AS LOCAL cmd
SAVE ARTIFACT internal AS LOCAL internal
SAVE ARTIFACT pkg AS LOCAL pkg
SAVE ARTIFACT main.go AS LOCAL main.go
SAVE ARTIFACT list.go AS LOCAL internal/connectors/plugins/public/list.go
SAVE ARTIFACT configs.json AS LOCAL internal/connectors/plugins/configs.json
pre-commit:
WAIT
BUILD --pass-args +tidy
END
BUILD --pass-args +lint
compile-openapi-configs:
FROM core+builder-image
COPY (+sources/*) /src
WORKDIR /src/tools/compile-configs
RUN go build -o compile-configs
RUN ./compile-configs --path /src/internal/connectors/plugins/public --output ./v3-connectors-config.yaml
SAVE ARTIFACT ./v3-connectors-config.yaml /v3-connectors-config.yaml
openapi:
FROM node:20-alpine
RUN apk update && apk add yq
RUN npm install -g openapi-merge-cli
WORKDIR /src
COPY --dir openapi openapi
COPY (+compile-openapi-configs/v3-connectors-config.yaml) ./openapi/v3/v3-connectors-config.yaml
RUN openapi-merge-cli --config ./openapi/openapi-merge.json
RUN yq -oy ./openapi.json > openapi.yaml
SAVE ARTIFACT ./openapi.yaml AS LOCAL ./openapi.yaml
tidy:
FROM core+builder-image
COPY --pass-args (+sources/src) /src
WORKDIR /src
COPY --dir test .
DO --pass-args core+GO_TIDY
generate:
FROM core+builder-image
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
# generate-generic-connector-client:
# FROM openapitools/openapi-generator-cli:v6.6.0
# WORKDIR /src
# COPY cmd/connectors/internal/connectors/generic/client/generic-openapi.yaml .
# RUN docker-entrypoint.sh generate \
# -i ./generic-openapi.yaml \
# -g go \
# -o ./generated \
# --git-user-id=formancehq \
# --git-repo-id=payments \
# -p packageVersion=latest \
# -p isGoSubmodule=true \
# -p packageName=genericclient
# RUN rm -rf ./generated/test
# SAVE ARTIFACT ./generated AS LOCAL ./cmd/connectors/internal/connectors/generic/client/generated
release:
FROM core+builder-image
ARG mode=local
COPY --dir . /src
DO core+GORELEASER --mode=$mode