Repository navigation
Expand file tree
/
Copy pathEarthfile
More file actions
146 lines (127 loc) · 5.11 KB
/
Copy pathEarthfile
File metadata and controls
146 lines (127 loc) · 5.11 KB
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
VERSION 0.8
ARG core=github.com/formancehq/earthly:main
IMPORT $core AS core
FROM core+base-image
sources:
FROM +builder-image
WORKDIR /src
WORKDIR /src/components/operator
COPY --dir api internal pkg cmd config .
COPY go.* .
SAVE ARTIFACT /src
controller-gen:
FROM +builder-image
DO --pass-args core+GO_INSTALL --package=sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.0
generate:
FROM --pass-args +controller-gen
COPY +sources/* /src
WORKDIR /src/components/operator
COPY --dir hack .
RUN --mount=type=cache,id=gomod,target=${GOPATH}/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
SAVE ARTIFACT internal AS LOCAL internal
SAVE ARTIFACT api AS LOCAL api
compile:
ARG LICENCE_PUBLIC_KEY_B64=""
FROM +builder-image
COPY (+sources/*) /src
COPY --pass-args (+generate/*) /src/components/operator
WORKDIR /src/components/operator/cmd
IF [ "$LICENCE_PUBLIC_KEY_B64" = "" ]
DO --pass-args core+GO_COMPILE
ELSE
RUN --mount=type=cache,id=gomod,target=${GOPATH}/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
LICENCE_PUBLIC_KEY="$(printf '%s' "$LICENCE_PUBLIC_KEY_B64" | base64 -d)" && \
go build -ldflags "-X 'github.com/formancehq/go-libs/v5/pkg/authn/licence.formancePublicKey=${LICENCE_PUBLIC_KEY}'" -o main .
END
SAVE ARTIFACT main
build-image:
ARG LICENCE_PUBLIC_KEY_B64=""
ARG EARTHLY_BUILD_SHA
FROM DOCKERFILE \
--build-arg LICENCE_PUBLIC_KEY_B64=$LICENCE_PUBLIC_KEY_B64 \
--build-arg VERSION=$tag \
--build-arg COMMIT=$EARTHLY_BUILD_SHA \
-f Dockerfile .
ARG REPOSITORY=ghcr.io
ARG tag=latest
DO --pass-args core+SAVE_IMAGE --COMPONENT=operator --TAG=$tag
deploy:
ARG LICENCE_TOKEN=""
ARG LICENCE_ISSUER="http://licence-api.formance.svc.cluster.local:8080/keys"
COPY (+sources/*) /src
LET tag=$(tar cf - /src | sha1sum | awk '{print $1}')
WAIT
BUILD --pass-args +build-image --tag=$tag
BUILD --pass-args ./tools/utils+build-image --tag=$tag
END
FROM --pass-args core+vcluster-deployer-image
COPY --dir helm helm
WORKDIR helm
# When all clients are using the new base CRDS chart, we can uncomment this step
# RUN helm upgrade --install --namespace formance-system --install formance-operator-crds \
# --wait \
# --create-namespace ./base
RUN helm dependency update ./operator
ARG FORMANCE_DEV_CLUSTER_V2=no
LET ADDITIONAL_ARGS=""
IF [ "$FORMANCE_DEV_CLUSTER_V2" == "yes" ]
SET ADDITIONAL_ARGS="$ADDITIONAL_ARGS --set imagePullSecrets[0].name=zot"
ARG --required REPOSITORY=
SET ADDITIONAL_ARGS="$ADDITIONAL_ARGS --set image.repository=$REPOSITORY/formancehq/operator"
END
RUN --no-cache helm upgrade --install --namespace formance-system --install formance-operator \
--wait \
--debug \
--create-namespace \
--set image.tag=$tag \
--set operator.licence.token=$LICENCE_TOKEN \
--set operator.licence.issuer=$LICENCE_ISSUER ./operator \
--set operator.utils.tag=$tag \
--set operator.dev=true $ADDITIONAL_ARGS
WORKDIR /
COPY .earthly .earthly
WORKDIR .earthly
RUN kubectl get versions default || kubectl apply -f k8s-versions.yaml
ARG user
SET ADDITIONAL_ARGS=""
IF [ "$FORMANCE_DEV_CLUSTER_V2" == "yes" ]
SET ADDITIONAL_ARGS="$ADDITIONAL_ARGS --set v2=true"
SET ADDITIONAL_ARGS="$ADDITIONAL_ARGS --set ghcrRegistry=$REPOSITORY"
END
RUN --secret tld helm upgrade --install operator-configuration ./configuration \
--namespace formance-system \
--set gateway.fallback=https://console.$user.$tld $ADDITIONAL_ARGS
deploy-staging:
FROM --pass-args core+base-argocd
ARG --required TAG
ARG APPLICATION=staging-eu-west-1-hosting-operator
LET SERVER=argocd.internal.formance.cloud
RUN --secret AUTH_TOKEN \
argocd app set $APPLICATION \
--parameter image.tag=$TAG \
--parameter operator.utils.tag=$TAG \
--auth-token=$AUTH_TOKEN --server=$SERVER --grpc-web
RUN --secret AUTH_TOKEN argocd --auth-token=$AUTH_TOKEN --server=$SERVER --grpc-web app sync $APPLICATION
### Following targets are used by agent tests
manifests:
FROM --pass-args +controller-gen
COPY (+sources/*) /src
WORKDIR /src/components/operator
COPY --dir config .
RUN --mount=type=cache,id=gomod,target=${GOPATH}/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
SAVE ARTIFACT config AS LOCAL config
# Keep shared build helpers while selecting an exact Go compiler.
go-toolchain:
FROM golang:1.27.3-alpine
SAVE ARTIFACT /usr/local/go
builder-image:
FROM core+builder-image
COPY (+go-toolchain/go) /usr/local/go
ENV GOROOT=/usr/local/go
ENV PATH=/usr/local/go/bin:$PATH
ENV GOTOOLCHAIN=local