Files
scylladb/tools/toolchain/prepare
Kefu Chai 70ef7e63b5 tools: toolchain: prepare: do not bail out when checking for command
before this change, if `buildah` is not available in $PATH, this script
fails like:
```console
$ tools/toolchain/prepare --help
tools/toolchain/prepare: line 3: buildah: command not found
```

the error message never gets a chance to show up. as `set -e` in the
shebang line just let bash quit.

after this change, we check for the existence of buildah, and bail out
if it is not available. so, on a machine without buildah around, we now
have:
```console
$ tools/toolchain/prepare  --help
install buildah 1.19.3 or later
```

the same applies to "reg".

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes scylladb/scylladb#17697
2024-03-08 15:09:21 +02:00

61 lines
1.5 KiB
Bash
Executable File

#!/bin/bash -e
if ! command -v buildah > /dev/null; then
echo install buildah 1.19.3 or later
exit 1
fi
bv=$(buildah --version)
# translate to array of version components
bv="${bv#buildah version }"
bv="${bv% (*}"
bv=(${bv//./ })
maj=${bv[0]}
min=${bv[1]}
patch=${bv[2]}
ok=$(( maj > 1 || ( maj == 1 && min > 19 ) || ( maj == 1 && min == 19 && patch >= 3 ) ))
if (( ! ok )); then
echo install buildah 1.19.3 or later
exit 1
fi
if ! command -v reg > /dev/null; then
echo install the reg command for registry inspection
exit 1
fi
if reg digest $(<tools/toolchain/image) > /dev/null; then
echo "Toolchain image $(<tools/toolchain/image) exists; select a new name"
exit 1
fi
archs=(amd64 arm64)
# docker arch has a diffrent spelling than uname arch
declare -A arch_unames=(
[amd64]=x86_64
[arm64]=aarch64
[s390x]=s390x
)
for arch in "${archs[@]}"; do
# translate from docker arch to uname arch
arch_uname="${arch_unames[$arch]}"
if [[ "$(uname -m)" == "${arch_uname}" ]]; then
continue
fi
if [[ ! -f /proc/sys/fs/binfmt_misc/qemu-"${arch_uname}" ]]; then
echo install qemu-user-static
exit 1
fi
done
buildah bud "${archs[@]/#/--platform=linux/}" --jobs 0 --squash --no-cache --pull -f tools/toolchain/Dockerfile --manifest "$(<tools/toolchain/image)"
echo "Done building $(<tools/toolchain/image). You can now test it, and push with"
echo ""
echo " podman manifest push --all $(<tools/toolchain/image) docker://$(<tools/toolchain/image)"