-
Notifications
You must be signed in to change notification settings - Fork 16
/
build_images.sh
executable file
·261 lines (221 loc) · 6.51 KB
/
build_images.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
#!/usr/bin/env bash
# Build docker images script, with options
#
# Prerequisites:
# Run `./build_images.sh -r`
#
# local/default envs - .env.local
#
set -e
build_3dparty_image() {
# $1 dockerfile
# $2 image name
# $3 build from path
# $4 subtag - if not set, extracted from dockerfile ie: TOR_VERSION
if [ -f "docker_rig/$1" ]; then
if [ -z "$4" ]; then
SUBTAG=$(awk -v search="^ARG ${2^^}?_VERSION=" -F '=' '$0 ~ search \
{ gsub(/["]/, "", $2); printf("%s",$2) }' \
"docker_rig/$1")
else
SUBTAG=$4
fi
else
echo "No docker file docker_rig/$1"
exit 1
fi
echo "Building from $1 in $2 image version ${SUBTAG}${SUBTAG_EXTRA} ..."
# Add docker tag alias - ie: latest
if [ ! -z "${TL_TAG_ALIAS}" ]; then
TL_TAG_CMD=" -t ${TL_TAG_URL}/$2:${TL_TAG_ALIAS} "
fi
docker ${TL_TAG_BUILD_OPTS} \
-f docker_rig/$1 \
--build-arg VERSION="${TL_VERSION}" \
--build-arg ${2^^}_VERSION=${SUBTAG} \
$4 $5 $6 $7 $8 $9 \
-t ${TL_TAG_URL}/$2:${SUBTAG}${SUBTAG_EXTRA} $3 ${TL_TAG_BUILD_Extra} ${TL_TAG_CMD}
}
build_minotari_image() {
# $1 image name
# $2 image tag
# $3 build from path
# $4 APP_NAME ie: minotari_node
# $5 APP_EXEC ie: minotari_node
# Add docker tag alias - ie: latest
if [ ! -z "${TL_TAG_ALIAS}" ]; then
TL_TAG_CMD=" -t ${TL_TAG_URL}/$1:${TL_TAG_ALIAS} "
fi
echo "Building $4 ($5) from tarilabs.Dockerfile in $1 image version $2 ..."
echo "* Image will be tagged as ${TL_TAG_URL}/$1:$2"
echo "* and: ${TL_TAG_CMD}"
echo "* Build options: ${TL_TAG_BUILD_OPTS}"
echo "* Architecture: ${TBN_ARCH}"
echo "* Features: ${TBN_FEATURES}"
echo "* TL_TAG_BUILD_Extra: ${TL_TAG_BUILD_Extra}"
docker ${TL_TAG_BUILD_OPTS} \
-f docker_rig/tarilabs.Dockerfile \
--build-arg ARCH=${TBN_ARCH} \
--build-arg FEATURES=${TBN_FEATURES} \
--build-arg VERSION=$2 \
--build-arg APP_NAME=$4 \
--build-arg APP_EXEC=$5 \
--build-arg TARI_NETWORK=${TARI_NETWORK} \
$6 $7 $8 $9 \
-t ${TL_TAG_URL}/$1:$2 $3 ${TL_TAG_BUILD_Extra} ${TL_TAG_CMD}
}
build_3dparty_image_json() {
# $1 json image_name
build_3dparty_image $1.Dockerfile $1 .
}
build_all_3dparty_images() {
for element in "${arr3rdParty[@]}"; do
build_3dparty_image_json $element
done
}
build_minotari_image_json() {
# $1 json image_name
export $(jq --arg jsonVar "$1" -r '. [] | select(."image_name"==$jsonVar)
| to_entries[] | .key + "=" + .value' tarisuite.json)
build_minotari_image $image_name \
"$TL_VERSION_LONG" ${TARI_SOURCE_ROOT} \
$app_name $app_exec
}
build_all_minotari_images() {
for element in "${arrTariSuite[@]}"; do
build_minotari_image_json $element
done
}
build_all_images() {
build_all_3dparty_images
build_all_minotari_images
}
build_help_info() {
cat << EOF
Build launchpad's docker images locally
USAGE:
$0 [OPTIONS]
OPTIONS:
-a, --all build all images with current default environment variables
-3, 3rdparty build 3rd Party images
-t, tari build Tari suite images
-l, ls list images that can be built
-r, requirements list and check for pre-requisite software needed by this script
-b image_name build an image
-h this help info
Default envs can loaded from .env.local
EOF
}
build_help_images() {
echo "List all images that can be built:"
echo " ${arr3rdParty[@]}"
echo " ${arrTariSuite[@]}"
}
# Quick overrides
if [ -f ".env.local" ]; then
source ".env.local"
fi
# Location of Tari source code
TARI_SOURCE_ROOT=${TARI_SOURCE_ROOT:-"../tari"}
if [ ! -f "${TARI_SOURCE_ROOT}/applications/minotari_node/Cargo.toml" ]; then
echo "!! Can't find Tari source code at ${TARI_SOURCE_ROOT} !!"
echo "searching for ${TARI_SOURCE_ROOT}/applications/minotari_node/Cargo.toml "
exit 2
fi
if [ ! -f "${TARI_SOURCE_ROOT}/buildtools/docker_rig/start_tari_app.sh" ]; then
echo "Put start_tari_app.sh into tari source"
mkdir -p ${TARI_SOURCE_ROOT}/buildtools/docker_rig
cp -v docker_rig/start_tari_app.sh ${TARI_SOURCE_ROOT}/buildtools/docker_rig/start_tari_app.sh
fi
# Version refers to the node, wallet, etc.
# applications/tari_app_utilities/Cargo.toml
TL_VERSION=${TL_VERSION:-$(awk -F ' = ' '$1 ~ /^version/ \
{ gsub(/["]/, "", $2); printf("%s",$2) }' \
"${TARI_SOURCE_ROOT}/applications/minotari_node/Cargo.toml")}
# Default build options - general x86-64 / AMD64
TBN_ARCH=${TBN_ARCH:-x86-64}
TBN_FEATURES=${TBN_FEATURES:-safe}
# Docker tag URL
TL_TAG_URL=${TL_TAG_URL:-quay.io/tarilabs}
# Docker build options
TL_TAG_BUILD_OPTS=${TL_TAG_BUILD_OPTS:-"build"}
# Docker tag suffix for platform
#TL_TAG_BUILD_PF=-amd64
#TL_VERSION_LONG="${TL_VERSION}-${TBN_ARCH}-${TBN_FEATURES}"
TL_VERSION_LONG=${TL_VERSION_LONG:-"${TL_VERSION}${TL_TAG_BUILD_PF}"}
# Docker sub Tag extra
#SUBTAG_EXTRA=${SUBTAG_EXTRA:-"-$TL_VERSION_LONG"}
# Docker tag alias
#TL_TAG_ALIAS=latest
# Docker Build extra commands
#TL_TAG_BUILD_Extra=" --build-arg RUST_TOOLCHAIN=nightly-2023-06-03 "
arrAllTools=( $(jq -r '.[].image_name' tarisuite.json 3rdparty.json) )
arrTariSuite=( $(jq -r '.[].image_name' tarisuite.json) )
arr3rdParty=( $(jq -r '.[].image_name' 3rdparty.json) )
check_for() {
if result=$($1 --version 2>/dev/null); then
result="$1: $result INSTALLED ✓"
else
result="$1: MISSING ⨯"
fi
}
if [ -n "$BASH_VERSION" ]; then
if [ "${BASH_VERSION:0:1}" -lt 4 ]; then
echo "!! Needs bash v4.x or above - current bash version $BASH_VERSION !!"
fi
else
echo "Should be run with bash v4.x or above"
fi
# toLower
#commandEnv="${1,,}"
commandEnv=$(echo "${1}" | tr "[:upper:]" "[:lower:]")
case $commandEnv in
-3 | 3rdparty )
build_all_3dparty_images
;;
-t | tari )
build_all_minotari_images
;;
-a | all )
build_all_images
;;
-b | build )
echo "Build a docker image"
shift
if [[ ${arrAllTools[*]} =~ (^|[[:space:]])"${1}"($|[[:space:]]) ]]; then
echo "Image found - $1"
if [ "${1:0:9}" == "minotari_" ]; then
build_minotari_image_json $1
else
build_3dparty_image_json $1
fi
else
echo "Image not found for $1"
build_help_info
build_help_images
exit 3
fi
;;
-l | ls )
build_help_images
;;
-r | req | requirement | requirements )
echo "List of requirements and possible test:"
check_for jq
echo "$result"
check_for docker
echo "$result"
check_for awk
echo "$result"
check_for bash
echo "$result"
;;
-h | -? | --help | help )
build_help_info
;;
*) echo "Unrecognised option: $1"
build_help_info
exit 4
;;
esac
exit 0