| #!/bin/bash |
| |
| # find where we are |
| APP_PATH=$(git rev-parse --show-toplevel) |
| cd $APP_PATH |
| |
| # set the environment file |
| ENV_FILE=/data/nolabs/config/.env |
| |
| # remove leftovers |
| rm -rf $APP_PATH/.venv |
| |
| # go into venv |
| echo "Info: Creating python virtualenv" |
| pyvenv $APP_PATH/.venv > /dev/null |
| source $APP_PATH/.venv/bin/activate |
| |
| # source our own environment settings |
| set -a |
| source $ENV_FILE |
| set +a |
| |
| # install requirements |
| echo "Info: Installing application requirements" |
| pip install -r $APP_PATH/requirements.txt > /dev/null |
| |
| # make folder to store application logs |
| mkdir -p $LOGS_DIR |
| |
| # build flask application container image |
| echo "Info: Building application container image" |
| echo "-------------------------------------------------------" |
| docker build -t $FLASK_APP_CONTAINER_NAME . |
| echo "-------------------------------------------------------" |
| echo "Info: Built application container image" |
| |
| # wait for mysql container to be up |
| while true; do |
| flask db upgrade #> /dev/null 2>&1 |
| if [[ "$?" == "0" ]]; then |
| break |
| fi |
| echo "Warn: Waiting for MySQL to be ready before starting the application. Retrying in 5 secs..." |
| sleep 5 |
| done |
| |
| # start flask application container |
| echo "Info: Starting application container" |
| echo "-------------------------------------------------------" |
| docker build -t $FLASK_APP_CONTAINER_NAME . |
| docker run --rm --name $FLASK_APP_CONTAINER_NAME -d --net host \ |
| -v $PWD:/data/nolabs/app -v $LOGS_DIR:$LOGS_DIR --env-file $ENV_FILE \ |
| $FLASK_APP_CONTAINER_NAME |
| echo "-------------------------------------------------------" |
| echo "Info: Application started!" |