Fatih Degirmenci | c2a4601 | 2019-09-30 12:07:45 +0200 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # find where we are |
| 4 | APP_PATH=$(git rev-parse --show-toplevel) |
| 5 | cd $APP_PATH |
| 6 | |
| 7 | # set the environment file |
| 8 | ENV_FILE=/data/nolabs/config/.env |
| 9 | |
| 10 | # remove leftovers |
| 11 | rm -rf $APP_PATH/.venv |
| 12 | |
| 13 | # go into venv |
| 14 | echo "Info: Creating python virtualenv" |
| 15 | pyvenv $APP_PATH/.venv > /dev/null |
| 16 | source $APP_PATH/.venv/bin/activate |
| 17 | |
| 18 | # source our own environment settings |
| 19 | set -a |
| 20 | source $ENV_FILE |
| 21 | set +a |
| 22 | |
| 23 | # install requirements |
| 24 | echo "Info: Installing application requirements" |
| 25 | pip install -r $APP_PATH/requirements.txt > /dev/null |
| 26 | |
| 27 | # make folder to store application logs |
| 28 | mkdir -p $LOGS_DIR |
| 29 | |
| 30 | # build flask application container image |
| 31 | echo "Info: Building application container image" |
| 32 | echo "-------------------------------------------------------" |
| 33 | docker build -t $FLASK_APP_CONTAINER_NAME . |
| 34 | echo "-------------------------------------------------------" |
| 35 | echo "Info: Built application container image" |
| 36 | |
| 37 | # wait for mysql container to be up |
| 38 | while 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 |
| 45 | done |
| 46 | |
| 47 | # start flask application container |
| 48 | echo "Info: Starting application container" |
| 49 | echo "-------------------------------------------------------" |
| 50 | docker build -t $FLASK_APP_CONTAINER_NAME . |
| 51 | docker 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 |
| 54 | echo "-------------------------------------------------------" |
| 55 | echo "Info: Application started!" |