2022-06-08 11:16:56 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
MSG="";
|
|
|
|
PRUNE="false";
|
|
|
|
|
2022-06-09 15:25:01 -04:00
|
|
|
LOG_FILE=""
|
|
|
|
#LOG_FILE="$(dirname -- "$( readlink -f -- "$0"; )")/build.log";
|
|
|
|
|
2022-06-08 11:16:56 -04:00
|
|
|
function appendOutput()
|
|
|
|
{
|
|
|
|
if [ -z "${MSG}" ]; then echo -e "\n" > /dev/tty; fi
|
|
|
|
|
|
|
|
ARGS=$@;
|
2022-06-09 15:25:01 -04:00
|
|
|
LINE="${ARGS}\n";
|
|
|
|
if [ -z "${LOG_FILE}" ]; then echo -e "${LINE}" > /dev/tty; else echo -e "${LINE}" &>> "${LOG_FILE}"; fi
|
2022-06-08 11:16:56 -04:00
|
|
|
|
|
|
|
MSG="${MSG}${LINE}";
|
|
|
|
}
|
|
|
|
|
|
|
|
function runDockerBuild()
|
|
|
|
{
|
|
|
|
if [ "${PRUNE}" == "true" ]; then docker system prune -a -f; fi
|
|
|
|
|
|
|
|
STARTTS=$(date +%s);
|
|
|
|
ARGS=$@;
|
|
|
|
|
2022-06-10 07:27:17 -04:00
|
|
|
APP_VERSION=$(grep -o '"version":\s*"[^"]*"' ./package.json | cut -f4- -d\" | tr -d '"')
|
|
|
|
BUILD_CMD="docker build -f docker/Dockerfile --force-rm --no-cache ${ARGS} -t meshcentral:latest -t meshcentral:${APP_VERSION} .";
|
2022-06-08 11:16:56 -04:00
|
|
|
appendOutput "Current build: ${BUILD_CMD}";
|
|
|
|
|
2022-06-09 15:25:01 -04:00
|
|
|
if [ -z "${LOG_FILE}" ]; then ${BUILD_CMD}; else ${BUILD_CMD} &>> "${LOG_FILE}"; fi
|
2022-06-08 11:16:56 -04:00
|
|
|
if [ $? -ne 0 ]; then exit $?; fi
|
2022-07-02 13:50:07 -04:00
|
|
|
|
|
|
|
IMAGEID=$(docker images --format "{{.ID}} {{.CreatedAt}}" | sort -rk 2 | awk 'NR==1{print $1}');
|
|
|
|
appendOutput "\tImageId: ${IMAGEID}";
|
2022-06-08 11:16:56 -04:00
|
|
|
|
|
|
|
ENDTS=$(date +%s);
|
|
|
|
DIFSEC=$((${ENDTS}-${STARTTS}));
|
|
|
|
if [ ${DIFSEC} -ge 60 ]; then
|
|
|
|
TMPMIN=$((${DIFSEC}/60));
|
|
|
|
TMPSEC=$((${DIFSEC}%60));
|
|
|
|
|
|
|
|
if [ ${TMPMIN} -ge 60 ]; then
|
|
|
|
TMPHOUR=$((${TMPMIN}/60));
|
|
|
|
TMPMIN=$((${TMPMIN}%60));
|
|
|
|
|
|
|
|
appendOutput "\tBuild time: ${TMPHOUR} hr ${TMPMIN} min ${TMPSEC} sec";
|
|
|
|
else appendOutput "\tBuild time: ${TMPMIN} min ${TMPSEC} sec"; fi
|
|
|
|
else appendOutput "\tBuild time: ${DIFSEC} sec"; fi
|
|
|
|
|
2022-07-02 13:50:07 -04:00
|
|
|
IMG_SIZE=$(docker image inspect ${IMAGEID} | grep -o '"Size":\s*[^,]*' | cut -f2- -d ':' | tr -d ' ');
|
2022-06-09 15:25:01 -04:00
|
|
|
expr $IMG_SIZE + 0 > /dev/null;
|
|
|
|
appendOutput "\tImage size: ${IMG_SIZE} ($((${IMG_SIZE}/1024/1024))M)\n";
|
2022-06-08 11:16:56 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent_path=$(dirname -- $(dirname -- "$( readlink -f -- "$0"; )"));
|
|
|
|
if [ "${parent_path}" != "$(pwd -P)" ]; then
|
|
|
|
echo -e "change working directory to: ${parent_path}" > /dev/tty;
|
|
|
|
cd "${parent_path}";
|
|
|
|
fi
|
|
|
|
|
2022-07-02 13:50:07 -04:00
|
|
|
if ! [ -z $1 ]; then
|
|
|
|
for arg in "$@"
|
|
|
|
do
|
|
|
|
case "${arg}" in
|
|
|
|
--prune)
|
|
|
|
PRUNE="true";
|
|
|
|
shift 1;
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
MAINARGS=$@;
|
2022-06-08 11:16:56 -04:00
|
|
|
|
2022-07-02 13:50:07 -04:00
|
|
|
#runDockerBuild --build-arg DISABLE_MINIFY=yes --build-arg DISABLE_TRANSLATE=yes ${MAINARGS};
|
|
|
|
#runDockerBuild --build-arg DISABLE_TRANSLATE=yes ${MAINARGS};
|
|
|
|
#runDockerBuild --build-arg DISABLE_MINIFY=yes ${MAINARGS};
|
|
|
|
runDockerBuild ${MAINARGS};
|
2022-06-08 11:16:56 -04:00
|
|
|
|
2022-07-02 13:50:07 -04:00
|
|
|
#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes --build-arg DISABLE_MINIFY=yes --build-arg DISABLE_TRANSLATE=yes ${MAINARGS};
|
|
|
|
#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes --build-arg DISABLE_TRANSLATE=yes ${MAINARGS};
|
|
|
|
#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes --build-arg DISABLE_MINIFY=yes ${MAINARGS};
|
|
|
|
#runDockerBuild --build-arg INCLUDE_MONGODBTOOLS=yes ${MAINARGS};
|
2022-06-08 11:16:56 -04:00
|
|
|
|
|
|
|
echo "";
|
2022-06-09 15:25:01 -04:00
|
|
|
echo -e "${MSG}";
|
2022-06-08 11:16:56 -04:00
|
|
|
|
|
|
|
exit 0;
|