From c49d9e0d69685d022fa6ffaa04f91bbe46f67551 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Wed, 27 Mar 2019 23:06:36 -0400 Subject: Fully dockerized environment --- Dockerfile | 33 +++++++++++++++++++-- app/config-compose.yml | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ app/uwsgi.ini | 11 +++---- docker-compose.yml | 33 ++++++++++++++++----- docker-scripts/setup.sh | 28 ++++++++++++++++++ docker-scripts/shell.sh | 11 +++++++ docker-scripts/uwsgi.sh | 17 +++++++++++ nginx.conf | 48 +++++++++++++++++++++++++++++++ static/.keep | 0 9 files changed, 242 insertions(+), 15 deletions(-) create mode 100644 app/config-compose.yml create mode 100755 docker-scripts/setup.sh create mode 100755 docker-scripts/shell.sh create mode 100644 docker-scripts/uwsgi.sh create mode 100644 nginx.conf create mode 100644 static/.keep diff --git a/Dockerfile b/Dockerfile index 1b26b25..62693b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,35 @@ RUN apk add postgresql-dev gcc python3-dev libc-dev COPY app/requirements.txt /requirements.txt -RUN pip3 install -r /requirements.txt +RUN pip3 install --no-cache-dir -r /requirements.txt -COPY app/ /app/ +RUN apk add linux-headers -VOLUME ['/var/lib/dispatch'] +RUN pip3 install --no-cache-dir uwsgi + +RUN apk del linux-headers + +RUN apk add postgresql-client + +# Feel free to change the UID if necessary +RUN adduser -D -H -u 1000 uwsgi + +# RUN apk add uwsgi-python3 + +RUN rm /requirements.txt + +RUN mkdir /app && chown uwsgi /app +RUN mkdir /static && chown uwsgi /static + +USER uwsgi + +CMD [ "uwsgi", "--ini", "/app/uwsgi.ini" ] + +# WORKDIR /app + +# CMD [ "uwsgi", "--socket", "0.0.0.0:9200", \ +# "--env", "CUSTOM_CONFIG=/app/config.yml", \ +# "--processes", "1", \ +# "--threads", "4", \ +# "--uid", "uwsgi", \ +# "wsgi:application" ] diff --git a/app/config-compose.yml b/app/config-compose.yml new file mode 100644 index 0000000..ddbf18b --- /dev/null +++ b/app/config-compose.yml @@ -0,0 +1,76 @@ +--- +# 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: 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 us + if you would like more information. This version has been + specifically designed for use by a trucking company. +

+

+ ' + + + + + diff --git a/app/uwsgi.ini b/app/uwsgi.ini index 829d185..2dae309 100644 --- a/app/uwsgi.ini +++ b/app/uwsgi.ini @@ -2,13 +2,14 @@ processes = 1 threads = 4 -env = CUSTOM_CONFIG=config.yml +env = CUSTOM_CONFIG=config-compose.yml -socket = 127.0.0.1:9200 +# 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 -daemonize=uwsgi.log -pidfile=uwsgi.pid +# uid = uwsgi -home = env +# home = env diff --git a/docker-compose.yml b/docker-compose.yml index 1d2d69a..b4c08e0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,41 @@ version: "3" services: - web: - image: dispatch + nginx: + image: nginx:mainline-alpine networks: - - backend + backend: + ipv4_address: 172.21.23.2 volumes: - - web-storage:/var/lib/dispatch - + - ./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.2 networks: - - backend + backend: + ipv4_address: 172.21.23.4 volumes: - db-data:/var/lib/postgresql/data volumes: db-data: - web-storage: 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 new file mode 100755 index 0000000..e036aa8 --- /dev/null +++ b/docker-scripts/setup.sh @@ -0,0 +1,28 @@ +#!/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 + python3 ./manage.py migrate + python3 ./manage.py createsuperuser + + v="" + while ! [ "$v" = "done" ] ; do + printf "Please login to the system and fill out the form," + printf "then come back, type \"done\" to continue:\t" + read v; + done + + 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 new file mode 100755 index 0000000..4a417c0 --- /dev/null +++ b/docker-scripts/shell.sh @@ -0,0 +1,11 @@ +#!/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 \ + --user 0 \ + dispatch-app \ + ash diff --git a/docker-scripts/uwsgi.sh b/docker-scripts/uwsgi.sh new file mode 100644 index 0000000..26c57fe --- /dev/null +++ b/docker-scripts/uwsgi.sh @@ -0,0 +1,17 @@ +#!/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/nginx.conf b/nginx.conf new file mode 100644 index 0000000..6f9fafa --- /dev/null +++ b/nginx.conf @@ -0,0 +1,48 @@ +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; + } + + location /static { + alias /var/www; + } + location /robots.txt { + alias /var/www/static/robots.txt; + } + + } + + include conf.d/*.conf; + +} + diff --git a/static/.keep b/static/.keep new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3