#!/bin/sh printf "\033[1;31m" set -e set -x # The entrypoint script here takes care of basic setup for the application # writing out the Nginx config, Uwsgi, and optionally running a local # postgres instance for the application. # # The default configuration is to run postgres locally and start in demo mode. # # If you actually want to use this application you'll want to of course # disable that, which can be done by tweaking the environment variables below. # # You can use volumes if you want to persist any of the data. The data directory # for postgres is `/var/postgres` # # Uploaded attachments are stored in `/app/media` # # Carefully read the vars below. If you needs help understanding the application # specific ones check out `app/settigns.py` Though it's pretty much just # passing things into Django FULL_NAME="${FULL_NAME:-Default App User}" APP_SHELL="${APP_SHELL:-/bin/ash}" # UID and GID used by the `git` user inside of the container APP_UID="${APP_UID:-3500}" APP_GID="${APP_GID:-3500}" APP_NAME=dispatch # If this is anything other than "yes" local postgres will *NOT* be used LOCAL_POSTGRES="${LOCAL_POSTGRES:-yes}" # uwsgi conf UWSGI_PROCESSES="${UWSGI_PROCESSES:-1}" UWSGI_THREADS="${UWSGI_THREADS:-4}" UWSGI_SOCKET="${UWSGI_SOCKET:-0.0.0.0:9200}" # nginx conf NGINX_PORT="${NGINX_PORT:-8080}" NGINX_WORKER_PROCESSES="${NGINX_WORKER_PROCESSES:-1}" NGINX_WORKER_CONNECTIONS="${NGINX_WORKER_CONNECTIONS:-1024}" NGINX_UWSGI_PASS="${NGINX_UWSGI_PASS:-127.0.0.1:9200}" NGINX_MAX_BODY_SIZE="${NGINX_MAX_BODY_SIZE:-20m}" NGINX_BODY_TIMEOUT="${NGINX_BODY_TIMEOUT:-300s}" # application specific INIT_DEMO="${INIT_DEMO:-yes}" # Create demo user, data, etc? # TEMPLATE_VARS= # Comma seperated list of suffixes to extract into vars # TEMPLATE_VARS_login_info="bla" # for instance is extracted into: # # TEMPLATE_VARS["login_info"] = "bla" # If you need an example, the same thing is done for APP_DB_CONF below: APP_DB_CONF="${APP_DB_CONF:-ENGINE,NAME,USER,PASSWORD,PORT}" APP_DB_CONF_ENGINE="${APP_DB_CONF_ENGINE:-django.db.backends.postgresql}" APP_DB_CONF_NAME="${APP_DB_CONF_NAME:-dispatch}" APP_DB_CONF_USER="${APP_DB_CONF_USER:-postgres}" APP_DB_CONF_PASSWORD="${APP_DB_CONF_PASSWORD:-}" APP_DB_CONF_PORT="${APP_DB_CONF_PORT:-5432}" # Sqlite example # APP_DB_CONF=ENGINE,NAME # APP_DB_CONF_ENGINE=django.db.backends.sqlite3 # APP_DB_CONF_NAME=/app/database.sqlite3 # MySQL Example # APP_DB_CONF=ENGINE,NAME,USER,PASSWORD,HOST,PORT # APP_DB_CONF_ENGINE=django.db.backends.mysql # APP_DB_CONF_NAME=dispatch_test # APP_DB_CONF_USER=dispatch # APP_DB_CONF_PASSWORD=changeme # APP_DB_CONF_HOST=127.0.0.1 # APP_DB_CONF_PORT=3306 # More normal environment variables WEBSITE_URI="${WEBSITE_URI:-http://example.com}" WEBSITE_APP_NAME="${WEBSITE_APP_NAME:-Example dispatch tracker}" USE_EMAIL="${USE_EMAIL:-no}" STATIC_ROOT="${STATIC_ROOT:-/static}" EMAIL_USE_TLS="${EMAIL_USE_TLS:-yes}" EMAIL_PORT="${EMAIL_PORT:-465}" EMAIL_HOST_USER="${EMAIL_HOST_USER:-example}" EMAIL_HOST_PASSWORD="${EMAIL_HOST_PASSWORD:-changeme}" EMAIL_HOST="${EMAIL_HOST:-mail.example.com}" DEFAULT_FROM_EMAIL="${DEFAULT_FROM_EMAIL:-app@example.com}" DEBUG="${DEBUG:-no}" ALLOWED_HOSTS="${ALLOWED_HOSTS:-}" # Defaults to 127.0.0.1 and localhost ADMINS="${ADMINS:-Bob\'s Name:bobs.email@example.com,other:other@example.com}" ACCOUNT_ACTIVATION_DAYS="${ACCOUNT_ACTIVATION_DAYS:-7}" set +x if [ -z "$SECRET_KEY" ] ; then _l="##################################################" printf "\n%s\nSET THE SECRET KEY IF YOU'RE IN PRODUCTION\n%s\n" \ $_l $_l fi set -x printf "\033[0m" # This is only run once in the container's lifetime unless /setup is removed setup() { if [ -e /setup ] ; then return ; fi addgroup -g "${APP_GID}" $APP_NAME adduser -h /var/$APP_NAME --gecos "$FULL_NAME" -D -s "${APP_SHELL}" \ -u "${APP_UID}" -G $APP_NAME $APP_NAME passwd -u $APP_NAME addgroup nginx $APP_NAME chown -R $APP_NAME:$APP_NAME /app /static touch /setup } run_nginx() { cat > /etc/nginx/nginx.conf < /app/uwsgi.ini </dev/null ; then echo "Service $service has stopped... quitting!" exit 1 fi done sleep "$interval" done } setup chown -R $APP_NAME:$APP_NAME /app [ "$LOCAL_POSTGRES" = "yes" ] && run_postgres [ "$INIT_DEMO" = "yes" ] && init_demo run_uwsgi run_nginx set +x sleep 10 # Wait around a little bit before we start checking for the # services since they don't start that quickly on slow systems. # Bail out if a service stops, poll it every 30 seconds watchServices 30 # or if you comment out the above, you can drop into a shell # exec /bin/ash "$@"