-
Notifications
You must be signed in to change notification settings - Fork 55
311 lines (287 loc) · 9.24 KB
/
ci.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
name: ci
on: [push, pull_request]
jobs:
setup:
runs-on: ubuntu-latest
outputs:
version-tag: ${{ steps.regex-match.outputs.match }}
steps:
- uses: actions-ecosystem/action-regex-match@v2
id: regex-match
with:
text: ${{ github.ref_name }}
regex: '^v[0-9]+(\.[0-9]+)*(-[a-zA-Z0-9-]+)?$'
- name: Print setup
run: |
echo github.ref=${{ github.ref }}
echo github.ref_name=${{ github.ref_name }}
echo github.ref_type=${{ github.ref_type }}
echo release-ref=${{ steps.regex-match.outputs.match }}
test010:
runs-on: ubuntu-latest
container:
image: cimg/go:1.19
env:
GO111MODULE: "on"
KAFKA_TOPICS_TEST_ZK_ADDR: zookeeper:2181
KAFKA_TOPICS_TEST_KAFKA_ADDR: kafka1:9092
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Go setup
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Display Go version
run: go version
- name: Run tests
run: make test
env:
KAFKA_TOPICS_TEST_ZK_ADDR: zookeeper:2181
KAFKA_TOPICS_TEST_KAFKA_ADDR: kafka1:9092
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka1:
image: wurstmeister/kafka:2.11-0.10.2.2
ports:
- "9092:9092"
env:
KAFKA_BROKER_ID: 1
KAFKA_BROKER_RACK: zone1
KAFKA_ADVERTISED_HOST_NAME: kafka1
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
kafka2:
image: wurstmeister/kafka:2.11-0.10.2.2
ports:
- "9093:9092"
env:
KAFKA_BROKER_ID: 2
KAFKA_BROKER_RACK: zone1
KAFKA_ADVERTISED_HOST_NAME: kafka2
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
kafka3:
image: wurstmeister/kafka:2.11-0.10.2.2
ports:
- "9094:9092"
env:
KAFKA_BROKER_ID: 3
KAFKA_BROKER_RACK: zone2
KAFKA_ADVERTISED_HOST_NAME: kafka3
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
kafka4:
image: wurstmeister/kafka:2.11-0.10.2.2
ports:
- "9095:9092"
env:
KAFKA_BROKER_ID: 4
KAFKA_BROKER_RACK: zone2
KAFKA_ADVERTISED_HOST_NAME: kafka4
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
kafka5:
image: wurstmeister/kafka:2.11-0.10.2.2
ports:
- "9096:9092"
env:
KAFKA_BROKER_ID: 5
KAFKA_BROKER_RACK: zone3
KAFKA_ADVERTISED_HOST_NAME: kafka5
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
kafka6:
image: wurstmeister/kafka:2.11-0.10.2.2
ports:
- "9097:9092"
env:
KAFKA_BROKER_ID: 6
KAFKA_BROKER_RACK: zone3
KAFKA_ADVERTISED_HOST_NAME: kafka6
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
test271:
runs-on: ubuntu-latest
container:
image: cimg/go:1.19
env:
GO111MODULE: "on"
KAFKA_TOPICS_TEST_ZK_ADDR: zookeeper:2181
KAFKA_TOPICS_TEST_KAFKA_ADDR: kafka1:9092
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Go setup
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Display Go version
run: go version
- name: Run tests
run: make test-v2
env:
KAFKA_TOPICS_TEST_ZK_ADDR: zookeeper:2181
KAFKA_TOPICS_TEST_KAFKA_ADDR: kafka1:9092
KAFKA_TOPICS_TEST_BROKER_ADMIN_SECURITY: 1
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka1:
image: wurstmeister/kafka:2.13-2.7.1
ports:
- "9092:9092"
env:
KAFKA_BROKER_ID: 1
KAFKA_BROKER_RACK: zone1
KAFKA_ADVERTISED_HOST_NAME: kafka1
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.auth.SimpleAclAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: true
kafka2:
image: wurstmeister/kafka:2.13-2.7.1
ports:
- "9093:9092"
env:
KAFKA_BROKER_ID: 2
KAFKA_BROKER_RACK: zone1
KAFKA_ADVERTISED_HOST_NAME: kafka2
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.auth.SimpleAclAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: true
kafka3:
image: wurstmeister/kafka:2.13-2.7.1
ports:
- "9094:9092"
env:
KAFKA_BROKER_ID: 3
KAFKA_BROKER_RACK: zone2
KAFKA_ADVERTISED_HOST_NAME: kafka3
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.auth.SimpleAclAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: true
kafka4:
image: wurstmeister/kafka:2.13-2.7.1
ports:
- "9095:9092"
env:
KAFKA_BROKER_ID: 4
KAFKA_BROKER_RACK: zone2
KAFKA_ADVERTISED_HOST_NAME: kafka4
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.auth.SimpleAclAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: true
kafka5:
image: wurstmeister/kafka:2.13-2.7.1
ports:
- "9096:9092"
env:
KAFKA_BROKER_ID: 5
KAFKA_BROKER_RACK: zone3
KAFKA_ADVERTISED_HOST_NAME: kafka5
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.auth.SimpleAclAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: true
kafka6:
image: wurstmeister/kafka:2.13-2.7.1
ports:
- "9097:9092"
env:
KAFKA_BROKER_ID: 6
KAFKA_BROKER_RACK: zone3
KAFKA_ADVERTISED_HOST_NAME: kafka6
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.auth.SimpleAclAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: true
snyk:
runs-on: ubuntu-latest
needs: [test010, test271]
steps:
- uses: actions/checkout@v3
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/golang@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high --fail-on=upgradable
publish-ghcr:
needs: [setup, snyk]
runs-on: ubuntu-latest
if: ${{ ( github.ref_type == 'branch' ) && (( github.ref_name == 'master' ) || ( github.ref_name == 'v0' )) }}
steps:
- uses: actions/checkout@v3
- name: setup env variables
id: vars
run: |
echo "SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
- run: echo "publishing the image ghcr.io/segmentio/topicctl:${SHORT_SHA}"
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: true
- run: echo "GHCR LOGIN SUCCESSFUL"
- if: ${{ github.ref_name == 'master' }}
name: Build and push image for master
run: |
docker context create buildx-build
docker buildx create --use buildx-build
docker buildx build \
-t ghcr.io/segmentio/topicctl:${SHORT_SHA} \
-t ghcr.io/segmentio/topicctl:latest \
--build-arg VERSION=${SHORT_SHA} \
--push \
.
- if: ${{ github.ref_name == 'v0' }}
name: Build and push image for v0
run: |
docker context create buildx-build
docker buildx create --use buildx-build
docker buildx build \
-t ghcr.io/segmentio/topicctl:${SHORT_SHA} \
--build-arg VERSION=${SHORT_SHA} \
--push \
.
- run: echo "GHCR PUBLISH SUCCESSFUL"
publish-dockerhub:
needs: [setup, snyk]
environment: CICD
env:
RELEASE_TAG: ${{ needs.setup.outputs.version-tag }}
runs-on: ubuntu-latest
if: ${{ ( github.ref_type == 'tag' ) && ( needs.setup.outputs.version-tag != '') }}
steps:
- uses: actions/checkout@v3
- run: echo "publishing the release version segment/topicctl:${RELEASE_TAG}"
- name: Dockerhub login
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
logout: true
- run: echo "DOCKERHUB LOGIN SUCCESSFUL"
- name: Build and push image
run: |
docker context create buildx-build
docker buildx create --use buildx-build
docker buildx build \
--platform=linux/amd64,linux/arm64 \
-t segment/topicctl:${RELEASE_TAG} \
-t segment/topicctl:latest \
--build-arg VERSION=${RELEASE_TAG} \
--push \
.
- run: echo "DOCKERHUB PUBLISH SUCCESSFUL"