-
Notifications
You must be signed in to change notification settings - Fork 4
228 lines (196 loc) · 7.62 KB
/
build-image.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
name: Build, test and publish
on:
push:
branches: [ "**" ]
tags: [ "v*.*.*" ]
permissions:
contents: write
id-token: write
packages: write
jobs:
changes:
if: ${{ github.repository == 'danfromtitan/envars-from-node-labels' }}
runs-on: ubuntu-latest
outputs:
build: ${{ steps.filter.outputs.build }}
chart: ${{ steps.filter.outputs.chart }}
test: ${{ steps.filter.outputs.test }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
base: ${{ github.ref }}
filters: |
build:
- 'cmd/envars-webhook/*'
- 'Dockerfile'
- 'go.mod'
- 'Makefile'
chart:
- 'charts/envars-webhook/**/*'
test:
- '.github/**/*'
- 'test/*'
build:
needs: changes
if: |
(github.repository == 'danfromtitan/envars-from-node-labels') &&
(needs.changes.outputs.build == 'true')
runs-on: ubuntu-latest
outputs:
image-tag: ${{ steps.image-output.outputs.image-tag }}
image-name: ${{ steps.image-output.outputs.image-name }}
image-digest: ${{ steps.image-output.outputs.image-digest }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 1.19
cache: true
- uses: docker/metadata-action@v5
id: meta
with:
images: |
ghcr.io/danfromtitan/envars-from-node-labels
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix=${{ github.ref_name }}-
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: go install github.com/mitchellh/gox@latest
- run: make build-all
- uses: docker/build-push-action@v5
id: docker-build
with:
context: ./
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- id: image-output
run: |
echo image-tag=$(echo '${{ steps.docker-build.outputs.metadata }}' | jq -r '."image.name" | split(",")[-1] | split(":")[-1]') >>$GITHUB_OUTPUT
echo image-name=$(echo '${{ steps.docker-build.outputs.metadata }}' | jq -r '."image.name"') >>$GITHUB_OUTPUT
echo image-digest=${{ steps.docker-build.outputs.digest }} >>$GITHUB_OUTPUT
chart:
needs: changes
permissions:
contents: write
if: |
(github.repository == 'danfromtitan/envars-from-node-labels') &&
(needs.changes.outputs.chart == 'true')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: configure git
run: |
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "[email protected]"
- name: lint helm chart
run: |
helm lint ./charts/envars-webhook
- uses: helm/[email protected]
with:
charts_dir: charts
env:
CR_RELEASE_NAME_TEMPLATE: "helm-chart-{{ .Version }}"
CR_SKIP_EXISTING: "true"
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
test:
needs: [build, changes, chart]
if: |
always() &&
(github.repository == 'danfromtitan/envars-from-node-labels') &&
(needs.changes.outputs.build == 'true' || needs.changes.outputs.chart == 'true' || needs.changes.outputs.test == 'true')
runs-on: ubuntu-latest
steps:
- uses: medyagh/setup-minikube@master
id: minikube
with:
minikube-version: 1.23.2
driver: docker
container-runtime: containerd
kubernetes-version: v1.22.10
- uses: actions/checkout@v4
- name: setup helm
run: |
curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
helm repo add envars-webhook https://danfromtitan.github.io/envars-from-node-labels/
helm repo update
helm search repo envars-webhook -l
- name: deploy webhook
timeout-minutes: 2
env:
NAMESPACE: webtest
run: |
IMAGE_TAG=latest
[[ "${{contains(needs.build.result, 'success') }}" == "true" ]] && IMAGE_TAG=${{ needs.build.outputs.image-tag }}
helm install -n $NAMESPACE --create-namespace envars-webhook envars-webhook/envars-webhook --set image.tag="$IMAGE_TAG" \
--set webhook.containersAllowed.ingester=true,webhook.containersAllowed.prober=true,webhook.containersAllowed.store-gateway=true
until kubectl get pods -n $NAMESPACE | grep "Running" > /dev/null; do
kubectl get pods -n $NAMESPACE | tail -n +2
sleep 1
done
- name: stage samples
run: |
make sample
- name: verify pod-allowed
timeout-minutes: 2
env:
NAMESPACE: samples
run: |
kubectl apply -f test/pod-allowed.yaml
until kubectl get pods -n $NAMESPACE | grep "pod-allowed" | grep "Completed" > /dev/null; do sleep 1; done
kubectl logs -n $NAMESPACE pod-allowed | grep "NODE_MINIKUBE_K8S_IO_NAME" > /dev/null
- name: verify pod-excluded
timeout-minutes: 2
env:
NAMESPACE: samples
run: |
kubectl apply -f test/pod-excluded.yaml
until kubectl get pods -n $NAMESPACE | grep "pod-excluded" | grep "Completed" > /dev/null; do sleep 1; done
kubectl logs -n $NAMESPACE pod-excluded | grep -v "NODE_MINIKUBE_K8S_IO_NAME" > /dev/null
- name: verify pod-mixed
timeout-minutes: 2
env:
NAMESPACE: samples
run: |
kubectl apply -f test/pod-mixed.yaml
until kubectl get pods -n $NAMESPACE | grep "pod-mixed" | grep "Completed" > /dev/null; do sleep 1; done
kubectl logs -n $NAMESPACE pod-mixed ingester | grep "NODE_MINIKUBE_K8S_IO_NAME" > /dev/null
kubectl logs -n $NAMESPACE pod-mixed store-gateway | grep "NODE_MINIKUBE_K8S_IO_NAME" > /dev/null
kubectl logs -n $NAMESPACE pod-mixed compactor | grep -v "NODE_MINIKUBE_K8S_IO_NAME" > /dev/null
- name: verify deployment
timeout-minutes: 2
env:
NAMESPACE: samples
run: |
kubectl apply -f test/deployment.yaml
until [[ $(kubectl get pods -n $NAMESPACE | grep "deployment" | grep "Running" | wc -l) == "2" ]]; do sleep 1; done
for POD in $(kubectl get pods -n $NAMESPACE | grep "deployment" | awk '{print $1}'); do
kubectl logs -n $NAMESPACE $POD prober | grep "NODE_MINIKUBE_K8S_IO_NAME"
kubectl exec -n $NAMESPACE $POD -c ingester -- env | grep "NODE_MINIKUBE_K8S_IO_NAME"
done
- name: verify statefulset
timeout-minutes: 2
env:
NAMESPACE: samples
run: |
kubectl apply -f test/statefulset.yaml
until [[ $(kubectl get pods -n $NAMESPACE | grep "statefulset" | grep "Running" | wc -l) == "2" ]]; do sleep 1; done
for POD in $(kubectl get pods -n $NAMESPACE | grep "statefulset" | awk '{print $1}'); do
kubectl logs -n $NAMESPACE $POD prober | grep "NODE_MINIKUBE_K8S_IO_NAME"
kubectl exec -n $NAMESPACE $POD -c store-gateway -- env | grep "NODE_MINIKUBE_K8S_IO_NAME"
done