Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Docker image + sample_project entrypoint & setup #877

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 6 additions & 0 deletions sample_project/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions sample_project/management/commands/setup.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]", password=password
)
Loading