Skip to content

Commit

Permalink
Merge 5ea4925 into 88eef8d
Browse files Browse the repository at this point in the history
  • Loading branch information
ropable committed Jan 9, 2018
2 parents 88eef8d + 5ea4925 commit 549e621
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 190 deletions.
79 changes: 75 additions & 4 deletions .s2i/bin/assemble
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,80 @@
#!/bin/bash

function is_django_installed() {
python -c "import django" &>/dev/null
}

function should_collectstatic() {
is_django_installed && [[ -z "$DISABLE_COLLECTSTATIC" ]]
}

# Install pipenv to the separate virtualenv to isolate it
# from system Python packages and packages in the main
# virtualenv. Executable is simlinked into ~/.local/bin
# to be accessible. This approach is inspired by pipsi
# (pip script installer).
function install_pipenv() {
echo "---> Installing pipenv packaging tool ..."
VENV_DIR=$HOME/.local/venvs/pipenv
virtualenv $VENV_DIR
$VENV_DIR/bin/pip --isolated install -U pipenv
mkdir -p $HOME/.local/bin
ln -s $VENV_DIR/bin/pipenv $HOME/.local/bin/pipenv
}

set -e

shopt -s dotglob
echo "---> Installing application source ..."
mv /tmp/src/* ./

if [[ ! -z "$UPGRADE_PIP_TO_LATEST" || ! -z "$ENABLE_PIPENV" ]]; then
echo "---> Upgrading pip to latest version ..."
pip install -U pip setuptools wheel
fi

if [[ ! -z "$ENABLE_PIPENV" ]]; then
install_pipenv
echo "---> Installing dependencies via pipenv ..."
if [[ -f Pipfile ]]; then
pipenv install --deploy
elif [[ -f requirements.txt ]]; then
pipenv install -r requirements.txt
fi
pipenv check
elif [[ -f requirements.txt ]]; then
echo "---> Installing dependencies ..."
pip install -r requirements.txt
elif [[ -f setup.py ]]; then
echo "---> Installing application ..."
python setup.py develop
fi

if should_collectstatic; then
(
echo "---> Collecting Django static files ..."


APP_HOME=${APP_HOME:-.}
# Look for 'manage.py' in the directory specified by APP_HOME, or the current directory
manage_file=$APP_HOME/manage.py

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."
exit
fi

if ! python $manage_file collectstatic --dry-run --noinput; 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."
exit
fi

pip install --upgrade pip
pip install --upgrade setuptools
pip install -r requirements.txt
python $manage_file collectstatic --noinput
)
fi

#python manage.py migrate --noinput
# set permissions for any installed artifacts
fix-permissions /opt/app-root
182 changes: 0 additions & 182 deletions fabfile.py

This file was deleted.

3 changes: 2 additions & 1 deletion prs2/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
It exposes the WSGI callable as a module-level variable named ``application``.
"""
import confy
confy.read_environment_file('.env') # Must precede dj_static imports.
confy.read_environment_file() # Must precede dj_static imports.
from django.core.wsgi import get_wsgi_application
from dj_static import Cling, MediaCling
import os


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "prs2.settings")
application = Cling(MediaCling(get_wsgi_application()))
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Django==1.11.7
django-extensions==1.9.7
git+https://github.com/parksandwildlife/dpaw-utils.git@0.3a16#egg=dpaw-utils
uWSGI==2.0.15
django-reversion==2.0.10
django-debug-toolbar==1.8
django-tastypie==0.14.0
Expand All @@ -14,8 +15,7 @@ django-storages==1.5.2
django-bootstrap-pagination==1.6.2
dj-static==0.0.6
Unipath==1.1
Unidecode==0.04.20
Fabric==1.10.1
Unidecode==1.0.22
jinja2==2.9.6
Pillow==3.4.2
coverage==3.7.1
Expand All @@ -25,6 +25,5 @@ python-magic==0.4.13
lxml==3.7.3
django-downloadview==1.9
webtemplate-dpaw==0.4.8
selenium==2.46.1
openpyxl==2.2.6
xmltodict==0.10.2
2 changes: 2 additions & 0 deletions run_uwsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
exec uwsgi --ini uwsgi.ini --module prs2.wsgi
19 changes: 19 additions & 0 deletions uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[uwsgi]
# Sensible defaults for an uWSGI application
processes = 4
max-requests = 100
cache2 = name=default,bitmap=1,items=10000,blocksize=1000,blocks=200000
vacuum = true
logdate = %%Y/%%m/%%d %%H:%%M:%%S

# Process-related settings
master = true
http-socket = :8080
die-on-term = true
touch-reload = uwsgi.ini

# Django static files
static-map = /static=staticfiles

# Media uploads
static-map = /media=media

0 comments on commit 549e621

Please sign in to comment.