From 4769c8b5e3ba70301b1123c5750429b2092b01b1 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Sat, 28 Sep 2019 06:20:07 +1000 Subject: Create custom manage.py entry point, remove scripts and merge Dockerfile. --- docker/Dockerfile | 26 ++++++++++++++ docker/app/Dockerfile | 27 --------------- docker/app/build-wiki.Dockerfile | 2 -- docker/app/local.Dockerfile | 28 --------------- docker/app/scripts/build-wiki.sh | 4 --- docker/app/scripts/migrate.sh | 10 ------ docker/app/scripts/migrate_and_serve.sh | 21 ------------ docker/app/uwsgi.ini | 38 --------------------- .../wiki-0.5.dev20190420204942-py3-none-any.whl | Bin 1287002 -> 0 bytes docker/uwsgi.ini | 38 +++++++++++++++++++++ .../wiki-0.5.dev20190420204942-py3-none-any.whl | Bin 0 -> 1287002 bytes 11 files changed, 64 insertions(+), 130 deletions(-) create mode 100644 docker/Dockerfile delete mode 100644 docker/app/Dockerfile delete mode 100644 docker/app/build-wiki.Dockerfile delete mode 100644 docker/app/local.Dockerfile delete mode 100644 docker/app/scripts/build-wiki.sh delete mode 100755 docker/app/scripts/migrate.sh delete mode 100755 docker/app/scripts/migrate_and_serve.sh delete mode 100644 docker/app/uwsgi.ini delete mode 100644 docker/app/wheels/wiki-0.5.dev20190420204942-py3-none-any.whl create mode 100644 docker/uwsgi.ini create mode 100644 docker/wheels/wiki-0.5.dev20190420204942-py3-none-any.whl (limited to 'docker') diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..aa427947 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.7-slim + +# Allow service to handle stops gracefully +STOPSIGNAL SIGQUIT + +# Set pip to have cleaner logs and no saved cache +ENV PIP_NO_CACHE_DIR=false \ + PIPENV_HIDE_EMOJIS=1 \ + PIPENV_NOSPIN=1 + +# Create non-root user. +RUN useradd --system --shell /bin/false --uid 1500 pysite + +# Install pipenv +RUN pip install -U pipenv + +# Copy the project files into working directory +WORKDIR /app +COPY . . + +# Install project dependencies +RUN pipenv install --system --deploy + +# Run web server through custom manager +ENTRYPOINT ["python", "manage.py"] +CMD ["run"] diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile deleted file mode 100644 index a6986fb2..00000000 --- a/docker/app/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -FROM python:3.7-slim - -# Allow service to handle stops gracefully -STOPSIGNAL SIGQUIT - -# Set pip to have cleaner logs and no saved cache -ENV PIP_NO_CACHE_DIR=false \ - PIPENV_HIDE_EMOJIS=1 \ - PIPENV_NOSPIN=1 - -# Create non-root user. -RUN useradd --system --shell /bin/false --uid 1500 pysite - -# Install pipenv & pyuwsgi -RUN pip install -U pipenv pyuwsgi - -# Copy the project files into working directory -WORKDIR /app -COPY . . - -# Install project dependencies -RUN pipenv install --system --deploy - -# Migrate, collect and start the app -RUN chmod +x /app/docker/app/scripts/migrate.sh -ENTRYPOINT ["/app/docker/app/scripts/migrate.sh"] -CMD ["uwsgi", "--ini", "docker/app/uwsgi.ini"] diff --git a/docker/app/build-wiki.Dockerfile b/docker/app/build-wiki.Dockerfile deleted file mode 100644 index 92003377..00000000 --- a/docker/app/build-wiki.Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM python:3.7 -RUN pip --no-cache-dir wheel --wheel-dir=/wheels "wiki @ git+https://github.com/python-discord/django-wiki.git" diff --git a/docker/app/local.Dockerfile b/docker/app/local.Dockerfile deleted file mode 100644 index 9e15c438..00000000 --- a/docker/app/local.Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -FROM python:3.7-slim - -# Allow service to handle stops gracefully -STOPSIGNAL SIGQUIT - -# Set pip to have cleaner logs and no saved cache -ENV PIP_NO_CACHE_DIR=false \ - PIPENV_HIDE_EMOJIS=1 \ - PIPENV_NOSPIN=1 - -# Create non-root user -RUN useradd --system --shell /bin/false --uid 1500 pysite - -# Install pipenv & pyuwsgi -RUN pip install -U pipenv pyuwsgi - -# Copy the project files into working directory -WORKDIR /app -COPY . . - -# Install project dependencies -RUN pipenv install --system --deploy - -# Prepare static files for site -RUN SECRET_KEY=placeholder DATABASE_URL=sqlite:// \ - python3 manage.py collectstatic --no-input --clear --verbosity 0 - -CMD ["uwsgi", "--ini", "docker/app/uwsgi.ini"] diff --git a/docker/app/scripts/build-wiki.sh b/docker/app/scripts/build-wiki.sh deleted file mode 100644 index 07c54f66..00000000 --- a/docker/app/scripts/build-wiki.sh +++ /dev/null @@ -1,4 +0,0 @@ -docker build -t build_uwsgi -f docker/app/build-wiki.Dockerfile . -CONTAINER=$(docker run -itd build_uwsgi /bin/bash) -docker cp "$CONTAINER:/wheels" docker/app -docker stop "$CONTAINER" diff --git a/docker/app/scripts/migrate.sh b/docker/app/scripts/migrate.sh deleted file mode 100755 index 22636c93..00000000 --- a/docker/app/scripts/migrate.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -echo --- Applying migrations --- -python manage.py migrate --verbosity 1 - -echo --- Collecting static files --- -python manage.py collectstatic --no-input --clear --verbosity 1 - -echo --- Starting uwsgi --- -exec "$@" # This runs the CMD at the end of the Dockerfile diff --git a/docker/app/scripts/migrate_and_serve.sh b/docker/app/scripts/migrate_and_serve.sh deleted file mode 100755 index c30d7e04..00000000 --- a/docker/app/scripts/migrate_and_serve.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -set -eu - -### NOTE -# This file is intended to be used by local setups. -# You do not want to run the Django development server -# in production. The default Dockerfile command will -# run using uWSGI, this script is provided purely as -# a convenience to run migrations and start a development server. - -echo [i] Applying migrations. -python manage.py migrate --verbosity 1 - -echo [i] Collecting static files. -python manage.py collectstatic --no-input --clear --verbosity 1 - -echo [i] Creating a superuser. -echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin', 'admin') if not User.objects.filter(username='admin').exists() else print('Admin user already exists')" | python manage.py shell - -echo [i] Starting server. -python manage.py runserver 0.0.0.0:8000 diff --git a/docker/app/uwsgi.ini b/docker/app/uwsgi.ini deleted file mode 100644 index 3f35258c..00000000 --- a/docker/app/uwsgi.ini +++ /dev/null @@ -1,38 +0,0 @@ -[uwsgi] -### Exposed ports -# uWSGI protocol socket -socket = :4000 - -### File settings -# WSGI application -wsgi = pydis_site.wsgi:application -# Directory to move into at startup -chdir = /app - -### Concurrency options -# Run a master to supervise the workers -master = true -# Keep a minimum of 1 worker -cheaper = 1 -# Allow a maximum of 4 workers -workers = 4 -# Automatically set up meanginful process names -auto-procname = true -# Prefix process names with `pydis_site : ` -procname-prefix-spaced = pydis_site : - -### Worker options -# Kill workers if they take more than 30 seconds to respond. -harakiri = 30 - -### Startup settings -# Exit if we can't load the app -need-app = true -# `setuid` to an unprivileged user -uid = 1500 -# Do not use multiple interpreters -single-interpreter = true - -### Hook setup -# Gracefully kill workers on `SIGQUIT` -hook-master-start = unix_signal:3 gracefully_kill_them_all diff --git a/docker/app/wheels/wiki-0.5.dev20190420204942-py3-none-any.whl b/docker/app/wheels/wiki-0.5.dev20190420204942-py3-none-any.whl deleted file mode 100644 index b7637e76..00000000 Binary files a/docker/app/wheels/wiki-0.5.dev20190420204942-py3-none-any.whl and /dev/null differ diff --git a/docker/uwsgi.ini b/docker/uwsgi.ini new file mode 100644 index 00000000..3f35258c --- /dev/null +++ b/docker/uwsgi.ini @@ -0,0 +1,38 @@ +[uwsgi] +### Exposed ports +# uWSGI protocol socket +socket = :4000 + +### File settings +# WSGI application +wsgi = pydis_site.wsgi:application +# Directory to move into at startup +chdir = /app + +### Concurrency options +# Run a master to supervise the workers +master = true +# Keep a minimum of 1 worker +cheaper = 1 +# Allow a maximum of 4 workers +workers = 4 +# Automatically set up meanginful process names +auto-procname = true +# Prefix process names with `pydis_site : ` +procname-prefix-spaced = pydis_site : + +### Worker options +# Kill workers if they take more than 30 seconds to respond. +harakiri = 30 + +### Startup settings +# Exit if we can't load the app +need-app = true +# `setuid` to an unprivileged user +uid = 1500 +# Do not use multiple interpreters +single-interpreter = true + +### Hook setup +# Gracefully kill workers on `SIGQUIT` +hook-master-start = unix_signal:3 gracefully_kill_them_all diff --git a/docker/wheels/wiki-0.5.dev20190420204942-py3-none-any.whl b/docker/wheels/wiki-0.5.dev20190420204942-py3-none-any.whl new file mode 100644 index 00000000..b7637e76 Binary files /dev/null and b/docker/wheels/wiki-0.5.dev20190420204942-py3-none-any.whl differ -- cgit v1.2.3