Commit 3051ffa4 authored by Noah Zoschke's avatar Noah Zoschke

compile UX tweaks; update settings with inject_dbs script

parent 62d69655
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
# bin/compile <build-dir> <cache-dir> # bin/compile <build-dir> <cache-dir>
set -e set -e
set -o pipefail
BIN_DIR=$(dirname $0) BIN_DIR=$(cd $(dirname $0); pwd) # absolute path
BUILD_DIR=$1 BUILD_DIR=$1
CACHE_DIR=$2 CACHE_DIR=$2
...@@ -24,44 +25,27 @@ for dir in $VIRTUALENV_DIRS; do ...@@ -24,44 +25,27 @@ for dir in $VIRTUALENV_DIRS; do
cp -R $CACHE_DIR/$dir . &> /dev/null || true cp -R $CACHE_DIR/$dir . &> /dev/null || true
done done
echo "-----> Preparing virtualenv" echo "-----> $NAME app detected"
echo "-----> Preparing virtualenv version $(virtualenv --version)"
virtualenv --no-site-packages . | sed -u 's/^/ /' virtualenv --no-site-packages . | sed -u 's/^/ /'
[ "${PIPESTATUS[*]}" == "0 0" ]
echo "-----> Byte-compiling code" echo "-----> Byte-compiling code"
find . -name "*.py" | xargs bin/python -m py_compile find . -name "*.py" | xargs bin/python -m py_compile
[ "${PIPESTATUS[*]}" == "0 0" ]
# if Django, inject psycopg and append settings # if Django, inject psycopg and append settings
if [ "$NAME" = "Django" ]; then if [ "$NAME" = "Python/Django" ]; then
grep -q ^psycopg2 requirements.txt || ( echo "-----> Django settings injection"
echo "-----> Injecting psycopg2 into requirements for PostgreSQL support"
echo "psycopg2==2.3.1" >> requirements.txt
)
SETTINGS_FILE=$(ls **/settings.py | head -1) SETTINGS_FILE=$(ls **/settings.py | head -1)
echo "-----> Appending code to $SETTINGS_FILE to read from DATABASE_URL" echo " Injecting code into $SETTINGS_FILE to read from DATABASE_URL"
cat >>$SETTINGS_FILE <<EOF
import os, urlparse $BIN_DIR/../opt/inject_dbs $SETTINGS_FILE _settings.py
if os.environ.has_key('DATABASE_URL'): mv _settings.py $SETTINGS_FILE
urlparse.uses_netloc.append('postgres')
url = urlparse.urlparse(os.environ['DATABASE_URL'])
DATABASES['default'] = {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': url.path[1:],
'USER': url.username,
'PASSWORD': url.password,
'HOST': url.hostname,
'PORT': url.port,
}
EOF
fi fi
echo "-----> Installing dependencies with pip" echo "-----> Installing dependencies using pip version $(pip --version | awk '{print $2}')"
PIP_DOWNLOAD_CACHE=$PIP_DOWNLOAD_CACHE bin/pip install -r requirements.txt | sed -u 's/^/ /' PIP_DOWNLOAD_CACHE=$PIP_DOWNLOAD_CACHE bin/pip install -r requirements.txt | sed -u 's/^/ /'
[ "${PIPESTATUS[*]}" == "0 0" ]
# store new artifacts in cache # store new artifacts in cache
for dir in $VIRTUALENV_DIRS; do for dir in $VIRTUALENV_DIRS; do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment