63 lines
1.8 KiB
Bash
Executable file
63 lines
1.8 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# This script uses these environment variables:
|
|
#
|
|
# DISABLE_COLLECTSTATIC: if not empty, inhibits execution of 'manage.py collectstatic'.
|
|
|
|
function assemble() {
|
|
# For SCL enablement
|
|
source .bashrc
|
|
|
|
set -e
|
|
|
|
echo "---> Copying application source ..."
|
|
cp -Rf /tmp/src/* ./
|
|
|
|
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
|
|
|
|
set +e
|
|
django_collectstatic
|
|
set -e
|
|
|
|
# remove pip temporary directory
|
|
rm -rf /tmp/pip_build_default
|
|
}
|
|
|
|
function django_collectstatic() {
|
|
[ -n "$DISABLE_COLLECTSTATIC" ] && return
|
|
! pip show -q django && return
|
|
|
|
# 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)
|
|
|
|
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
|
|
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
|
|
}
|
|
|
|
assemble
|