-
Notifications
You must be signed in to change notification settings - Fork 1
316 lines (274 loc) · 11.4 KB
/
build.yaml
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
name: Go
on: [push, pull_request]
permissions:
contents: read
pull-requests: read
checks: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ShellCheck on GHA config
uses: saleor/shellcheck-gha@v0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Verify
run: go mod verify
- name: Build
run: go build ./...
- name: Test
run: go test ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
install-mode: binary
- name: Prepare manifests for linting
run: |
go build -C deploy .
mkdir manifests
./deploy/deploy --k8s-flavor vanilla my-images > manifests/vanilla.yaml
./deploy/deploy --k8s-flavor ocp my-images > manifests/ocp.yaml
./deploy/deploy --k8s-flavor vanilla --secret my-secret my-images > manifests/vanilla-with-secret.yaml
./deploy/deploy --k8s-flavor ocp --secret my-secret my-images > manifests/ocp-with-secret.yaml
./deploy/deploy --k8s-flavor vanilla --collect-metrics my-images > manifests/vanilla-metrics.yaml
./deploy/deploy --k8s-flavor ocp --collect-metrics my-images > manifests/ocp-metrics.yaml
./deploy/deploy --k8s-flavor vanilla --secret my-secret --collect-metrics my-images > manifests/vanilla-with-secret-metrics.yaml
./deploy/deploy --k8s-flavor ocp --secret my-secret --collect-metrics my-images > manifests/ocp-with-secret-metrics.yaml
- name: kubeconform
run: |
make -C deploy kubeconform MANIFESTS="$(pwd)/manifests"
- name: kube-linter
uses: stackrox/[email protected]
with:
directory: manifests
- name: Build binary
run: make -j2 binary-all
- name: Login to Quay
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_STACKROX_IO_RW_USERNAME }}
password: ${{ secrets.QUAY_STACKROX_IO_RW_PASSWORD }}
- name: Prepare manifest OCI metadata for amd64
id: meta-amd64
uses: docker/metadata-action@v5
with:
images: "quay.io/stackrox-io/image-prefetcher"
# generate Docker tags based on the following events/attributes
# See https://github.com/docker/metadata-action
tags: |
type=ref,event=branch,prefix=branch-,suffix=-amd64
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-amd64
type=semver,pattern=v{{major}}.{{minor}},suffix=-amd64
type=semver,pattern=v{{major}},suffix=-amd64
type=sha,suffix=-amd64
- name: Build and push OCI amd64 image
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-amd64.outputs.tags }}
labels: ${{ steps.meta-amd64.outputs.labels }}
platforms: linux/amd64
build-args: |
ARCH=amd64
- name: Prepare manifest OCI metadata for arm64
id: meta-arm64
uses: docker/metadata-action@v5
with:
images: "quay.io/stackrox-io/image-prefetcher"
# generate Docker tags based on the following events/attributes
# See https://github.com/docker/metadata-action
tags: |
type=ref,event=branch,prefix=branch-,suffix=-arm64
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-arm64
type=semver,pattern=v{{major}}.{{minor}},suffix=-arm64
type=semver,pattern=v{{major}},suffix=-arm64
type=sha,suffix=-arm64
- name: Build and push OCI arm64 image
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-arm64.outputs.tags }}
labels: ${{ steps.meta-arm64.outputs.labels }}
platforms: linux/arm64
build-args: |
ARCH=arm64
- name: Prepare manifest OCI metadata for ppc64le
id: meta-ppc64le
uses: docker/metadata-action@v5
with:
images: "quay.io/stackrox-io/image-prefetcher"
# generate Docker tags based on the following events/attributes
# See https://github.com/docker/metadata-action
tags: |
type=ref,event=branch,prefix=branch-,suffix=-ppc64le
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-ppc64le
type=semver,pattern=v{{major}}.{{minor}},suffix=-ppc64le
type=semver,pattern=v{{major}},suffix=-ppc64le
type=sha,suffix=-ppc64le
- name: Build and push OCI ppc64le image
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-ppc64le.outputs.tags }}
labels: ${{ steps.meta-ppc64le.outputs.labels }}
platforms: linux/ppc64le
build-args: |
ARCH=ppc64le
- name: Prepare manifest OCI metadata for s390x
id: meta-s390x
uses: docker/metadata-action@v5
with:
images: "quay.io/stackrox-io/image-prefetcher"
# generate Docker tags based on the following events/attributes
# See https://github.com/docker/metadata-action
tags: |
type=ref,event=branch,prefix=branch-,suffix=-s390x
type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-s390x
type=semver,pattern=v{{major}}.{{minor}},suffix=-s390x
type=semver,pattern=v{{major}},suffix=-s390x
type=sha,suffix=-s390x
- name: Build and push OCI s390x image
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-s390x.outputs.tags }}
labels: ${{ steps.meta-s390x.outputs.labels }}
platforms: linux/s390x
build-args: |
ARCH=s390x
- name: Prepare manifest OCI metadata
id: meta
uses: docker/metadata-action@v5
with:
images: "quay.io/stackrox-io/image-prefetcher"
# generate Docker tags based on the following events/attributes
# See https://github.com/docker/metadata-action
tags: |
type=ref,event=branch,prefix=branch-
type=semver,pattern=v{{major}}.{{minor}}.{{patch}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
type=sha
- name: Create and push multi-arch manifest
if: github.event_name != 'pull_request'
env:
IMAGE_TAGS: ${{ steps.meta.outputs.tags }}
run: |
for tag in ${IMAGE_TAGS};
do
docker manifest create "${tag}" \
--amend "${tag}-amd64" \
--amend "${tag}-arm64" \
--amend "${tag}-ppc64le" \
--amend "${tag}-s390x"
docker manifest push "${tag}"
done
e2e:
if: github.event_name != 'pull_request'
needs: build
runs-on: ubuntu-latest
env:
CLUSTER_NAME: img-prefetch-${{ github.run_id }}
INFRA_TOKEN: ${{ secrets.INFRA_TOKEN }}
NS: prefetch
NAME: basic
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Authenticate against GCP
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GCP_IMAGE_PREFETCHER_CI_SA }}"
- name: Install GKE auth plugin
uses: "google-github-actions/setup-gcloud@v2"
with:
install_components: "gke-gcloud-auth-plugin"
- name: Install infractl
uses: stackrox/actions/infra/install-infractl@main
- name: Create GKE cluster
uses: stackrox/actions/infra/[email protected]
with:
token: ${{ secrets.INFRA_TOKEN }}
flavor: gke-default
name: img-prefetch-${{ github.run_id }}
lifespan: 1h
args: nodes=2
wait: "true"
no-slack: "true"
- name: Setup environment from cluster artifacts
env:
ARTIFACTS_DIR: ${{ runner.temp }}/gke-artifacts
run: |
# Fetch the artifacts for the GKE cluster.
infractl artifacts --download-dir="${ARTIFACTS_DIR}" "${CLUSTER_NAME}" >/dev/null
# Set both URL and admin password.
KUBECONFIG="${ARTIFACTS_DIR}/kubeconfig"
echo "KUBECONFIG=$KUBECONFIG" >> "$GITHUB_ENV"
- name: Build the deploy tool
run: go build -C deploy .
- name: Deploy prefetcher
run: |
set -e
echo busybox:latest >> images.txt
echo debian:sid >> images.txt
kubectl create --dry-run=client -o yaml --namespace="$NS" configmap "${NAME}" --from-file="images.txt=images.txt" > manifest.yaml
echo --- >> manifest.yaml
./deploy/deploy \
--version="sha-$(git rev-parse --short HEAD)" \
--k8s-flavor=vanilla \
--collect-metrics \
"${NAME}" >> manifest.yaml
kubectl create namespace "$NS"
kubectl apply -n "$NS" -f manifest.yaml
- name: Wait for prefetcher to finish
run: |
set -e
info() { echo "$@"; }
die() { info "$@"; exit 1; }
attempt=0
service="service/${NAME}-metrics"
while [[ -z $(kubectl -n "${NS}" get "${service}" -o jsonpath="{.status.loadBalancer.ingress}" 2>/dev/null) ]]; do
if [ "$attempt" -lt "10" ]; then
info "Waiting for ${service} to obtain endpoint ..."
attempt=$((attempt+1))
sleep 10
else
die "ERROR: Timeout waiting for ${service} to obtain endpoint!"
fi
done
endpoint="$(kubectl -n "${NS}" get "${service}" -o json | jq -r '.status.loadBalancer.ingress[] | .ip')"
curl --silent --show-error --fail --retry 3 --retry-connrefused "http://${endpoint}:8080/metrics" > metrics.json
- name: Dump metrics
run: jq . metrics.json
- name: Dump debug info
if: always()
run: |
kubectl -n "$NS" get -o yaml daemonsets,deployments,pods,replicasets,services,roles,rolebindings
kubectl -n "$NS" get events
kubectl -n "$NS" logs -l app=basic-metrics --all-containers=true --ignore-errors=true --tail=-1
kubectl -n "$NS" logs -l app=basic-metrics --all-containers=true --ignore-errors=true --tail=-1 --previous=true
kubectl -n "$NS" logs -l app=basic --all-containers=true --ignore-errors=true --tail=-1
kubectl -n "$NS" logs -l app=basic --all-containers=true --ignore-errors=true --tail=-1 --previous=true
- name: Teardown cluster
if: always()
env:
INFRA_TOKEN: ${{ secrets.INFRA_TOKEN }}
run: |
infractl delete "${CLUSTER_NAME}" || echo "Failed to remove the infra cluster"