From 89fab2ade28922749909431e903297464e0e726e Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Tue, 6 Feb 2024 21:38:20 +0100 Subject: [PATCH] feat: add Docker image + sample_project entrypoint & setup --- Dockerfile | 24 +++++++++++++++++++++ sample_project/entrypoint.sh | 6 ++++++ sample_project/management/commands/setup.py | 14 ++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 Dockerfile create mode 100755 sample_project/entrypoint.sh create mode 100644 sample_project/management/commands/setup.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..eb477a338 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM python:3.11 + +# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE +# Prevents Python from writing .pyc files to disk +ENV PYTHONDONTWRITEBYTECODE 1 + +# ensures that the python output is sent straight to terminal (e.g. your container log) +# without being first buffered and that you can see the output of your application (e.g. django logs) +# in real time. Equivalent to python -u: https://docs.python.org/3/using/cmdline.html#cmdoption-u +ENV PYTHONUNBUFFERED 1 +# don't cache downloaded pip packages +ENV PIP_NO_CACHE_DIR=1 +# disable version check of pip +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 + +COPY . /app + +RUN pip install /app + +EXPOSE 8000 + +USER nobody + +ENTRYPOINT ["/app/sample_project/entrypoint.sh"] diff --git a/sample_project/entrypoint.sh b/sample_project/entrypoint.sh new file mode 100755 index 000000000..e6dbc13b4 --- /dev/null +++ b/sample_project/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +/app/manage.py migrate +/app/manage.py setup || true +/app/manage.py loaddata sample_project +/app/manage.py runserver 0.0.0.0:8000 diff --git a/sample_project/management/commands/setup.py b/sample_project/management/commands/setup.py new file mode 100644 index 000000000..ecddf4942 --- /dev/null +++ b/sample_project/management/commands/setup.py @@ -0,0 +1,14 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth.models import User +import secrets + + +class Command(BaseCommand): + help = "Set up APIS test instance" + + def handle(self, *app_labels, **options): + password = secrets.token_urlsafe(8) + print(f"Password for admin user is: {password}") + User.objects.create_superuser( + username="admin", email="admin@example.org", password=password + )