#!/bin/bash

set -e

export PYTHONPATH="/srv/app:$PYTHONPATH"

SETUP_BACKEND=${SETUP_BACKEND:-"false"}
SETUP_FRONTEND=${SETUP_FRONTEND:-"false"}

/srv/bin/wait-for-cloud.sh

if [ "${SETUP_BACKEND}" = "true" ];then
    if [ "${RUN_POETRY_INSTALL}" = "true" ];then
        poetry install --no-ansi --no-cache
    else
        /srv/bin/wait-for-virtualenv.sh
    fi
fi

if [ "${SETUP_FRONTEND}" = "true" ];then
    if [ "${RUN_YARN_INSTALL}" = "true" ];then
        yarn --modules-folder /srv/node_modules/ install --frozen-lockfile
    else
        /srv/bin/wait-for-yarn-env.sh
    fi
fi

exec "$@"
