Skip to content

Instantly share code, notes, and snippets.

@themightychris
Created February 28, 2019 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themightychris/13a1993caa1d007c4864707f7dc7c916 to your computer and use it in GitHub Desktop.
Save themightychris/13a1993caa1d007c4864707f7dc7c916 to your computer and use it in GitHub Desktop.
habitat studio starter: python / django app
#!/bin/bash
# prevent supervisor from starting
echo
echo "--> Disabling studio supervisor..."
export HAB_STUDIO_SUP=false
# install environmental dependencies
echo
echo "--> Installing environmental dependencies..."
hab pkg binlink -d /usr/bin core/coreutils env
hab pkg install core/tzdata
export ZONEINFO="$(hab pkg path core/tzdata)/share/zoneinfo"
hab pkg install -b core/python
pip install --upgrade pip
# prepare workspace
echo
echo "--> Preparing python workspace..."
pushd "/src" > /dev/null
# setup venv
python3 -m venv .venv
# fix timezone
ZONEINFO_ESCAPED="$(echo "${ZONEINFO}" | sed 's/\//\\\//g')" # prepare for use as sed replacement
sed -i "s/zoneinfo_root = Path('\/usr\/share\/zoneinfo')/zoneinfo_root = Path('${ZONEINFO_ESCAPED}')/g" .venv/lib/python*/site-packages/django/conf/__init__.py
# activate environment
source .venv/bin/activate
pip install -r requirements.txt
# generate database if needed
./manage.py migrate
popd > /dev/null
# set up studio commands
echo
echo "--> Setting up studio commands"
echo " * Use 'app-run' to run the app for testing"
app-run() {
pushd "/src" > /dev/null
./manage.py runserver
popd > /dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment