-
Notifications
You must be signed in to change notification settings - Fork 34
274 lines (252 loc) · 9.18 KB
/
publish.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
name: Publish
on:
- push
- workflow_dispatch
jobs:
check-dockerhub-token:
runs-on: ubuntu-latest
outputs:
HAS_DOCKERHUB_TOKEN: ${{ steps.gh-token.outputs.HAS_DOCKERHUB_TOKEN }}
steps:
- id: gh-token
env:
HAS_DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN != '' }}
run: |
echo "HAS_DOCKERHUB_TOKEN=$HAS_DOCKERHUB_TOKEN" >> $GITHUB_OUTPUT
echo "HAS_DOCKERHUB_TOKEN=$HAS_DOCKERHUB_TOKEN" >> $GITHUB_STEP_SUMMARY
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: install and run golangci-lint
uses: golangci/golangci-lint-action@v6.1.1
with:
version: v1.56.2
args: --timeout=3m
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Download K8s envtest - local K8s cluster control plane
run: |
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
mkdir -p local/envtest-bin/
setup-envtest use -p env 1.30.x --bin-dir local/envtest-bin > local/envtest-bin/env
- name: Run Unit tests @
run: |
source local/envtest-bin/env
export KUBEBUILDER_ASSETS=$(pwd)/$KUBEBUILDER_ASSETS
go test -race -covermode atomic -coverprofile=profile.cov ./...
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
go install github.com/mattn/goveralls@v0.0.11
goveralls -coverprofile=profile.cov -service=github
test-helm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: v3.5.0
- uses: actions/setup-python@v5
with:
python-version: 3.7
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.6.1
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- uses: ko-build/setup-ko@v0.7
name: Setup ko
env:
KO_DOCKER_REPO: ko.local
- name: Run ko publish
run: |
export REF=${{ github.ref}}
export COMMIT=${{ github.sha}}
ko publish ./cmd/kubelet-csr-approver/ --base-import-paths --platform=linux/amd64 --local
- name: Run chart-testing (lint)
run: ct lint --target-branch=main --check-version-increment=false --chart-dirs=charts
- name: Create kind cluster
uses: helm/kind-action@v1.10.0
with:
cluster_name: kind
- name: Load image
run: kind load docker-image ko.local/kubelet-csr-approver:latest
- name: Update chart values
run: |
sed -i \
-e 's|repository:.*|repository: ko.local/kubelet-csr-approver|g' \
-e 's|tag:.*|tag: latest|g' \
-e 's|providerRegex:.*|providerRegex: ^.+$|g' \
-e 's|maxExpirationSeconds:.*|maxExpirationSeconds: "86400"|g' \
-e 's|bypassDnsResolution:.*|bypassDnsResolution: true|g' \
-e 's|providerIpPrefixes:.*|providerIpPrefixes: [ '192.168.8.0/22', 'fc00::/7' ]|g' \
charts/kubelet-csr-approver/values.yaml
cat charts/kubelet-csr-approver/values.yaml
- name: Run chart-testing (install)
run: ct install --target-branch=main --chart-dirs=charts
publish-tagged:
needs:
- lint
- test
- check-dockerhub-token
if: |
startsWith(github.ref, 'refs/tags/v') &&
!github.event.pull_request.head.repo.fork &&
needs.check-dockerhub-token.outputs.HAS_DOCKERHUB_TOKEN == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- uses: ko-build/setup-ko@v0.7
name: Setup ko
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: postfinance
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Run ko publish for docker.io
env:
KO_DOCKER_REPO: docker.io/postfinance
run: |
export REF=${{ github.ref}}
export COMMIT=${{ github.sha}}
export TAG=$(echo ${{ github.ref }} | cut -d "/" -f 3 - )
ko publish ./cmd/kubelet-csr-approver/ --base-import-paths --platform=linux/amd64,linux/arm64,linux/arm --tags $TAG
ko publish ./cmd/kubelet-csr-approver/ --base-import-paths --platform=linux/amd64,linux/arm64,linux/arm
- name: Log in to ghcr.io registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Run ko publish for ghcr.io/postfinance
env:
KO_DOCKER_REPO: ghcr.io/postfinance
run: |
export REF=${{ github.ref}}
export COMMIT=${{ github.sha}}
export TAG=$(echo ${{ github.ref }} | cut -d "/" -f 3 - )
ko publish ./cmd/kubelet-csr-approver/ --base-import-paths --platform=linux/amd64,linux/arm64,linux/arm --tags $TAG
ko publish ./cmd/kubelet-csr-approver/ --base-import-paths --platform=linux/amd64,linux/arm64,linux/arm
publish-helm-charts:
needs:
- lint
- test-helm
- check-dockerhub-token
if: |
startsWith(github.ref, 'refs/tags/v') &&
!github.event.pull_request.head.repo.fork &&
needs.check-dockerhub-token.outputs.HAS_DOCKERHUB_TOKEN == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Install Helm
uses: azure/setup-helm@v4
with:
version: v3.5.0
- name: Prepare version
run: |
export TAG=$(echo ${{ github.ref }} | cut -d '/' -f 3 - )
export VERSION=${TAG#v}
echo TAG=${TAG} >> $GITHUB_ENV
echo VERSION=${VERSION} >> $GITHUB_ENV
echo "TAG: ${TAG}"
echo "VERSION: ${VERSION}"
- name: Run chart-releaser
uses: stefanprodan/helm-gh-pages@v1.7.0
with:
token: "${{ secrets.GITHUB_TOKEN }}"
app_version: "${{env.TAG}}"
chart_version: "${{env.VERSION}}"
publish-untagged:
needs:
- lint
- test
- check-dockerhub-token
if: |
github.ref == 'refs/heads/main' &&
!github.event.pull_request.head.repo.fork &&
needs.check-dockerhub-token.outputs.HAS_DOCKERHUB_TOKEN == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- uses: ko-build/setup-ko@v0.7
name: Setup ko
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: postfinance
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Run ko publish for docker.io
env:
KO_DOCKER_REPO: docker.io/postfinance
run: |
export REF=${{ github.ref}}
export COMMIT=${{ github.sha}}
ko publish ./cmd/kubelet-csr-approver/ --base-import-paths --platform=linux/amd64,linux/arm64,linux/arm -t dev
- name: Log in to ghcr.io registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Run ko publish for ghcr.io/postfinance
env:
KO_DOCKER_REPO: ghcr.io/postfinance
run: |
export REF=${{ github.ref}}
export COMMIT=${{ github.sha}}
ko publish ./cmd/kubelet-csr-approver/ --base-import-paths --platform=linux/amd64,linux/arm64,linux/arm -t dev
publish-feature:
needs:
- lint
- test
- check-dockerhub-token
if: |
startsWith(github.ref, 'refs/heads/feat') &&
!github.event.pull_request.head.repo.fork &&
needs.check-dockerhub-token.outputs.HAS_DOCKERHUB_TOKEN == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: postfinance
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: ko-build/setup-ko@v0.7
name: Setup ko
- name: Run ko publish for docker.io
env:
KO_DOCKER_REPO: docker.io/postfinance
run: |
export REF=${{ github.ref}}
export COMMIT=${{ github.sha}}
export FEAT=$(echo $REF | awk -F 'feat/' '{print $2}')
ko publish ./cmd/kubelet-csr-approver/ --base-import-paths --platform=linux/amd64,linux/arm64,linux/arm -t $FEAT
- name: Log in to ghcr.io registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Run ko publish for ghcr.io/postfinance
env:
KO_DOCKER_REPO: ghcr.io/postfinance
run: |
export REF=${{ github.ref}}
export COMMIT=${{ github.sha}}
export FEAT=$(echo $REF | awk -F 'feat/' '{print $2}')
ko publish ./cmd/kubelet-csr-approver/ --base-import-paths --platform=linux/amd64,linux/arm64,linux/arm -t $FEAT