2020-11-03 21:42:44 +00:00
|
|
|
#!/bin/bash
|
2020-09-04 20:54:23 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2024-04-22 06:13:35 +00:00
|
|
|
. ./scripts/version.sh
|
|
|
|
|
2023-06-27 17:28:23 +00:00
|
|
|
GO=${GO-go}
|
|
|
|
ARCH=${ARCH:-$("${GO}" env GOARCH)}
|
|
|
|
|
2020-09-04 20:54:23 +00:00
|
|
|
if [ "${DEBUG}" = 1 ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2022-08-27 01:33:13 +00:00
|
|
|
# Try to keep the K3s binary under 70 megabytes.
|
2021-12-02 20:51:57 +00:00
|
|
|
# "64M ought to be enough for anybody"
|
2022-08-27 01:33:13 +00:00
|
|
|
MAX_BINARY_MB=70
|
2021-12-02 20:51:57 +00:00
|
|
|
MAX_BINARY_SIZE=$((MAX_BINARY_MB * 1024 * 1024))
|
2020-11-03 21:42:44 +00:00
|
|
|
BIN_SUFFIX="-${ARCH}"
|
|
|
|
if [ ${ARCH} = amd64 ]; then
|
|
|
|
BIN_SUFFIX=""
|
|
|
|
elif [ ${ARCH} = arm ]; then
|
|
|
|
BIN_SUFFIX="-armhf"
|
2022-04-15 16:41:40 +00:00
|
|
|
elif [ ${ARCH} = s390x ]; then
|
|
|
|
BIN_SUFFIX="-s390x"
|
2020-11-03 21:42:44 +00:00
|
|
|
fi
|
|
|
|
|
2024-04-22 06:13:35 +00:00
|
|
|
CMD_NAME="dist/artifacts/k3s${BIN_SUFFIX}${BINARY_POSTFIX}"
|
2020-11-03 21:42:44 +00:00
|
|
|
SIZE=$(stat -c '%s' ${CMD_NAME})
|
2020-09-04 20:54:23 +00:00
|
|
|
|
2022-10-28 16:17:49 +00:00
|
|
|
if [ -n "${DEBUG}" ]; then
|
|
|
|
echo "DEBUG is set, ignoring binary size"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-09-04 20:54:23 +00:00
|
|
|
if [ ${SIZE} -gt ${MAX_BINARY_SIZE} ]; then
|
2021-12-02 20:51:57 +00:00
|
|
|
echo "k3s binary ${CMD_NAME} size ${SIZE} exceeds max acceptable size of ${MAX_BINARY_SIZE} bytes (${MAX_BINARY_MB} MiB)"
|
|
|
|
exit 1
|
2020-09-04 20:54:23 +00:00
|
|
|
fi
|
|
|
|
|
2021-12-02 20:51:57 +00:00
|
|
|
echo "k3s binary ${CMD_NAME} size ${SIZE} is less than max acceptable size of ${MAX_BINARY_SIZE} bytes (${MAX_BINARY_MB} MiB)"
|
2020-09-04 20:54:23 +00:00
|
|
|
exit 0
|