-
Notifications
You must be signed in to change notification settings - Fork 24
385 lines (322 loc) · 11.2 KB
/
go-application.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
name: Go application CI/CD
on:
push:
branches:
- master
tags:
- "*"
pull_request:
branches:
- master
env:
GOLANGCI_LINT_VERSION: v1.51.1
TAG_NAME: "${GITHUB_REF##*/}"
jobs:
lint:
name: Lint code
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v4
with:
go-version: "^1.20"
- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin ${GOLANGCI_LINT_VERSION}
- name: Lint code
run: golangci-lint run
test:
name: Unit test code
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v4
with:
go-version: "^1.20"
- name: Test code
run: go test ./... -covermode=atomic -coverprofile=coverage.out
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
verify-helm-readme:
name: Verify that Helm README is up to date
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Node 18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install README generator
run: make install-helm-readme
- name: Generate README
run: make helm-readme
- name: Verify that there are no changes
run: git diff --exit-code || echo "README.md is not up to date. Please use helm-readme and commit the changes."
lint-helm-chart:
name: Lint Helm chart
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: 3.11.0
- name: Lint Helm chart
working-directory: ./chart
run: helm lint .
template-helm-chart:
name: Verify templating chart with default values
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: 3.11.2
- name: Template Helm chart
working-directory: ./chart
run: helm template . > /dev/null
test-integration:
name: Test integration with Prometheus
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Compose
uses: ndeloof/[email protected]
with:
version: v2.15.1
legacy: true
- name: Print compose version
run: docker-compose version
- name: Wait for compose
run: make wait-for-compose
- name: Run metrics integration test
run: make verify-metrics
- name: Generate metric names for README
run: ./scripts/add_metrics_to_readme.sh
- name: Verify that there are no changes
run: git diff --exit-code || echo "README.md is not up to date. Please use add_metrics_to_readme.sh and commit the changes."
- name: Shutdown compose
run: docker-compose down -v
build-linux:
name: Build Linux binary
runs-on: ubuntu-20.04
needs: [lint, test]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v4
with:
go-version: "^1.20"
- name: Build Linux binary
run: make build-linux
env:
VERSION: ${{ github.ref }}
- name: Upload Linux binary
uses: actions/upload-artifact@v3
with:
name: logstash-exporter-linux
path: out/main-linux
build-darwin:
name: Build Mac binary
runs-on: ubuntu-20.04
needs: [lint, test]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v4
with:
go-version: "^1.20"
- name: Build Mac binary
run: make build-darwin
env:
VERSION: ${{ github.ref }}
- name: Upload Mac binary
uses: actions/upload-artifact@v3
with:
name: logstash-exporter-darwin
path: out/main-darwin
build-windows:
name: Build Windows binary
runs-on: ubuntu-20.04
needs: [lint, test]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v4
with:
go-version: "^1.20"
- name: Build Windows binary
run: make build-windows
env:
VERSION: ${{ github.ref }}
- name: Upload Windows binary
uses: actions/upload-artifact@v3
with:
name: logstash-exporter-windows
path: out/main-windows
build-linux-docker-image:
name: Build Linux Docker image
runs-on: ubuntu-20.04
needs: [build-linux]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build Docker image
run: make build-docker
- name: Package Docker image
run: docker save logstash-exporter:latest | gzip > logstash-exporter.tar.gz
- name: Upload Docker image as an artifact
uses: actions/upload-artifact@v3
with:
name: logstash-exporter-docker-image
path: logstash-exporter.tar.gz
retention-days: 1
- name: Login to GitHub registry
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master'
run: echo ${{ secrets.GH_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
- name: Login to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ secrets.DOCKER_HUB_PAT }} | docker login -u ${{ github.repository_owner }} --password-stdin
- name: Tag Docker image with master
if: github.ref == 'refs/heads/master'
run: docker tag logstash-exporter:latest ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:master
- name: Tag Docker image with tag to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: docker tag logstash-exporter:latest ${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
- name: Tag Docker image with tag to ghcr.io
if: startsWith(github.ref, 'refs/tags/')
run: docker tag logstash-exporter:latest ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
- name: Push Docker image to GitHub registry
if: github.ref == 'refs/heads/master'
run: docker push ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:master
- name: Push Docker image with tag to Docker Hub
if: startsWith(github.ref, 'refs/tags/')
run: docker push ${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
- name: Push Docker image with tag to ghcr.io
if: startsWith(github.ref, 'refs/tags/')
run: docker push ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ env.TAG_NAME }}
test-helm-integration:
name: Test integration with Helm chart
runs-on: ubuntu-20.04
needs:
- verify-helm-readme
- lint-helm-chart
- template-helm-chart
- build-linux-docker-image
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download Docker image
uses: actions/download-artifact@v3
with:
name: logstash-exporter-docker-image
path: .helm/files
- name: Load Docker image
run: docker load -i .helm/files/logstash-exporter.tar.gz
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: 3.11.2
- name: Include current chart versions
working-directory: .helm/logstash-integration-test-chart
run: helm dependency update
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
cluster_name: kind-chart-testing
- name: Export Docker image to Kind cluster
run: kind load docker-image logstash-exporter:latest --name kind-chart-testing
- name: Install Helm chart
working-directory: .helm/logstash-integration-test-chart
run: helm install --atomic --wait --timeout 15m --debug logstash-integration-test-chart .
create-release:
name: Create GitHub release
runs-on: ubuntu-20.04
permissions:
contents: write
packages: write
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
release_id: ${{ steps.create_release.outputs.id }}
needs:
- build-linux
- build-darwin
- build-windows
- build-linux-docker-image
- test-integration
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Output tag information
run: |
echo "Tag name: ${{ env.TAG_NAME }}"
echo "Tag ref: ${{ github.ref }}"
- name: Generate release notes
run: ./scripts/create_release_notes.sh
- name: Create GitHub release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body_path: "./release_notes.txt"
draft: false
prerelease: false
upload-binaries:
strategy:
matrix:
binary: [linux, darwin, windows]
runs-on: ubuntu-20.04
needs:
- create-release
- build-linux
- build-darwin
- build-windows
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download binary
uses: actions/download-artifact@v3
with:
name: logstash-exporter-${{ matrix.binary }}
- name: Generate sha256 checksum
run: |
CHECKSUM_FILE="main-${{ matrix.binary }}.sha256"
sha256sum main-${{ matrix.binary }} | cut -d ' ' -f1 | tr -d $'\n' > "$CHECKSUM_FILE"
echo -n ' logstash-exporter-${{ matrix.binary }}' >> "$CHECKSUM_FILE"
- name: Upload binary to GitHub release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: main-${{ matrix.binary }}
asset_name: logstash-exporter-${{ matrix.binary }}
asset_content_type: application/octet-stream
- name: Upload sha256 checksum to GitHub release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: main-${{ matrix.binary }}.sha256
asset_name: logstash-exporter-${{ matrix.binary }}.sha256
asset_content_type: text/plain