giskard / hf.sh
inoki-giskard's picture
Prepare new Python env using pyenv if demo
c718ed6
raw
history blame
1.52 kB
#!/bin/bash
echo "Initializing datadir..."
# Create dir if not existed in HF persistent storage
if [ ! -d "${GSK_HOME}" ]
then
# Create HOME
mkdir -p "${GSK_HOME}"
# Create frontend run dir
mkdir -p "${GSK_HOME}/run/nginx"
fi
if [ ! -z "${GISKARD_LICENSE}" ]
then
# Use new license if env set
echo "${GISKARD_LICENSE}" > "${GISKARD_HOME}/license.lic"
# TODO: Backend raises exception if license is not parsable
fi
echo "Detecting demo Giskard Space..."
if [ ! -z "${SPACE_ID}" ] && [ "${DEMO_SPACE_ID}" == "${SPACE_ID}" ]
then
# Generate GISKARD_DEFAULT_API_KEY in demo space instead of set from Secrets
export GISKARD_DEFAULT_API_KEY=gsk-$(cat /dev/urandom | tr -dc '[:alpha:]' | fold -w ${1:-28} | head -n 1)
# Prepare a new env for demo worker
curl https://pyenv.run | bash
pyenv install $(python --version | cut -d' ' -f2)
pyenv global $(python --version | cut -d' ' -f2)
pip install --upgrade pip
WHEEL=$(ls $GSK_DIST_PATH/python-client/giskard*.whl) && pip install $WHEEL\[server\]
pip install -r /requirements.txt
# Append demo worker supervisord item to conf
echo """
[program:demo_worker]
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
autorestart=true
redirect_stderr=true
startsecs=0
startretries=5000
command=/bin/bash -c 'python -m giskard.cli worker start -u \"http://localhost:9000\" -k \"\$GISKARD_DEFAULT_API_KEY\"; sleep 5'
""" >> "${GSK_DIST_PATH}/supervisord.conf"
fi
echo "Starting supervisord..."
exec supervisord -c "${GSK_DIST_PATH}/supervisord.conf"