From e3ab204f621d6483710d871c53ff73a3c1600f74 Mon Sep 17 00:00:00 2001 From: Luca Date: Sat, 14 Oct 2023 23:46:19 +0200 Subject: [PATCH] Dockerize application --- .dockerignore | 8 ++++++++ Dockerfile | 28 ++++++++++++++++++++++++++++ docker-compose.yml | 11 +++++++++++ docker/entrypoint.sh | 12 ++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 docker/entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fd52388 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +**/.git* +**/__pycache__ +*.md +.dockerignore +.env* +Dockerfile +db.sqlite3 +docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7e1f19f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM python:3.11-alpine3.18 AS requirements + +WORKDIR /workdir + +RUN pip --no-cache-dir install poetry + +COPY poetry.lock pyproject.toml /workdir/ +RUN poetry export -f requirements.txt -o /requirements.txt + + +FROM python:3.11-alpine3.18 + +ENV PORT=8000 + +WORKDIR /app + +RUN pip --no-cache-dir install gunicorn + +COPY --from=requirements /requirements.txt /app/ +RUN pip --no-cache-dir install -r requirements.txt + +COPY LICENSE manage.py /app/ +COPY ljg /app/ljg/ +COPY docker/entrypoint.sh / + +EXPOSE 8000 + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a9f8b06 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +--- + +services: + app: + build: . + restart: unless-stopped + env_file: .env + ports: + - 127.0.0.1:8000:8000 + volumes: + - ./db.sqlite3:/app/db.sqlite3 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..267bd3a --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -ex + +python manage.py migrate + +if [ -z "$1" ] || [ "${1%-}" != "$1" ] +then + exec gunicorn ljg.wsgi "$@" +fi + +exec "$@"