blob: e323bfb6d94ad7238e9c2a840ba1e39229a95e8c [file] [log] [blame]
Fatih Degirmencic2a46012019-09-30 12:07:45 +02001#!/bin/bash
2
3# find where we are
4APP_PATH=$(git rev-parse --show-toplevel)
5cd $APP_PATH
6
7# set the environment file
8ENV_FILE=/data/nolabs/config/.env
9
10# remove leftovers
11rm -rf $APP_PATH/.venv
12
13# go into venv
14echo "Info: Creating python virtualenv"
15pyvenv $APP_PATH/.venv > /dev/null
16source $APP_PATH/.venv/bin/activate
17
18# source our own environment settings
19set -a
20source $ENV_FILE
21set +a
22
23# install requirements
24echo "Info: Installing application requirements"
25pip install -r $APP_PATH/requirements.txt > /dev/null
26
27# make folder to store application logs
28mkdir -p $LOGS_DIR
29
30# build flask application container image
31echo "Info: Building application container image"
32echo "-------------------------------------------------------"
33docker build -t $FLASK_APP_CONTAINER_NAME .
34echo "-------------------------------------------------------"
35echo "Info: Built application container image"
36
37# wait for mysql container to be up
38while true; do
39 flask db upgrade #> /dev/null 2>&1
40 if [[ "$?" == "0" ]]; then
41 break
42 fi
43 echo "Warn: Waiting for MySQL to be ready before starting the application. Retrying in 5 secs..."
44 sleep 5
45done
46
47# start flask application container
48echo "Info: Starting application container"
49echo "-------------------------------------------------------"
50docker build -t $FLASK_APP_CONTAINER_NAME .
51docker run --rm --name $FLASK_APP_CONTAINER_NAME -d --net host \
52 -v $PWD:/data/nolabs/app -v $LOGS_DIR:$LOGS_DIR --env-file $ENV_FILE \
53 $FLASK_APP_CONTAINER_NAME
54echo "-------------------------------------------------------"
55echo "Info: Application started!"