diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2019-09-13 23:25:19 -0400 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2019-09-13 23:25:19 -0400 |
| commit | 103d362b6a76f1bc05b038e7e0b68eb5cd37dc26 (patch) | |
| tree | ac52f33767edc25c31ea9f7e71296a1e27c7eb1b | |
| parent | d16ac1fa8e8b7019156ae11267a23d957aed6495 (diff) | |
| download | dispatch-tracker-103d362b6a76f1bc05b038e7e0b68eb5cd37dc26.tar.gz dispatch-tracker-103d362b6a76f1bc05b038e7e0b68eb5cd37dc26.tar.xz | |
failed experiment with running the demo application entirely inside of a docker containerdemo
| -rw-r--r-- | .dockerignore | 2 | ||||
| -rw-r--r-- | Dockerfile | 26 | ||||
| -rw-r--r-- | app/dispatch/management/commands/setup_identity.py | 37 | ||||
| -rw-r--r-- | app/requirements.txt | 2 | ||||
| -rw-r--r-- | app/setup.sh | 12 | ||||
| -rw-r--r-- | app/uwsgi.ini | 9 | ||||
| -rw-r--r-- | etc/nginx/nginx.conf | 44 | ||||
| -rw-r--r-- | etc/profile.d/runit.sh | 1 | ||||
| -rwxr-xr-x | etc/start | 3 | ||||
| -rwxr-xr-x | etc/sv/nginx/run | 3 | ||||
| -rwxr-xr-x | etc/sv/postgres/run | 14 | ||||
| -rw-r--r-- | etc/sv/uwsgi/run | 9 |
12 files changed, 156 insertions, 6 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..69ae62b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +app/env* +app/media diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..63eaa21 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM alpine:latest + +RUN apk update && apk add python3 py3-setuptools py3-virtualenv +RUN apk add postgresql postgresql-client +RUN apk add linux-headers git postgresql-dev gcc python3-dev libc-dev + +COPY app/requirements.txt /requirements.txt +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 + +RUN adduser -h /app -D -H -u 1000 app + +RUN mkdir /app /static +RUN chown -R app /app /static + + +# TODO: add these to the install above +RUN apk add nginx runit + +COPY etc /etc + +CMD [ '/etc/start' ] diff --git a/app/dispatch/management/commands/setup_identity.py b/app/dispatch/management/commands/setup_identity.py new file mode 100644 index 0000000..3251d4e --- /dev/null +++ b/app/dispatch/management/commands/setup_identity.py @@ -0,0 +1,37 @@ +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth import get_user_model +from dispatch.models import Identity +from faker import Faker +import random + +from django.db.utils import IntegrityError + +# import yaml + +User = get_user_model() + + +class Command(BaseCommand): + help = "with " + + def add_arguments(self, parser): + # parser.add_argument('--file', type=str, dest='filename') + parser.add_argument('--name', type=str, dest='name', default='My Company') + parser.add_argument('--address', type=str, dest='address', default='123 Main St') + parser.add_argument('--city', type=str, dest='city', default='Demoville') + parser.add_argument('--state', type=str, dest='state', default='Michigan') + parser.add_argument('--zip', type=str, dest='zip', default='49503') + + + def handle(self, *args, **options): + u = User.objects.first() + + ident = Identity( + user=u, + name=options['name'], + address=options['address'], + city=options['city'], + state=options['state'], + zip_code=options['zip']) + ident.save() + ident.set_default() diff --git a/app/requirements.txt b/app/requirements.txt index c4f2f33..954ca4a 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,4 +1,4 @@ -Django==1.11.5 +Django==1.11.24 django-auditlog==0.4.3 django-jsonfield==1.0.1 Faker==0.8.4 diff --git a/app/setup.sh b/app/setup.sh new file mode 100644 index 0000000..fb6ca4b --- /dev/null +++ b/app/setup.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +manage="python3 manage.py" + +echo "create database dispatch;" | psql -U postgres +$manage migrate +$manage createsuperuser +$manage setup_identity +$manage insert_fake_data --companies 10 --users 10 \ + --loads 400 --start-date='-16w' --end-date='+16w' +# $manage runserver 0.0.0.0:8080 + diff --git a/app/uwsgi.ini b/app/uwsgi.ini index 829d185..c5a363c 100644 --- a/app/uwsgi.ini +++ b/app/uwsgi.ini @@ -2,13 +2,12 @@ processes = 1 threads = 4 -env = CUSTOM_CONFIG=config.yml +env = CUSTOM_CONFIG=/app/config.yml socket = 127.0.0.1:9200 module = wsgi:application -daemonize=uwsgi.log -pidfile=uwsgi.pid - -home = env +# daemonize=uwsgi.log +# pidfile=uwsgi.pid +# home = env diff --git a/etc/nginx/nginx.conf b/etc/nginx/nginx.conf new file mode 100644 index 0000000..1235f67 --- /dev/null +++ b/etc/nginx/nginx.conf @@ -0,0 +1,44 @@ +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; + server_name localhost; + + location / { + include uwsgi_params; + client_max_body_size 20m; + client_body_timeout 300s; + uwsgi_pass 127.0.0.1:9200; + } + + location /static { + alias /static; + } + location /robots.txt { + alias /static/robots.txt; + } + + } + + include conf.d/*.conf; + +} diff --git a/etc/profile.d/runit.sh b/etc/profile.d/runit.sh new file mode 100644 index 0000000..c114c7e --- /dev/null +++ b/etc/profile.d/runit.sh @@ -0,0 +1 @@ +export SVDIR=/etc/sv diff --git a/etc/start b/etc/start new file mode 100755 index 0000000..808ee81 --- /dev/null +++ b/etc/start @@ -0,0 +1,3 @@ +#!/bin/sh + +exec runsvdir -P /etc/sv "log: ...................................................................................." diff --git a/etc/sv/nginx/run b/etc/sv/nginx/run new file mode 100755 index 0000000..edc430d --- /dev/null +++ b/etc/sv/nginx/run @@ -0,0 +1,3 @@ +#!/bin/sh +mkdir -p /run/nginx +exec nginx -g 'daemon off;' diff --git a/etc/sv/postgres/run b/etc/sv/postgres/run new file mode 100755 index 0000000..dafcfe3 --- /dev/null +++ b/etc/sv/postgres/run @@ -0,0 +1,14 @@ +#!/bin/sh +set -e +pguser="postgres" + +PGDATA="/postgres" +if ! [ -d "$PGDATA" ] ; then + mkdir -p "$PGDATA" + chown -R "$pguser" "$PGDATA" + chmod 700 "$PGDATA" + su - postgres -m -c "pg_ctl initdb -D \"$PGDATA\"" +fi + +mkdir -p /run/postgresql && chown "$pguser" /run/postgresql +exec chpst -u postgres:postgres postgres -D "$PGDATA" 2>&1 diff --git a/etc/sv/uwsgi/run b/etc/sv/uwsgi/run new file mode 100644 index 0000000..a5762d8 --- /dev/null +++ b/etc/sv/uwsgi/run @@ -0,0 +1,9 @@ +#!/bin/sh +set -e +set -x +sv check postgres 2>&1 >/dev/null || exit 1 +if ! [ -e /setup ] ; then + su -l app -c "/bin/sh /app/setup.sh" + touch /setup +fi +uwsgi --ini /app/uwsgi.ini |
