django-ex/.sti/bin/assemble

64 lines
1.8 KiB
Text
Raw Normal View History

2015-05-22 13:47:35 +02:00
#!/bin/bash
# This script uses these environment variables:
#
# DISABLE_COLLECTSTATIC: if not empty, inhibits execution of 'manage.py collectstatic'.
2015-05-22 13:47:35 +02:00
function assemble() {
# For SCL enablement
source .bashrc
2015-05-22 13:47:35 +02:00
set -e
2015-05-22 13:47:35 +02:00
echo "---> Copying application source ..."
cp -Rf /tmp/src/* ./
2015-05-22 13:47:35 +02:00
if [ -f setup.py ]; then
echo "---> Installing application ..."
python setup.py install --user
elif [ -f requirements.txt ]; then
echo "---> Installing dependencies ..."
pip install --user -r requirements.txt
fi
# set permissions for any installed artifacts
chmod -R og+rwx /opt/openshift
2015-05-22 13:47:35 +02:00
set +e
django_collectstatic
set -e
2015-05-22 13:47:35 +02:00
# remove pip temporary directory
rm -rf /tmp/pip_build_default
}
2015-05-22 13:47:35 +02:00
function django_collectstatic() {
[ -n "$DISABLE_COLLECTSTATIC" ] && return
! pip show -q django && return
2015-05-22 13:47:35 +02:00
# Find shallowest manage.py script, either ./manage.py or <project>/manage.py
local MANAGE_FILE=$(find . -maxdepth 2 -type f -name 'manage.py' -printf '%d\t%P\n' | sort -nk1 | cut -f2 | head -1)
2015-05-22 13:47:35 +02:00
if [ ! -f "$MANAGE_FILE" ]; then
echo "WARNING: seems that you're using Django, but we could not find a 'manage.py' file."
echo "'manage.py collectstatic' ignored."
return
2015-05-22 13:47:35 +02:00
fi
echo "---> Collecting Django static files ..."
if ! python $MANAGE_FILE collectstatic --dry-run --noinput &> /dev/null; then
echo "WARNING: could not run 'manage.py collectstatic'. To debug, run:"
echo " $ python $MANAGE_FILE collectstatic --noinput"
echo "Ignore this warning if you're not serving static files with Django."
return
fi
if ! python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d'; then
local status=$?
echo "ERROR: 'manage.py collectstatic' failed."
return $status
fi
}
2015-05-22 13:47:35 +02:00
assemble