#! /bin/bash
# A utility that will install the latest version of the code in the repo
# to your virtualenv, run any upgrade scripts to update your production
# MySQL instance and then preload the JSX cache. Effectively, a one-liner
# to deploying a new version.

set -e

pushd /path/to/git/checkout
source /path/to/your/virtualenv/bin/activate

# Install dependencies, install this library.
python3 -m pip install --upgrade pip wheel setuptools
python3 -m pip install --upgrade -r requirements.txt
python3 -m pip install --upgrade .

# Copy the WSGI files over the old ones, recompile JSX.
cp bemani/wsgi/*.wsgi /path/to/your/wsgi/files
./jsx --output-directory /path/to/static/jsx/directory

# Perform DB schema migrations
./dbutils --config /path/to/your/root/server.yaml upgrade

deactivate
popd

sudo service uwsgi restart && ./preload
echo "Done!"
