diff --git a/.sti/bin/assemble b/.sti/bin/assemble new file mode 100755 index 0000000..c50bdab --- /dev/null +++ b/.sti/bin/assemble @@ -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 diff --git a/.sti/bin/run b/.sti/bin/run new file mode 100755 index 0000000..38c9dd5 --- /dev/null +++ b/.sti/bin/run @@ -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}