-
Notifications
You must be signed in to change notification settings - Fork 4
262 lines (221 loc) · 9.91 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
name: Build and Deploy Images
on:
push:
paths-ignore:
- "docs/**"
- "*.md"
- "deploy/helm/*.md"
tags:
- '*.*.*'
pull_request:
branches:
- master
- release/**
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: Create k8s Kind Cluster
uses: helm/[email protected]
with:
version: v0.24.0
kubectl_version: v1.31.0
node_image: kindest/node:v1.31.0
cluster_name: kind
- name: Add dependency chart repos
run: |
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm repo add jetstack https://charts.jetstack.io
- 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: Copy image to Kind cluster
run: |
kind load docker-image $(jq -r '.builds[] | select(.imageName=="integration-test") | .tag' /tmp/tags.json)
kind load docker-image $(jq -r '.builds[] | select(.imageName=="swi-k8s-opentelemetry-collector") | .tag' /tmp/tags.json)
kind load docker-image $(jq -r '.builds[] | select(.imageName=="swi-k8s-opentelemetry-collector-tests") | .tag' /tmp/tags.json)
- name: Setup kubetail
run: |
curl -Lo kubetail https://raw.githubusercontent.com/johanhaleby/kubetail/master/kubetail && sudo install kubetail /usr/local/bin/
shell: bash
- name: Deploy services using Skaffold
run: skaffold deploy --build-artifacts=/tmp/tags.json --kube-context kind-kind
- name: Show all resources
if: ${{ failure() }}
run: |
kubectl get all -n test-namespace
- name: Run integration tests
uses: ./.github/actions/run-integration-tests
build_and_test_windows:
runs-on: windows-2022
if: startsWith(github.ref, 'refs/tags/') && !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-2022 .
- name: CP assets
run: |
docker create --name assets swi-k8s-opentelemetry-collector:${{ steps.generate-tag.outputs.value }}-nanoserver-ltsc2022
docker cp assets:/swi-otelcol.exe swi-otelcol.exe
docker cp assets:/wrapper.exe wrapper.exe
- name: Build 2019
run: |
docker build -t swi-k8s-opentelemetry-collector:${{ steps.generate-tag.outputs.value }}-nanoserver-ltsc2019 --build-arg WINBASE=mcr.microsoft.com/windows/nanoserver:ltsc2019 -f build/docker/Dockerfile.Windows-Runtime .
- name: Save image
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'swo-k8s-collector')
run: |
docker save --output swi-k8s-opentelemetry-collector-windows-ltsc2022.tar swi-k8s-opentelemetry-collector:${{ steps.generate-tag.outputs.value }}-nanoserver-ltsc2022
docker save --output swi-k8s-opentelemetry-collector-windows-ltsc2019.tar swi-k8s-opentelemetry-collector:${{ steps.generate-tag.outputs.value }}-nanoserver-ltsc2019
- uses: actions/upload-artifact@v3
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'swo-k8s-collector')
with:
name: image
path: |
swi-k8s-opentelemetry-collector-windows-ltsc2022.tar
swi-k8s-opentelemetry-collector-windows-ltsc2019.tar
retention-days: 2
deploy_dockerhub:
runs-on: ubuntu-latest
needs: build_and_test
name: Deploy to docker hub
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, 'swo-k8s-collector')
environment:
name: production
url: https://hub.docker.com/repository/docker/solarwinds/swi-opentelemetry-collector
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get image tag
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.OPENTELEMETRY_DOCKER_HUB_CI_USER }}
password: ${{ secrets.OPENTELEMETRY_DOCKER_HUB_CI_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: build/docker/Dockerfile
platforms: linux/amd64,linux/arm64
provenance: false
sbom: false
push: true
tags: ${{ 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: startsWith(github.ref, 'refs/tags/') && !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-ltsc2022.tar
docker load --input swi-k8s-opentelemetry-collector-windows-ltsc2019.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
docker tag swi-k8s-opentelemetry-collector:${{ needs.build_and_test_windows.outputs.image_tag }}-nanoserver-ltsc2019 ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }}-nanoserver-ltsc2019
- name: Docker login
env:
OPENTELEMETRY_DOCKER_HUB_CI_PASSWORD: ${{ secrets.OPENTELEMETRY_DOCKER_HUB_CI_PASSWORD }}
OPENTELEMETRY_DOCKER_HUB_CI_USER: ${{ secrets.OPENTELEMETRY_DOCKER_HUB_CI_USER }}
run: echo "$env:OPENTELEMETRY_DOCKER_HUB_CI_PASSWORD" | docker login -u "$env:OPENTELEMETRY_DOCKER_HUB_CI_USER" --password-stdin
- name: Push as specific
run: |
docker push ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }}-nanoserver-ltsc2022
docker push ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }}-nanoserver-ltsc2019
create_and_push_manifest:
runs-on: ubuntu-latest
name: Create Multi-platform Docker Manifest
needs:
- deploy_dockerhub_windows
- deploy_dockerhub
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get image tag
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.OPENTELEMETRY_DOCKER_HUB_CI_USER }}
password: ${{ secrets.OPENTELEMETRY_DOCKER_HUB_CI_PASSWORD }}
- name: Get linux manifest
run: |
docker manifest inspect ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }} > manifest.json
- name: Create multi-arch manifest
run: |
docker manifest create ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }} \
--amend ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }}-nanoserver-ltsc2022 \
--amend ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }}-nanoserver-ltsc2019 \
--amend ${{ env.DOCKERHUB_IMAGE }}@$(jq -r '.manifests[] | select(.platform.os == "linux" and .platform.architecture == "amd64") | .digest' manifest.json) \
--amend ${{ env.DOCKERHUB_IMAGE }}@$(jq -r '.manifests[] | select(.platform.os == "linux" and .platform.architecture == "arm64") | .digest' manifest.json)
- name: Push multi-arch manifest
run: |
docker manifest push ${{ env.DOCKERHUB_IMAGE }}:${{ steps.vars.outputs.tag }}
create_release:
runs-on: ubuntu-latest
name: Create GitHub Release
needs:
- create_and_push_manifest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Find previous tag
run: |
CURRENT_TAG=${GITHUB_REF#refs/tags/}
PREVIOUS_TAG=$(git tag --sort=version:refname | grep -B1 "^${CURRENT_TAG}$" | head -n 1)
echo "Previous tag: $PREVIOUS_TAG"
echo "PREVIOUS_TAG=$PREVIOUS_TAG" >> $GITHUB_ENV
- name: Get current tag
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Create Github Release
env:
# for gh cli
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ steps.vars.outputs.tag }} \
--title ${{ steps.vars.outputs.tag }} \
--latest=false \
--generate-notes \
--notes-start-tag ${{ env.PREVIOUS_TAG }}