Files
storyteller-ml/animation/hallo-83dd4eb/docker-56038fd/scripts/pre_start.sh
T
2024-07-30 11:39:15 +05:30

55 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
export PYTHONUNBUFFERED=1
export TMPDIR=/workspace/tmp
export APP="hallo"
DOCKER_IMAGE_VERSION_FILE="/workspace/${APP}/docker_image_version"
echo "Template version: ${TEMPLATE_VERSION}"
if [[ -e ${DOCKER_IMAGE_VERSION_FILE} ]]; then
EXISTING_VERSION=$(cat ${DOCKER_IMAGE_VERSION_FILE})
else
EXISTING_VERSION="0.0.0"
fi
rsync_with_progress() {
stdbuf -i0 -o0 -e0 rsync -au --info=progress2 "$@" | stdbuf -i0 -o0 -e0 tr '\r' '\n' | stdbuf -i0 -o0 -e0 grep -oP '\d+%|\d+.\d+[mMgG]' | tqdm --bar-format='{l_bar}{bar}' --total=100 --unit='%' > /dev/null
}
sync_apps() {
# Only sync if the DISABLE_SYNC environment variable is not set
if [ -z "${DISABLE_SYNC}" ]; then
# Sync application to workspace to support Network volumes
echo "Syncing ${APP} to workspace, please wait..."
rsync_with_progress --remove-source-files /${APP}/ /workspace/${APP}/
echo "${TEMPLATE_VERSION}" > ${DOCKER_IMAGE_VERSION_FILE}
fi
}
if [ "$(printf '%s\n' "$EXISTING_VERSION" "$TEMPLATE_VERSION" | sort -V | head -n 1)" = "$EXISTING_VERSION" ]; then
if [ "$EXISTING_VERSION" != "$TEMPLATE_VERSION" ]; then
sync_apps
# Create directories
mkdir -p /workspace/logs /workspace/tmp
else
echo "Existing version is the same as the template version, no syncing required."
fi
else
echo "Existing version is newer than the template version, not syncing!"
fi
if [[ ${DISABLE_AUTOLAUNCH} ]]
then
echo "Auto launching is disabled so the application will not be started automatically"
echo "You can launch it manually:"
echo ""
echo " /start_hallo.sh"
else
/start_hallo.sh
fi
echo "All services have been started"