From 0b89afc16bebee405979d046258426c587e243ab Mon Sep 17 00:00:00 2001 From: Paolo Greppi Date: Thu, 7 Sep 2023 15:42:56 +0200 Subject: [PATCH] dockerize, fixes #826 --- Dockerfile | 44 ++++++++++++++++++++++++++++++++++++++++++++ README.rst | 10 ++++++++-- entrypoint | 14 ++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 entrypoint diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e325b33f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +ARG PYTHON_VERSION=3.11.5-slim-bookworm + +# define an alias for the specfic python version used in this file. +FROM python:${PYTHON_VERSION} as python + +FROM python as python-build-stage + +# Install apt packages +RUN apt-get update && apt-get install --no-install-recommends -y \ + # dependencies for building Python packages + build-essential + +# Requirements are installed here to ensure they will be cached. +COPY ./requirements.txt ./requirements-dev.txt / + +# Create Python Dependency and Sub-Dependency Wheels +RUN pip wheel --wheel-dir /usr/src/app/wheels \ + -r requirements.txt \ + -r requirements-dev.txt + +FROM python as python-run-stage + +ARG APP_HOME=/app + +ENV PYTHONUNBUFFERED 1 +ENV PYTHONDONTWRITEBYTECODE 1 + +WORKDIR ${APP_HOME} + +COPY --from=python-build-stage /usr/src/app/wheels /wheels/ + +# use wheels to install python dependencies +RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \ + && rm -rf /wheels/ + +COPY ./entrypoint /entrypoint +RUN sed -i 's/\r$//g' /entrypoint && chmod +x /entrypoint + +FROM python-run-stage AS backend + +# copy application code to WORKDIR +COPY . ${APP_HOME} + +ENTRYPOINT ["/entrypoint"] diff --git a/README.rst b/README.rst index 5eae9856..16a25755 100644 --- a/README.rst +++ b/README.rst @@ -27,11 +27,17 @@ get started with testing or developing `django-helpdesk`. The demo project resides in the `demo/` top-level folder. It's likely that you can start up a demo project server by running -only the command:: +only the command: make rundemo -then pointing your web browser at `localhost:8080`. +or with docker: + + docker build . -t demodesk + docker run --rm -v "$PWD:/app" -p 8080:8080 demodesk + +then pointing your web browser at http://localhost:8080 (log in as user +`admin`` with password `Test1234`). For more information and options, please read the `demo/README.rst` file. diff --git a/entrypoint b/entrypoint new file mode 100644 index 00000000..922eca95 --- /dev/null +++ b/entrypoint @@ -0,0 +1,14 @@ +#!/bin/bash + +set -o errexit +set -o pipefail +set -o nounset + +pip3 install -e . --user || pip3 install -e . +pip3 install -e demo --user || pip3 install -e demo +python3 demo/manage.py migrate --noinput +DJANGO_SUPERUSER_PASSWORD=Test1234 python3 demo/manage.py createsuperuser --username admin --email helpdesk@example.com --noinput +# Install fixtures +python3 demo/manage.py loaddata emailtemplate.json +python3 demo/manage.py loaddata demo.json +python3 demo/manage.py runserver 0:8080