-
Notifications
You must be signed in to change notification settings - Fork 4
326 lines (265 loc) · 11.1 KB
/
buildAndDeploy.yml
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
317
318
319
320
321
322
323
324
325
name: Build and Deploy
on:
push:
branches:
- master
- release/**
pull_request:
branches:
- master
- release/**
release:
types: [published]
workflow_dispatch:
env:
DOCKERHUB_IMAGE: solarwinds/swi-opentelemetry-collector
jobs:
build_and_test:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.generate-tag.outputs.value }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy skaffold
uses: ./.github/actions/deploy-skaffold
- name: Generate docker image tag
id: generate-tag
run: echo "::set-output name=value::v${{ github.run_number }}-$(git rev-parse --short HEAD)"
- name: Build
run: skaffold build --file-output=/tmp/tags.json --tag ${{ steps.generate-tag.outputs.value }}
- name: Test
run: skaffold test --build-artifacts=/tmp/tags.json
- name: Deploy kubernetes
uses: ./.github/actions/deploy-kubernetes
- name: Add dependency chart repos
run: helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
- name: Deploy services using Skaffold
run: skaffold deploy --build-artifacts=/tmp/tags.json
- name: Run integration tests
uses: ./.github/actions/run-integration-tests
- name: Save image
if: github.event_name == 'release' && github.event.action == 'published' && !contains(github.ref, 'swo-k8s-collector')
run: |
docker save --output swi-k8s-opentelemetry-collector.tar swi-k8s-opentelemetry-collector:${{ steps.generate-tag.outputs.value }}
- uses: actions/upload-artifact@v3
if: github.event_name == 'release' && github.event.action == 'published' && !contains(github.ref, 'swo-k8s-collector')
with:
name: image
path: swi-k8s-opentelemetry-collector.tar
retention-days: 2
build_and_test_windows:
runs-on: windows-2022
if: github.event_name == 'release' && github.event.action == 'published' && !contains(github.ref, 'swo-k8s-collector')
outputs:
image_tag: ${{ steps.generate-tag.outputs.value }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate docker image tag
id: generate-tag
run: echo "::set-output name=value::v${{ github.run_number }}-$(git rev-parse --short HEAD)"
- name: Build
run: docker build -t swi-k8s-opentelemetry-collector:${{ steps.generate-tag.outputs.value }}-nanoserver-ltsc2022 -f build/docker/Dockerfile.Windows .
- name: Save image
if: github.event_name == 'release' && github.event.action == 'published' && !contains(github.ref, 'swo-k8s-collector')
run: |
docker save --output swi-k8s-opentelemetry-collector-windows.tar swi-k8s-opentelemetry-collector:${{ steps.generate-tag.outputs.value }}-nanoserver-ltsc2022
- uses: actions/upload-artifact@v3
if: github.event_name == 'release' && github.event.action == 'published' && !contains(github.ref, 'swo-k8s-collector')
with:
name: image
path: swi-k8s-opentelemetry-collector-windows.tar
retention-days: 2
# Verify whether Helm chart works with image published in DockerHub
helm_e2e:
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.generate-tag.outputs.value }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy skaffold
uses: ./.github/actions/deploy-skaffold
- name: Deploy kubernetes
uses: ./.github/actions/deploy-kubernetes
- name: Add dependency chart repos
run: helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
- name: Build
run: skaffold build -p=ci-helm-e2e --file-output=/tmp/tags.json
- name: Deploy services using Skaffold
run: skaffold deploy -p=ci-helm-e2e --build-artifacts=/tmp/tags.json
- name: Run integration tests
uses: ./.github/actions/run-integration-tests
helm_verify:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.10.0
- name: Add dependency chart repos
run: helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
- name: Download chart dependencies before linting
run: helm dependency build deploy/helm
- name: Lint helm
run: helm lint deploy/helm
- name: Install Unit test plugin
run: helm plugin install https://github.com/helm-unittest/helm-unittest.git
- name: Run unit tests
run: helm unittest deploy/helm
helm_test_auto_update_against_last_published:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy Kubernetes
uses: ./.github/actions/deploy-kubernetes
- name: Add dependency chart repos
run: |
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add solarwinds https://helm.solarwinds.com
helm repo update
- name: Deploy mocks.yaml
run: kubectl apply -f tests/deploy/base/mocks.yaml
- name: Create Dockerfile with Helm repository
run: |
cat <<EOF > Dockerfile
FROM python:3.8-alpine
WORKDIR /app
COPY . .
EXPOSE 5000
CMD ["python", "-m", "http.server", "5000"]
EOF
- name: Package and build Helm repository image
run: |
helm dependency build deploy/helm
helm package deploy/helm
helm repo index .
docker build -t helm-repo:latest .
- name: Deploy Helm repository in Kubernetes cluster
run: |
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: helm-repo
spec:
selector:
matchLabels:
app: helm-repo
replicas: 1
template:
metadata:
labels:
app: helm-repo
spec:
containers:
- name: helm-repo
image: helm-repo:latest
imagePullPolicy: Never
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: helm-repo
spec:
selector:
app: helm-repo
ports:
- protocol: TCP
port: 5000
targetPort: 5000
type: ClusterIP
EOF
- name: Deploy swo-k8s-collector Helm chart
run: |
helm install swo-k8s-collector solarwinds/swo-k8s-collector \
--create-namespace \
--namespace swo-k8s-collector \
--set cluster.name=test-cluster \
--set cluster.uid=test-cluster \
--set otel.endpoint=timeseries-mock-service:9082 \
--set prometheus.enabled=true \
--set autoupdate.enabled=true \
--set autoupdate.devel=true \
--set otel.metrics.swi_endpoint_check=false \
--set otel.metrics.prometheus_check=false \
--set otel.metrics.resources.requests.memory=100Mi \
--set otel.events.resources.requests.memory=100Mi \
--set otel.logs.resources.requests.memory=100Mi
- name: Update AutoUpdate ConfigMap to use local Helm repository
run: |
kubectl get configmap swo-k8s-collector-autoupdate-script -n swo-k8s-collector -o yaml > autoupdate-script.yaml
sed -i 's|https://helm.solarwinds.com|http://helm-repo.default.svc.cluster.local:5000|' autoupdate-script.yaml
kubectl apply -f autoupdate-script.yaml
cat autoupdate-script.yaml
- name: Trigger helm-autoupdate CronJob and verify
run: |
kubectl create job --from=cronjob/helm-autoupdate helm-autoupdate-manual-trigger -n swo-k8s-collector
kubectl wait --for=condition=complete --timeout=300s job/helm-autoupdate-manual-trigger -n swo-k8s-collector
- name: Trigger helm-autoupdate CronJob logs
if: ${{ always() }}
run: |
kubectl logs jobs/helm-autoupdate-manual-trigger -n swo-k8s-collector --all-containers=true
deploy_dockerhub:
runs-on: ubuntu-latest
needs: build_and_test
name: Deploy to docker hub
if: github.event_name == 'release' && github.event.action == 'published' && !contains(github.ref, 'swo-k8s-collector')
environment:
name: production
url: https://hub.docker.com/repository/docker/solarwinds/swi-opentelemetry-collector
steps:
- uses: actions/download-artifact@v3
with:
name: image
- name: Get image tag
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Load image
run: |
docker load --input swi-k8s-opentelemetry-collector.tar
- name: Tag images
run: |
docker tag swi-k8s-opentelemetry-collector:${{ needs.build_and_test.outputs.image_tag }} ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }}
docker tag swi-k8s-opentelemetry-collector:${{ needs.build_and_test.outputs.image_tag }} ${{ env.DOCKERHUB_IMAGE }}:latest
- name: Docker login
env:
DOCKER_HUB_CI_PASSWORD: ${{ secrets.DOCKER_HUB_CI_PASSWORD }}
DOCKER_HUB_CI_USER: ${{ secrets.DOCKER_HUB_CI_USER }}
run: echo "$DOCKER_HUB_CI_PASSWORD" | docker login -u "$DOCKER_HUB_CI_USER" --password-stdin
- name: Push as specific
run: docker push ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }}
deploy_dockerhub_windows:
runs-on: windows-2022
needs: build_and_test_windows
name: Deploy to docker hub Windows
if: github.event_name == 'release' && github.event.action == 'published' && !contains(github.ref, 'swo-k8s-collector')
environment:
name: production
url: https://hub.docker.com/repository/docker/solarwinds/swi-opentelemetry-collector
steps:
- uses: actions/download-artifact@v3
with:
name: image
- name: Get image tag
id: vars
run: echo "tag=$env:GITHUB_REF_NAME" >> $ENV:GITHUB_OUTPUT
- name: Load image
run: |
docker load --input swi-k8s-opentelemetry-collector-windows.tar
- name: Tag images
run: |
docker tag swi-k8s-opentelemetry-collector:${{ needs.build_and_test_windows.outputs.image_tag }}-nanoserver-ltsc2022 ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }}-nanoserver-ltsc2022
- name: Docker login
env:
DOCKER_HUB_CI_PASSWORD: ${{ secrets.DOCKER_HUB_CI_PASSWORD }}
DOCKER_HUB_CI_USER: ${{ secrets.DOCKER_HUB_CI_USER }}
run: echo "$env:DOCKER_HUB_CI_PASSWORD" | docker login -u "$env:DOCKER_HUB_CI_USER" --password-stdin
- name: Push as specific
run: docker push ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }}-nanoserver-ltsc2022