Add sti scripts

This commit is contained in:
Rodolfo Carvalho 2015-05-22 13:47:35 +02:00
parent 5548c3ad52
commit ae6eaa2272
2 changed files with 77 additions and 0 deletions

52
.sti/bin/assemble Executable file
View File

@ -0,0 +1,52 @@
#!/bin/bash
# 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
# Support for Django
# Take shallowest manage.py script
MANAGE_FILE=$(find . -maxdepth 3 -type f -name 'manage.py' -printf '%d\t%P\n' | sort -nk1 | cut -f2 | head -1)
if pip show -q django && [ -f "$MANAGE_FILE" ]; then
set +e
# Check if collectstatic can be run.
python $MANAGE_FILE collectstatic --dry-run --noinput &> /dev/null && RUN_COLLECTSTATIC=true
# Collect assets if settings seems okay.
if [ "$RUN_COLLECTSTATIC" ]; then
echo "---> Collecting static assets ..."
python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d'
[ $? -ne 0 ] && {
echo "ERROR: 'manage.py collectstatic' failed. See the build logs for more info."
exit 1
} || true
else
echo "WARNING: 'manage.py collectstatic' ignored. To debug, run:"
echo " $ python $MANAGE_FILE collectstatic --noinput"
echo "Ignore this warning if you're not serving static files with Django."
fi
fi
# remove pip temporary directory
rm -rf /tmp/pip_build_default

25
.sti/bin/run Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
function is_gunicorn_installed() {
pip show gunicorn
}
# For SCL enablement
source .bashrc
set -e
export APP_FILE=${APP_FILE:-"app.py"}
if [[ ! -v APP_MODULE && -f setup.py ]]; then
APP_MODULE=`python setup.py --name`":application"
fi
if is_gunicorn_installed && [[ -v APP_MODULE ]]; then
if [[ -v APP_CONFIG ]]; then
export CONFIG="--config ${APP_CONFIG}"
fi
exec gunicorn ${APP_MODULE} --bind=:8080 ${CONFIG}
fi
exec python -u ${APP_FILE}