forked from zapier/kubechecks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earthfile
256 lines (196 loc) · 6.7 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
VERSION 0.7
ARG --global USERARCH
test:
BUILD +ci-golang
BUILD +ci-helm
ci-golang:
BUILD +fmt-golang
BUILD +staticcheck-golang
BUILD +golang-ci-lint
BUILD +validate-golang
BUILD +test-golang
ci-helm:
BUILD +test-helm
BUILD +release-helm
docker-multiarch:
BUILD --platform=linux/amd64 --platform=linux/arm64 +docker
release:
BUILD --platform=linux/amd64 --platform=linux/arm64 +docker
BUILD +release-helm
go-deps:
ARG GOOS=linux
ARG GOARCH=$USERARCH
ARG --required GOLANG_VERSION
FROM --platform=linux/$USERARCH golang:$GOLANG_VERSION-bullseye
ENV GO111MODULE=on
ENV CGO_ENABLED=0
WORKDIR /src
COPY go.mod go.sum /src
RUN go mod download
SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum
rebuild-docs:
FROM +go-deps
COPY . /src
RUN go run hacks/env-to-docs.go
SAVE ARTIFACT ./docs/usage.md AS LOCAL ./docs/usage.md
validate-golang:
FROM +go-deps
WORKDIR /src
COPY . /src
RUN go vet ./...
test-golang:
FROM +go-deps
WORKDIR /src
COPY . /src
RUN go test ./...
build-binary:
ARG GOOS=linux
ARG GOARCH=$USERARCH
ARG VARIANT
ARG --required GIT_TAG
ARG --required GIT_COMMIT
FROM --platform=linux/$USERARCH +go-deps
WORKDIR /src
COPY . /src
RUN GOARM=${VARIANT#v} go build -ldflags "-X github.com/zapier/kubechecks/pkg.GitCommit=$GIT_COMMIT -X github.com/zapier/kubechecks/pkg.GitTag=$GIT_TAG" -o kubechecks
SAVE ARTIFACT kubechecks
build-debug-binary:
FROM --platform=linux/$USERARCH +go-deps
WORKDIR /src
COPY . /src
RUN go build -gcflags="all=-N -l" -ldflags "-X github.com/zapier/kubechecks/pkg.GitCommit=$GIT_COMMIT -X github.com/zapier/kubechecks/pkg.GitTag=$GIT_TAG" -o kubechecks
SAVE ARTIFACT kubechecks
docker:
ARG TARGETPLATFORM
ARG TARGETARCH
ARG TARGETVARIANT
FROM --platform=$TARGETPLATFORM ubuntu:20.04
RUN apt update && apt install -y ca-certificates curl git
WORKDIR /tmp
ARG KUSTOMIZE_VERSION=4.5.7
RUN \
curl \
--fail \
--silent \
--show-error \
--location \
"https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" \
--output install_kustomize.sh && \
chmod 700 install_kustomize.sh && \
./install_kustomize.sh ${KUSTOMIZE_VERSION} /usr/local/bin
ARG HELM_VERSION=3.10.0
RUN \
curl \
--fail \
--silent \
--show-error \
--location \
"https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3" \
--output get-helm-3.sh && \
chmod 700 get-helm-3.sh && \
./get-helm-3.sh -v v${HELM_VERSION}
RUN mkdir /app
WORKDIR /app
VOLUME /app/policies
VOLUME /app/schemas
COPY (+build-binary/kubechecks --platform=linux/$USERARCH --GOARCH=$TARGETARCH --VARIANT=$TARGETVARIANT) .
RUN ./kubechecks help
CMD ["./kubechecks", "controller"]
ARG --required IMAGE_NAME
ARG LATEST_IMAGE_NAME=""
SAVE IMAGE --push $IMAGE_NAME $LATEST_IMAGE_NAME
dlv:
ARG --required GOLANG_VERSION
FROM golang:$GOLANG_VERSION-bullseye
RUN apt update && apt install -y ca-certificates curl git
RUN go install github.com/go-delve/delve/cmd/dlv@latest
SAVE ARTIFACT /go/bin/dlv
docker-debug:
FROM +docker --GIT_TAG=debug --GIT_COMMIT=abcdef
COPY (+build-debug-binary/kubechecks --GOARCH=$USERARCH --VARIANT=$TARGETVARIANT) .
COPY (+dlv/dlv --GOARCH=$USERARCH --VARIANT=$TARGETVARIANT) /usr/local/bin/dlv
CMD ["/usr/local/bin/dlv", "--listen=:2345", "--api-version=2", "--headless=true", "--accept-multiclient", "exec", "--continue", "./kubechecks", "controller"]
ARG IMAGE_NAME="kubechecks:debug"
SAVE IMAGE --push $IMAGE_NAME
fmt-golang:
FROM +go-deps
WORKDIR /src
COPY . /src
RUN go fmt \
&& ./hacks/exit-on-changed-files.sh
golang-ci-lint:
ARG --required GOLANGCI_LINT_VERSION
FROM golangci/golangci-lint:v${GOLANGCI_LINT_VERSION}
WORKDIR /src
COPY . .
RUN golangci-lint --timeout 15m run --verbose
staticcheck-golang:
ARG --required STATICCHECK_VERSION
FROM +go-deps
# install staticcheck
RUN FILE=staticcheck.tgz \
&& URL=https://github.com/dominikh/go-tools/releases/download/$STATICCHECK_VERSION/staticcheck_linux_$USERARCH.tar.gz \
&& wget ${URL} \
--output-document ${FILE} \
&& tar \
--extract \
--verbose \
--directory /bin \
--strip-components=1 \
--file ${FILE} \
&& staticcheck -version
WORKDIR /src
COPY . /src
RUN staticcheck ./...
test-helm:
ARG CHART_TESTING_VERSION="3.7.1"
FROM quay.io/helmpack/chart-testing:v${CHART_TESTING_VERSION}
# install kubeconform
ARG KUBECONFORM_VERSION="0.6.4"
RUN FILE=kubeconform.tgz \
&& URL=https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-${USERARCH}.tar.gz \
&& wget ${URL} \
--output-document ${FILE} \
&& tar \
--extract \
--verbose \
--directory /bin \
--file ${FILE} \
&& kubeconform -v
ARG HELM_UNITTEST_VERSION="0.3.3"
RUN apk add --no-cache bash git \
&& helm plugin install --version "${HELM_UNITTEST_VERSION}" https://github.com/helm-unittest/helm-unittest \
&& helm unittest --help
# actually lint the chart
WORKDIR /src
COPY . /src
RUN git fetch --prune --unshallow | true
RUN ct --config ./.github/ct.yaml lint ./charts
release-helm:
ARG CHART_RELEASER_VERSION="1.6.0"
FROM quay.io/helmpack/chart-releaser:v${CHART_RELEASER_VERSION}
ARG HELM_VERSION="3.8.1"
RUN FILE=helm.tgz \
&& URL=https://get.helm.sh/helm-v${HELM_VERSION}-linux-${USERARCH}.tar.gz \
&& wget ${URL} \
--output-document ${FILE} \
&& tar \
--strip-components=1 \
--extract \
--verbose \
--directory /bin \
--file ${FILE} \
&& helm version
WORKDIR /src
COPY . /src
RUN cr --config .github/cr.yaml package charts/*
SAVE ARTIFACT .cr-release-packages/ AS LOCAL ./dist
RUN mkdir -p .cr-index
RUN git config --global user.email "[email protected]"
RUN git config --global user.name "Open Source at Zapier"
RUN git fetch --prune --unshallow | true
ARG repo_owner=""
ARG token=""
RUN --push cr --config .github/cr.yaml upload --owner $repo_owner --token $token --skip-existing
RUN --push cr --config .github/cr.yaml index --owner $repo_owner --token $token --push