From 067f8f92b568527e94e2a04fa495f86f1820a4bc Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Thu, 14 Oct 2021 17:01:23 -0400 Subject: Move to environment vars. Create a container that sets up a demo. Instead of the old method with scripts, docker-compose file, everything is pulled into the main container with various configuration options allowed from environment variables. Also move settings.py away from the old yaml setup and pull directly from the environment instead. --- .gitignore | 1 + Dockerfile | 20 +++-- app/.ash_history | 8 -- app/app/settings.py | 141 +++++++++++++++++++----------- app/config-compose.yml | 89 ------------------- app/config-example.yml | 76 ---------------- app/demo.sh | 14 +++ app/requirements.txt | 2 +- app/uwsgi.ini | 15 ---- docker-compose.yml | 43 --------- docker-scripts/setup.sh | 23 ----- docker-scripts/shell.sh | 12 --- docker-scripts/uwsgi.sh | 17 ---- entrypoint.sh | 225 ++++++++++++++++++++++++++++++++++++++++++++++++ nginx.conf | 55 ------------ static/.keep | 0 16 files changed, 343 insertions(+), 398 deletions(-) delete mode 100644 app/.ash_history delete mode 100644 app/config-compose.yml delete mode 100644 app/config-example.yml create mode 100755 app/demo.sh delete mode 100644 app/uwsgi.ini delete mode 100644 docker-compose.yml delete mode 100755 docker-scripts/setup.sh delete mode 100755 docker-scripts/shell.sh delete mode 100644 docker-scripts/uwsgi.sh create mode 100755 entrypoint.sh delete mode 100644 nginx.conf delete mode 100644 static/.keep diff --git a/.gitignore b/.gitignore index f9c64ce..42e57ee 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ static pg_data pg_log +db/* diff --git a/Dockerfile b/Dockerfile index 476dccd..35ad256 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ -FROM alpine:latest +FROM docker.io/alpine:3.14 -RUN apk update && apk add python3 py3-setuptools py3-virtualenv postgresql-client +RUN apk update +RUN apk add nginx python3 py3-pip py3-setuptools py3-virtualenv \ + postgresql-client py3-psycopg2 postgresql RUN apk add linux-headers postgresql-dev gcc python3-dev libc-dev COPY app/requirements.txt /requirements.txt @@ -8,17 +10,17 @@ RUN pip3 install --no-cache-dir -r /requirements.txt RUN rm /requirements.txt RUN pip3 install --no-cache-dir uwsgi - RUN apk del linux-headers postgresql-dev gcc python3-dev libc-dev -# Feel free to change the UID if necessary -RUN adduser -D -H -u 1000 app +RUN mkdir /app /static -# RUN apk add uwsgi-python3 +COPY app /app +WORKDIR /app -RUN mkdir /app /static && chown app /app /static +ENV STATIC_ROOT=/static -USER app +RUN python3 manage.py collectstatic -CMD [ "uwsgi", "--ini", "/app/uwsgi.ini" ] +COPY entrypoint.sh / +ENTRYPOINT /entrypoint.sh diff --git a/app/.ash_history b/app/.ash_history deleted file mode 100644 index 315e6ea..0000000 --- a/app/.ash_history +++ /dev/null @@ -1,8 +0,0 @@ -ls -pwd -cd -ls -la -pwd -vi manage.py -woami -whoami diff --git a/app/app/settings.py b/app/app/settings.py index d3dca5d..78cd7db 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -11,71 +11,98 @@ https://docs.djangoproject.com/en/1.11/ref/settings/ """ import os -import yaml - -try: - from yaml import CLoader as Loader, CDumper as Dumper -except ImportError: - from yaml import Loader, Dumper - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -def get_default_config(): - if os.path.exists(BASE_DIR + '/config.yml'): - return yaml.load(open(BASE_DIR + '/config.yml').read(), Loader=Loader) - else: - print("Warning: loading example config! Create config.yml Soon!") - return yaml.load(open(BASE_DIR + '/config-example.yml').read(), \ - Loader=Loader) +def getenv(param): + return os.environ.get(param) -CONFIG = {} - -if os.environ.get('CUSTOM_CONFIG'): - try: - fn = "{}/{}".format(BASE_DIR, os.environ.get('CUSTOM_CONFIG')) - CONFIG = yaml.load(open(fn)) - except Exception as e: - print("WARNING: Loading default configuration. \n{}".format(e)) - CONFIG = get_default_config() -else: - CONFIG = get_default_config() - +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = CONFIG['SECRET_KEY'] +if os.environ.get("SECRET_KEY"): + SECRET_KEY = os.environ.get("SECRET_KEY") +else: + # DO *NOT* use this in production + SECRET_KEY = 'h$r_bwlp@#h#y#%&qhw-n=gb2%wva1d_h65+o94u&!a#%iv&lo' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = CONFIG['debug'] - -ALLOWED_HOSTS = CONFIG['allowed_hosts'] - -ADMINS = CONFIG['admins'] +DEBUG = True if getenv("DEBUG") == "yes" else False -WEBSITE_URI = CONFIG['website_uri'] -WEB_APP_NAME =CONFIG['application_name'] +try: + ALLOWED_HOSTS = getenv("ALLOWED_HOSTS").split(",") +except Exception: + ALLOWED_HOSTS = ["127.0.0.1", "localhost"] -if CONFIG.get('SET_EMAIL'): - EMAIL_HOST = CONFIG['EMAIL_HOST'] - EMAIL_HOST_PASSWORD = CONFIG['EMAIL_HOST_PASSWORD'] - EMAIL_HOST_USER = CONFIG['EMAIL_HOST_USER'] - EMAIL_PORT = CONFIG['EMAIL_PORT'] - EMAIL_USE_TLS = CONFIG['EMAIL_USE_TLS'] - DEFAULT_FROM_EMAIL = CONFIG['DEFAULT_FROM_EMAIL'] +try: + ADMINS = [] + adm = getenv("ADMINS").split(",") + for person in adm: + ADMINS.append(person.split(":")) +except Exception: + ADMINS = [("bob", "bob@example.com")] + +WEBSITE_URI = getenv("WEBSITE_URI") if getenv("WEBSITE_URI") \ + else "http://localhost:8080" +WEB_APP_NAME = getenv("WEBSITE_APP_NAME") if getenv("WEBSITE_APP_NAME") \ + else "Example dispatch tracker" + +if getenv('USE_EMAIL') == "yes": + EMAIL_HOST = getenv("EMAIL_HOST") + EMAIL_HOST_PASSWORD = getenv("EMAIL_HOST_PASSWORD") + EMAIL_HOST_USER = getenv("EMAIL_HOST_USER") + EMAIL_PORT = getenv("EMAIL_PORT") + EMAIL_USE_TLS = True if getenv("EMAIL_USE_TLS") != "no" else False + DEFAULT_FROM_EMAIL = getenv("DEFAULT_FROM_EMAIL") else: print("WARNING EMAIL SETTINGS NOT APPLIED. CHECK CONFIG") TEMPLATE_VARS = {} -if CONFIG.get('TEMPLATE_VARS'): - TEMPLATE_VARS = CONFIG['TEMPLATE_VARS'] +TEMPLATE_VARS['app_name'] = "Subcontractor Invoicing system Demo" +if getenv('TEMPLATE_VARS'): + templateEnvVars = getenv("TEMPLATE_VARS").split(",") + for suffix in templateEnvVars: + TEMPLATE_VARS[suffix] = getenv("TEMPLATE_VARS_"+suffix) +else: + TEMPLATE_VARS['login_info'] = """ +

+ Welcome to a demo Subcontractor Invoicing system. +

+

+ We can design a system that customized specifically for your + use case. +

+

+ Please contact me + if you would like more information. This version has been + specifically designed for a trucking company that continues to + use it more than two years after implementation. +

+

+ + """ -ACCOUNT_ACTIVATION_DAYS = CONFIG['ACCOUNT_ACTIVATION_DAYS'] +try: + ACCOUNT_ACTIVATION_DAYS = int(getenv("ACCOUNT_ACTIVATION_DAYS")) +except Exception: + ACCOUNT_ACTIVATION_DAYS = 7 AUTH_USER_MODEL = 'dispatchAuth.User' @@ -92,7 +119,6 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'dispatch.apps.DispatchConfig', 'dispatchAuth.apps.DispatchauthConfig', - # 'auditlog', ] MIDDLEWARE = [ @@ -104,7 +130,6 @@ MIDDLEWARE = [ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'dispatch.middleware.LoginRequiredMiddleware', - # 'auditlog.middleware.AuditlogMiddleware', ] ROOT_URLCONF = 'app.urls' @@ -128,12 +153,28 @@ TEMPLATES = [ WSGI_APPLICATION = 'app.wsgi.application' +APP_DB_CONF = {} +if getenv('APP_DB_CONF'): + envVars = getenv("APP_DB_CONF").split(",") + for suffix in envVars: + APP_DB_CONF[suffix] = getenv("APP_DB_CONF_"+suffix) +else: + APP_DB_CONF["ENGINE"] = 'django.db.backends.postgresql' + APP_DB_CONF["NAME"] = 'dispatch' + APP_DB_CONF["USER"] = 'postgres' + APP_DB_CONF["PASSWORD"] = '' + APP_DB_CONF["PORT"] = '5432' + +try: + APP_DB_CONF["PORT"] = int(APP_DB_CONF["PORT"]) +except Exception: + APP_DB_CONF["PORT"] = 5432 # Database # https://docs.djangoproject.com/en/1.11/ref/settings/#databases DATABASES = { - 'default': CONFIG['db_default'] + 'default': APP_DB_CONF # 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), @@ -187,7 +228,7 @@ USE_TZ = True # https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/' -STATIC_ROOT = CONFIG['static_root'] +STATIC_ROOT = getenv("STATIC_ROOT") if getenv("STATIC_ROOT") else "/static" LOGIN_URL = '/login/' LOGIN_REDIRECT_URL = '/' diff --git a/app/config-compose.yml b/app/config-compose.yml deleted file mode 100644 index f93b76e..0000000 --- a/app/config-compose.yml +++ /dev/null @@ -1,89 +0,0 @@ ---- -# Postgres Example -db_default: - ENGINE: django.db.backends.postgresql - NAME: dispatch - USER: postgres - PASSWORD: - HOST: postgres - PORT: 5432 -# MySQL Example -# db_default: -# ENGINE: django.db.backends.mysql -# NAME: dispatch_test -# USER: dispatch -# PASSWORD: ahB2lee5 -# HOST: 127.0.0.1 -# PORT: 3306 -# Sqlite example. Full path is recommended -# db_default: -# ENGINE: django.db.backends.sqlite3 -# NAME: /home/mitch/scm/dispatch-tracker/app/db.sqlite3 - -allowed_hosts: - - localhost - - 127.0.0.1 - - 172.21.23.2 - -static_root: '/static' - -debug: True - -# CHANGE THIS BEFORE USING IN PRODUCTION -SECRET_KEY: 'h$r_bwlp@#h#y#%&qhw-n=gb2%wva1d_h65+o94u&!a#%iv&lo' - -# These people will be emailed if debug = false -admins: - - 'bob@example.com' - -application_name: "Yo Momma's Dispatch Tracker" -website_uri: 'http://172.21.23.2:8080' - -ACCOUNT_ACTIVATION_DAYS: 7 - -# Email settings won't be loaded from this file if this is false -SET_EMAIL: False -# Email settings, edit for your needs -EMAIL_HOST: smtp.example.com -EMAIL_HOST_PASSWORD: p@$$w0rd9876543210 -EMAIL_HOST_USER: django@example.com -EMAIL_PORT: 2525 -EMAIL_USE_TLS: True -DEFAULT_FROM_EMAIL: webmaster@localhost - -TEMPLATE_VARS: - app_name: Subcontractor Invoicing System Demo - # login_blurb: Login with "admin@example.com", "password" - login_info: | -

- Welcome to a demo Subcontractor Invoicing system. -

-

- We can design a system that customized specifically for your - use case. -

-

- Please contact me - if you would like more information. This version has been - specifically designed for a trucking company that continues to - use it more than two years after implementation. -

-

- - - - - - diff --git a/app/config-example.yml b/app/config-example.yml deleted file mode 100644 index dfc0872..0000000 --- a/app/config-example.yml +++ /dev/null @@ -1,76 +0,0 @@ ---- -# Postgres Example -db_default: - ENGINE: django.db.backends.postgresql - NAME: dispatch - USER: postgres - PASSWORD: - HOST: 127.0.0.1 - PORT: 5432 -# MySQL Example -# db_default: -# ENGINE: django.db.backends.mysql -# NAME: dispatch_test -# USER: dispatch -# PASSWORD: ahB2lee5 -# HOST: 127.0.0.1 -# PORT: 3306 -# Sqlite example. Full path is recommended -# db_default: -# ENGINE: django.db.backends.sqlite3 -# NAME: /home/mitch/scm/dispatch-tracker/app/db.sqlite3 - -allowed_hosts: - - localhost - - 127.0.0.1 - -static_root: '/full/path/to/static/root' - -debug: True - -# CHANGE THIS BEFORE USING IN PRODUCTION -SECRET_KEY: 'h$r_bwlp@#h#y#%&qhw-n=gb2%wva1d_h65+o94u&!a#%iv&lo' - -# These people will be emailed if debug = false -admins: - - 'bob@example.com' - -application_name: "Yo Momma's Dispatch Tracker" -website_uri: 'http://localhost:8080' - -ACCOUNT_ACTIVATION_DAYS: 7 - -# Email settings won't be loaded from this file if this is false -SET_EMAIL: False -# Email settings, edit for your needs -EMAIL_HOST: smtp.example.com -EMAIL_HOST_PASSWORD: p@$$w0rd9876543210 -EMAIL_HOST_USER: django@example.com -EMAIL_PORT: 2525 -EMAIL_USE_TLS: True -DEFAULT_FROM_EMAIL: webmaster@localhost - -TEMPLATE_VARS: - app_name: Subcontractor Invoicing System Demo - login_blurb: Here's an example blurb above the sign-in box. This can be changed according to your needs. - login_info: ' -

- Welcome to a demo Subcontractor Invoicing system. -

-

- We can design a system that works specifically for your - use case. -

-

- Please contact me - if you would like more information. This version has been - specifically designed for a trucking company that continues to - use it more than two years after implementation. -

-

- ' - - - - - diff --git a/app/demo.sh b/app/demo.sh new file mode 100755 index 0000000..79d1815 --- /dev/null +++ b/app/demo.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e +set -x +#shellcheck disable=SC2046 +python="$(find $(echo "$PATH" | tr : '\n') -type f -executable -iname 'python*' | sed 1q)" +manage() { +$python manage.py "$@" +} + +manage migrate +manage setup +manage setup_identity +manage insert_fake_data --companies 20 --users 20 --loads 600 \ + --attachments=True --invoices=True --start-date='-6w' --end-date='+6w' diff --git a/app/requirements.txt b/app/requirements.txt index ac816f3..8cf4ce5 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -8,6 +8,6 @@ Faker==9.2.0 python-dateutil==2.6.0 pytz==2021.3 PyYAML==5.4.1 -six==1.16.0 +# six==1.16.0 sqlparse==0.4.2 text-unidecode==1.3 diff --git a/app/uwsgi.ini b/app/uwsgi.ini deleted file mode 100644 index 2dae309..0000000 --- a/app/uwsgi.ini +++ /dev/null @@ -1,15 +0,0 @@ -[uwsgi] -processes = 1 -threads = 4 - -env = CUSTOM_CONFIG=config-compose.yml - -# use 127.0.0.1 instead of 0.0.0.0 if possible -# this is for a containerized deployment -socket = 0.0.0.0:9200 - -module = wsgi:application - -# uid = uwsgi - -# home = env diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 5ec2862..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,43 +0,0 @@ -version: "3" -services: - nginx: - image: nginx:mainline-alpine - networks: - backend: - ipv4_address: 172.21.23.2 - ports: - - "36200:80" - volumes: - - ./static:/var/www - - ./nginx.conf:/etc/nginx/nginx.conf - - app: - build: . - image: dispatch-app:latest - networks: - backend: - ipv4_address: 172.21.23.3 - working_dir: /app - volumes: - - ./app:/app - - ./static:/var/www - - postgres: - image: postgres:11-alpine - networks: - backend: - ipv4_address: 172.21.23.4 - volumes: - - db-data:/var/lib/postgresql/data - -volumes: - db-data: - -networks: - backend: - driver: bridge - ipam: - driver: default - config: - - subnet: 172.21.23.0/24 - diff --git a/docker-scripts/setup.sh b/docker-scripts/setup.sh deleted file mode 100755 index 6e4ff18..0000000 --- a/docker-scripts/setup.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -# Dumps you to a shell inside of the app container - -docker run --rm -it \ - --network dispatch-tracker_backend \ - -v $(pwd)/static:/static \ - -v $(pwd)/app:/app \ - dispatch-app \ - sh -x -e -c ' - cd /app; - export CUSTOM_CONFIG=config-compose.yml - echo "create database dispatch;" | psql -U postgres -h postgres - python3 ./manage.py collectstatic --no-input - python3 ./manage.py migrate - # python3 ./manage.py createsuperuser - python3 ./manage.py setup - python3 ./manage.py setup_identity - - python3 ./manage.py insert_fake_data --companies 10 --users 10 \ - --loads 400 --start-date='"'"'-16w'"'"' --end-date='"'"'+16w'"'"' \ - --attachments=true \ - --invoices=true' diff --git a/docker-scripts/shell.sh b/docker-scripts/shell.sh deleted file mode 100755 index c9ae91f..0000000 --- a/docker-scripts/shell.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -# Dumps you to a shell inside of the app container - -docker run --rm -it \ - --network dispatch-tracker_backend \ - -e CUSTOM_CONFIG=config-compose.yml \ - -v $(pwd)/static:/static \ - -v $(pwd)/app:/app \ - --user 0 \ - dispatch-app \ - ash diff --git a/docker-scripts/uwsgi.sh b/docker-scripts/uwsgi.sh deleted file mode 100644 index 26c57fe..0000000 --- a/docker-scripts/uwsgi.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -set -e -set -x -cd /app - -uwsgi \ - --socket 0.0.0.0:9200 \ - --env CUSTOM_CONFIG=/app/config.yml \ - --processes 1 \ - --threads 4 \ - --uid uwsgi \ - wsgi:application - -ls -la - - -echo "MOTHERFUCKER" diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..96380af --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,225 @@ +#!/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 +# Bail out if a service stops, poll it every 30 seconds +watchServices 30 +# or if you comment out the above, drop into a shell +# exec /bin/ash "$@" diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index 38b31df..0000000 --- a/nginx.conf +++ /dev/null @@ -1,55 +0,0 @@ -worker_processes 1; - -events { - worker_connections 1024; -} - - -http { - include mime.types; - default_type application/octet-stream; - - sendfile on; - #tcp_nopush on; - - #keepalive_timeout 0; - keepalive_timeout 65; - - gzip on; - - server_tokens off; - - server { - listen 80; - listen [::]:80; - listen 8000; - listen [::]:8000; - server_name localhost; - - location / { - include uwsgi_params; - client_max_body_size 20m; - client_body_timeout 300s; - uwsgi_pass app:9200; - } - - # Pass through the static directory - # This should match whatever is in your config file - location /static { - alias /var/www; - } - location /robots.txt { - alias /var/www/static/robots.txt; - } - - - # Optionally change the log path. - # access_log /var/log/nginx/dispatch.example.com/access.log; - # error_log /var/log/nginx/dispatch.example.com/error.log; - - } - - include conf.d/*.conf; - -} - diff --git a/static/.keep b/static/.keep deleted file mode 100644 index e69de29..0000000 -- cgit v1.2.3