forked from zapier/kubechecks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEarthfile
221 lines (172 loc) · 5.77 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
VERSION 0.7
test:
BUILD +ci-golang
BUILD +ci-helm
ci-golang:
# This should be enabled at some point
BUILD +lint-golang
BUILD +validate-golang
BUILD +test-golang
ci-helm:
BUILD +test-helm
BUILD +release-helm
build:
BUILD --platform=linux/amd64 --platform=linux/arm64 +docker
release:
BUILD --platform=linux/amd64 --platform=linux/arm64 +docker
BUILD +release-helm
go-deps:
ARG GOLANG_VERSION="1.19.3"
FROM 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
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:
FROM +go-deps
ARG GOOS=linux
ARG GOARCH=amd64
ARG VARIANT
ARG --required GIT_TAG
ARG --required GIT_COMMIT
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
docker:
FROM ubuntu:20.04
ARG TARGETVARIANT
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
COPY ./policy ./policy
COPY ./schemas ./schemas
COPY (+build-binary/kubechecks --GOARCH=amd64 --VARIANT=$TARGETVARIANT) .
RUN ./kubechecks help
CMD ["./kubechecks", "controller"]
docker-dev:
FROM +docker
ARG CI_REGISTRY_IMAGE="ghcr.io/zapier/kubechecks"
SAVE IMAGE --push $CI_REGISTRY_IMAGE:dev
docker-tag:
FROM +docker
ARG CI_REGISTRY_IMAGE="ghcr.io/zapier/kubechecks"
ARG --required GIT_TAG
SAVE IMAGE --push $CI_REGISTRY_IMAGE:latest
SAVE IMAGE --push $CI_REGISTRY_IMAGE:$GIT_TAG
dlv:
FROM golang:1.19
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:
ARG CI_REGISTRY_IMAGE="kubechecks"
FROM +docker --GIT_TAG=debug --GIT_COMMIT=abcdef
COPY (+dlv/dlv --GOARCH=$GOARCH --VARIANT=$TARGETVARIANT) /usr/local/bin/dlv
CMD ["/usr/local/bin/dlv", "--listen=:2345", "--api-version=2", "--headless=true", "--accept-multiclient", "exec", "--continue", "./kubechecks", "controller"]
SAVE IMAGE --push $CI_REGISTRY_IMAGE
lint-golang:
ARG STATICCHECK_VERSION="0.3.3"
FROM +go-deps
# install staticcheck
RUN FILE=staticcheck.tgz \
&& URL=https://github.com/dominikh/go-tools/releases/download/v$STATICCHECK_VERSION/staticcheck_linux_amd64.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.5.0"
RUN FILE=kubeconform.tgz \
&& URL=https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-amd64.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-amd64.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