-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-image
executable file
·90 lines (81 loc) · 2.2 KB
/
build-image
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
#!/usr/bin/env bash
set -e
__tag() {
local kafka="${1}"
local scala="${2}"
printf "${kafka}-${scala}"
}
DEFAULT_ARG_JRE='eclipse-temurin:17.0.5_8-jre-jammy'
DEFAULT_ARG_SCALA='2.13'
DEFAULT_ARG_KAFKA='3.3.1'
DEFAULT_ARG_TAG=$(__tag "${DEFAULT_ARG_SCALA}" "${DEFAULT_ARG_KAFKA}")
__show_help() {
echo "$0"
echo " -h, --help Display this message"
echo " -j, --jre <string> Set jre version (default ${DEFAULT_ARG_JRE})"
echo " -s, --scala <string> Set scala version (default ${DEFAULT_ARG_SCALA})"
echo " -k, --kafka <string> Set kafka version (default ${DEFAULT_ARG_KAFKA})"
echo " -t, --tag <string> Set image tag (default ${DEFAULT_ARG_TAG})"
echo " -p, --push Push image after build is complete"
echo " -l, --load Load image to local docker after build is complete"
}
ARG_JRE=$DEFAULT_ARG_JRE
ARG_SCALA=$DEFAULT_ARG_SCALA
ARG_KAFKA=$DEFAULT_ARG_KAFKA
ARG_TAG=
ARG_PUSH=
ARG_PLATFORM="--platform=linux/amd64,linux/arm64/v8"
while (($#)); do
case "${1}" in
-h|--help)
__show_help
exit 0
;;
-j|--jre)
ARG_JRE="${2}"
shift 2
;;
-s|--scala)
ARG_SCALA="${2}"
shift 2
;;
-k|--kafka)
ARG_KAFKA="${2}"
shift 2
;;
-t|--tag)
ARG_TAG="${2}"
shift 2
;;
-p|--push)
ARG_PUSH="--output=type=registry"
shift
;;
-l|--load)
ARG_PLATFORM=
ARG_PUSH="--output=type=docker"
shift
;;
*)
echo "Wrong arguments"
__show_help
exit 1
;;
esac
done
[ -z "${ARG_TAG}" ] && ARG_TAG=$(__tag "${ARG_KAFKA}" "${ARG_SCALA}")
IMAGE_NAME="moukoublen/kafka:${ARG_TAG}"
echo -e "\e[34m>>>\e[0m Building \e[34m${IMAGE_NAME}\e[0m"
echo -e " with jre \e[34m${ARG_JRE}\e[0m"
echo -e " with scala \e[34m${ARG_SCALA}\e[0m"
echo -e " with kafka \e[34m${ARG_KAFKA}\e[0m"
echo ""
#docker pull "${IMAGE_NAME}"
set -x
docker buildx build . \
${ARG_PUSH} \
${ARG_PLATFORM} \
--build-arg jre="${ARG_JRE}" \
--build-arg kafka_version="${ARG_KAFKA}" \
--build-arg scala_version="${ARG_SCALA}" \
--tag "${IMAGE_NAME}"