-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·528 lines (450 loc) · 13.9 KB
/
build.sh
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#!/bin/bash
set -ex
# x86_64, aarch64
ARCH=$(uname -m)
SUPPORT_ARCH="x86_64 aarch64"
LD_DIR="${LD_DIR:-./LogDevice}"
HS_DIR="${HS_DIR:-./docker-haskell}"
HSTREAM_DIR="${HSTREAM_DIR:-./hstream}"
DOCKER_BIN="${DOCKER_BIN:-docker}" # e.g. set to podman
# -----------------------------------------------------------------------------
_gen_tag() {
tag="$1"
arch="$2"
if [ -z "$tag" ] || [ "$tag" = "latest" ]; then
echo "$arch"
else
echo "${tag}_$arch"
fi
}
_tag() {
image="$1"
old_tag="$2"
new_tag="$3"
for arch in $SUPPORT_ARCH; do
old_tag_=$(_gen_tag $old_tag $arch)
new_tag_=$(_gen_tag $new_tag $arch)
$DOCKER_BIN pull $image:$old_tag_
$DOCKER_BIN tag $image:$old_tag_ $image:$new_tag_
$DOCKER_BIN push $image:$new_tag_
done
}
_push_manifest() {
image="$1"
tag="$2"
[ -z "$image" ] && echo "No image!" && exit 1;
tag_x86="${tag}_x86_64"
tag_arm="${tag}_aarch64"
if [ -z "$tag" ] || [ "$tag" = "latest" ]; then
tag="latest"
tag_x86="x86_64"
tag_arm="aarch64"
fi
$DOCKER_BIN manifest rm $image:$tag || true
manifests="$image:${tag_x86}"
[ "$(docker pull $image:${tag_arm})" ] && \
manifests="$manifests $image:${tag_arm}" || true
$DOCKER_BIN manifest create $image:$tag $manifests
$DOCKER_BIN manifest push $image:$tag
}
# -----------------------------------------------------------------------------
setup() {
git clone --recurse-submodules https://github.com/hstreamdb/LogDevice.git
git clone --recurse-submodules https://github.com/hstreamdb/docker-haskell.git
git clone --recurse-submodules https://github.com/hstreamdb/hstream.git
cd $LD_DIR && git checkout -b stable origin/stable
}
# -----------------------------------------------------------------------------
# Outdated
#
# TODO: use buildx instead
build_logdevice_builder() {
cd $LD_DIR
git checkout stable
$DOCKER_BIN build . -f docker/Dockerfile.builder --tag hstreamdb/logdevice-builder:$ARCH
}
push_logdevice_builder() {
$DOCKER_BIN push hstreamdb/logdevice-builder:$ARCH
}
push_logdevice_builder_manifest() {
$DOCKER_BIN manifest rm hstreamdb/logdevice-builder || true
$DOCKER_BIN manifest create hstreamdb/logdevice-builder \
hstreamdb/logdevice-builder:x86_64 \
hstreamdb/logdevice-builder:aarch64
$DOCKER_BIN manifest push hstreamdb/logdevice-builder
}
tag_logdevice_builder() {
old_tag="latest"
new_tag="v3.3.0"
_tag hstreamdb/logdevice-builder $old_tag $new_tag
_push_manifest "hstreamdb/logdevice-builder" "$new_tag"
}
build_logdevice() {
cd $LD_DIR
git checkout stable
$DOCKER_BIN build . -f docker/Dockerfile --tag hstreamdb/logdevice:$ARCH
$DOCKER_BIN build . -f docker/Dockerfile --tag hstreamdb/logdevice-client:$ARCH --target client
}
push_logdevice() {
$DOCKER_BIN push hstreamdb/logdevice:$ARCH
$DOCKER_BIN push hstreamdb/logdevice-client:$ARCH
}
push_logdevice_manifest() {
$DOCKER_BIN manifest rm hstreamdb/logdevice || true
$DOCKER_BIN manifest rm hstreamdb/logdevice-client || true
$DOCKER_BIN manifest create hstreamdb/logdevice \
hstreamdb/logdevice:x86_64 \
hstreamdb/logdevice:aarch64
$DOCKER_BIN manifest push hstreamdb/logdevice
$DOCKER_BIN manifest create hstreamdb/logdevice-client \
hstreamdb/logdevice-client:x86_64 \
hstreamdb/logdevice-client:aarch64
$DOCKER_BIN manifest push hstreamdb/logdevice-client
}
tag_logdevice() {
old_tag="latest"
new_tag="v3.3.0"
_tag hstreamdb/logdevice $old_tag $new_tag
_push_manifest hstreamdb/logdevice $new_tag
_tag hstreamdb/logdevice-client $old_tag $new_tag
_push_manifest hstreamdb/logdevice-client $new_tag
}
# -----------------------------------------------------------------------------
build_logdevice_builder_rq() {
cd $LD_DIR
git checkout main
$DOCKER_BIN build . -f docker/Dockerfile.builder --tag hstreamdb/logdevice-builder:rqlite_$ARCH
}
push_logdevice_builder_rq() {
$DOCKER_BIN push hstreamdb/logdevice-builder:rqlite_$ARCH
}
push_logdevice_builder_manifest_rq() {
$DOCKER_BIN manifest rm hstreamdb/logdevice-builder:rqlite || true
$DOCKER_BIN manifest create hstreamdb/logdevice-builder:rqlite \
hstreamdb/logdevice-builder:rqlite_x86_64 \
hstreamdb/logdevice-builder:rqlite_aarch64
$DOCKER_BIN manifest push hstreamdb/logdevice-builder:rqlite
}
build_logdevice_rq() {
cd $LD_DIR
git checkout main
$DOCKER_BIN build . -f docker/Dockerfile --tag hstreamdb/logdevice:rqlite_$ARCH
$DOCKER_BIN build . -f docker/Dockerfile --tag hstreamdb/logdevice-client:rqlite_$ARCH --target client
}
push_logdevice_rq() {
$DOCKER_BIN push hstreamdb/logdevice:rqlite_$ARCH
$DOCKER_BIN push hstreamdb/logdevice-client:rqlite_$ARCH
}
push_logdevice_manifest_rq() {
_push_manifest "hstreamdb/logdevice" "rqlite"
_push_manifest "hstreamdb/logdevice-client" "rqlite"
}
# -----------------------------------------------------------------------------
GRPC=${GRPC:-1.54.2}
build_grpc() {
cd $HS_DIR
$DOCKER_BIN build . -f dockerfiles/grpc \
--build-arg GRPC=v${GRPC} \
-t ghcr.io/hstreamdb/grpc:${GRPC}_$ARCH
}
push_grpc() {
$DOCKER_BIN push ghcr.io/hstreamdb/grpc:${GRPC}_$ARCH
}
push_grpc_manifest() {
_push_manifest ghcr.io/hstreamdb/grpc "$GRPC"
}
# -----------------------------------------------------------------------------
_build_ghc() {
cd $HS_DIR
build_ghc="$1" # e.g. 9.2.8
tag="$2" # e.g. 9.2.8
tag1="$3" # e.g. 9.2
$DOCKER_BIN build . -f dockerfiles/ghc_from_haskell \
--build-arg GHC=$build_ghc \
-t ghcr.io/hstreamdb/ghc:${tag}_$ARCH \
-t ghcr.io/hstreamdb/ghc:${tag1}_$ARCH
}
_push_ghc() {
tag="$1" # e.g. 9.2.8
tag1="$2" # e.g. 9.2
$DOCKER_BIN push ghcr.io/hstreamdb/ghc:${tag}_$ARCH
$DOCKER_BIN push ghcr.io/hstreamdb/ghc:${tag1}_$ARCH
}
_push_ghc_latest_manifest() {
tag="$1" # e.g. 9.2.8
$DOCKER_BIN manifest rm ghcr.io/hstreamdb/ghc || true
$DOCKER_BIN manifest create ghcr.io/hstreamdb/ghc \
ghcr.io/hstreamdb/ghc:${tag}_x86_64 \
ghcr.io/hstreamdb/ghc:${tag}_aarch64
$DOCKER_BIN manifest push ghcr.io/hstreamdb/ghc
}
build_ghc810() {
_build_ghc 8.10.7 8.10.7 8.10
}
build_ghc902() {
_build_ghc 9.2.8 9.2.8 9.2
}
build_ghc904() {
_build_ghc 9.4.8 9.4.8 9.4
}
push_ghc810() {
_push_ghc 8.10.7 8.10
}
push_ghc902() {
_push_ghc 9.2.8 9.2
}
push_ghc904() {
_push_ghc 9.4.8 9.4
}
push_ghc810_manifest() {
_push_manifest ghcr.io/hstreamdb/ghc 8.10.7
_push_manifest ghcr.io/hstreamdb/ghc 8.10
}
push_ghc902_manifest() {
_push_manifest ghcr.io/hstreamdb/ghc 9.2.8
_push_manifest ghcr.io/hstreamdb/ghc 9.2
}
push_ghc904_manifest() {
_push_manifest ghcr.io/hstreamdb/ghc 9.4.8
_push_manifest ghcr.io/hstreamdb/ghc 9.4
}
push_ghc_latest_manifest() {
ghc=${@:2}
if [ -z "$ghc" ]; then
echo "Empty ghc"
exit 1
else
_push_ghc_latest_manifest $ghc
fi
}
# -----------------------------------------------------------------------------
# Outdated, TODO: remove
build_hsthrift() {
cd $HS_DIR
$DOCKER_BIN build . -f dockerfiles/hsthrift -t ghcr.io/hstreamdb/hsthrift:$ARCH
}
push_hsthrift() {
$DOCKER_BIN push ghcr.io/hstreamdb/hsthrift:$ARCH
}
push_hsthrift_manifest() {
$DOCKER_BIN manifest rm ghcr.io/hstreamdb/hsthrift || true
$DOCKER_BIN manifest create ghcr.io/hstreamdb/hsthrift \
ghcr.io/hstreamdb/hsthrift:x86_64 \
ghcr.io/hstreamdb/hsthrift:aarch64
$DOCKER_BIN manifest push ghcr.io/hstreamdb/hsthrift
}
# -----------------------------------------------------------------------------
# Outdated, TODO: remove
build_hadmin_store() {
cd $HS_DIR
$DOCKER_BIN build . -f dockerfiles/hadmin_store -t ghcr.io/hstreamdb/hadmin-store:$ARCH
}
push_hadmin_store() {
$DOCKER_BIN push ghcr.io/hstreamdb/hadmin-store:$ARCH
}
push_hadmin_store_manifest() {
_push_manifest ghcr.io/hstreamdb/hadmin-store
}
# -----------------------------------------------------------------------------
_build_haskell() {
cd $HS_DIR
ghc="$1"
ld_client="$2"
tag="$3"
tag1="$4"
$DOCKER_BIN build . -f Dockerfile \
--build-arg GHC=$ghc \
--build-arg LD_CLIENT_IMAGE=$ld_client \
--tag hstreamdb/haskell:${tag}_$ARCH \
--tag hstreamdb/haskell:${tag1}_$ARCH
}
build_haskell810() {
_build_haskell 8.10.7 hstreamdb/logdevice-client 8.10.7 8.10
}
build_haskell902() {
_build_haskell 9.2.8 hstreamdb/logdevice-client 9.2.8 9.2
}
build_haskell904() {
_build_haskell 9.4.8 hstreamdb/logdevice-client 9.4.8 9.4
}
build_haskell810_rq() {
_build_haskell 8.10.7 hstreamdb/logdevice-client:rqlite "rqlite_8.10.7" "rqlite_8.10"
}
build_haskell902_rq() {
_build_haskell 9.2.8 hstreamdb/logdevice-client:rqlite "rqlite_9.2.8" "rqlite_9.2"
}
build_haskell904_rq() {
_build_haskell 9.4.8 hstreamdb/logdevice-client:rqlite "rqlite_9.4.8" "rqlite_9.4"
}
_push_haskell() {
tag="$1"
tag1="$2"
$DOCKER_BIN push hstreamdb/haskell:${tag}_$ARCH
$DOCKER_BIN push hstreamdb/haskell:${tag1}_$ARCH
}
push_haskell810() {
_push_haskell 8.10.7 8.10
}
push_haskell902() {
_push_haskell 9.2.8 9.2
}
push_haskell904() {
_push_haskell 9.4.8 9.4
}
push_haskell810_rq() {
_push_haskell "rqlite_8.10.7" "rqlite_8.10"
}
push_haskell902_rq() {
_push_haskell "rqlite_9.2.8" "rqlite_9.2"
}
push_haskell904_rq() {
_push_haskell "rqlite_9.4.8" "rqlite_9.4"
}
_push_haskell_manifest(){
image="hstreamdb/haskell"
tag="$1"
tag1="$2"
$DOCKER_BIN manifest rm $image:$tag || true
$DOCKER_BIN manifest create $image:$tag \
$image:${tag}_x86_64 \
$image:${tag}_aarch64
$DOCKER_BIN manifest push $image:$tag
$DOCKER_BIN manifest rm $image:$tag1 || true
$DOCKER_BIN manifest create $image:$tag1 \
$image:${tag1}_x86_64 \
$image:${tag1}_aarch64
$DOCKER_BIN manifest push $image:$tag1
}
push_haskell810_manifest() {
_push_manifest hstreamdb/haskell 8.10.7
_push_manifest hstreamdb/haskell 8.10
}
push_haskell902_manifest() {
_push_manifest hstreamdb/haskell 9.2.8
_push_manifest hstreamdb/haskell 9.2
}
push_haskell904_manifest() {
_push_manifest hstreamdb/haskell 9.4.8
_push_manifest hstreamdb/haskell 9.4
}
push_haskell810_manifest_rq() {
_push_manifest hstreamdb/haskell "rqlite_8.10.7"
_push_manifest hstreamdb/haskell "rqlite_8.10"
}
push_haskell902_manifest_rq() {
_push_manifest hstreamdb/haskell "rqlite_9.2.8"
_push_manifest hstreamdb/haskell "rqlite_9.2"
}
push_haskell904_manifest_rq() {
_push_manifest hstreamdb/haskell "rqlite_9.4.8"
_push_manifest hstreamdb/haskell "rqlite_9.4"
}
_push_haskell_latest_manifest() {
image="hstreamdb/haskell"
tag="$1"
ghc="$2"
$DOCKER_BIN manifest rm $image:$tag || true
$DOCKER_BIN manifest create $image:$tag \
$image:${ghc}_x86_64 \
$image:${ghc}_aarch64
$DOCKER_BIN manifest push $image:$tag
}
push_haskell_latest_manifest() {
ghc=${@:2}
if [ -z "$ghc" ]; then
echo "Empty ghc"
exit 1
else
_push_haskell_latest_manifest latest $ghc
fi
}
push_haskell_latest_manifest_rq() {
ghc=${@:2}
if [ -z "$ghc" ]; then
echo "Empty ghc"
exit 1
else
_push_haskell_latest_manifest rqlite "rqlite_$ghc"
fi
}
# -----------------------------------------------------------------------------
HSTREAM_TAG="v0.16.0"
_build_hstream() {
cd $HSTREAM_DIR
hs_image="$1"
ld_image="$2"
image="$3"
tag="$4"
target="$5"
git_tag="$(git describe --tag --abbrev=0)"
git_commit="$(git rev-parse HEAD)"
# TODO: divede to x86_64 and aarch64
if [ "$ARCH" = "x86_64" ]; then
build_cache="cache"
else
build_cache="no_cache"
fi
if [ -n "$target" ]; then
target_arg="--target $target"
else
target_arg=""
fi
$DOCKER_BIN build . -f docker/Dockerfile \
--build-arg HS_IMAGE=$hs_image \
--build-arg LD_IMAGE=$ld_image \
--build-arg BUILD_CACHE=$build_cache \
--build-arg HSTREAM_VERSION=$git_tag \
--build-arg HSTREAM_VERSION_COMMIT=$git_commit \
$target_arg \
-t $image:$tag
}
rebuild_hstream_builder() {
cd $HSTREAM_DIR
hs_image="hstreamdb/haskell:9.2"
ld_image="hstreamdb/logdevice:latest"
git_tag="$(git describe --tag --abbrev=0)"
git_commit="$(git rev-parse HEAD)"
$DOCKER_BIN build . -f docker/Dockerfile \
--build-arg HS_IMAGE=$hs_image \
--build-arg LD_IMAGE=$ld_image \
--build-arg BUILD_CACHE="no_cache" \
--build-arg HSTREAM_VERSION=$git_tag \
--build-arg HSTREAM_VERSION_COMMIT=$git_commit \
--target builder \
-t hstreamdb/hstream-builder
}
build_hstream() {
_build_hstream "hstreamdb/haskell:9.2" "hstreamdb/logdevice:latest" \
"hstreamdb/hstream" "${HSTREAM_TAG}_$ARCH" ""
}
build_hstream_rq() {
_build_hstream "hstreamdb/haskell:rqlite_9.2" "hstreamdb/logdevice:rqlite" \
"hstreamdb/hstream" "rqlite_${HSTREAM_TAG}_$ARCH" ""
}
push_hstream() {
$DOCKER_BIN push hstreamdb/hstream:${HSTREAM_TAG}_$ARCH
}
push_hstream_rq() {
$DOCKER_BIN push hstreamdb/hstream:rqlite_${HSTREAM_TAG}_$ARCH
}
_pre_push_hstream() {
tag="$1"
$DOCKER_BIN pull hstreamdb/hstream:$tag
$DOCKER_BIN tag hstreamdb/hstream:$tag hstreamdb/hstream:${tag}_x86_64
$DOCKER_BIN push hstreamdb/hstream:${tag}_x86_64
}
pre_push_hstream() {
if [ "$ARCH" = "x86_64" ]; then
_pre_push_hstream "$HSTREAM_TAG"
_pre_push_hstream "rqlite_$HSTREAM_TAG"
else
echo "Only for x86_64!"
exit 1
fi
}
push_hstream_tag_manifest() {
_push_manifest "hstreamdb/hstream" "$HSTREAM_TAG"
_push_manifest "hstreamdb/hstream" "rqlite_$HSTREAM_TAG"
}
# -----------------------------------------------------------------------------
[ "$1" ] && $1 $@