From 1902147f820c6cc3d6479fdb5290acad0581d914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Krop=C3=A1=C4=8Dek?= Date: Sat, 17 Aug 2024 21:28:13 +0200 Subject: [PATCH] application dockerized --- .dockerignore | 4 ++ Dockerfile | 48 ++++++++++++++++++++ poetry.lock | 88 ++++++++++++++++++++++++++++++++++++- pyproject.toml | 3 ++ scripts/entrypoint.sh | 5 +++ scripts/run.sh | 7 +++ {utils => scripts}/start.sh | 0 7 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 scripts/entrypoint.sh create mode 100644 scripts/run.sh rename {utils => scripts}/start.sh (100%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9eb9db7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git/ +.idea/ +*.drawio +.ruff_cache/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ac608cd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +ARG PYTHON_VERSION=3.12 + +FROM python:${PYTHON_VERSION}-alpine AS base + +ENV PYTHONUNBUFFERED=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + DEBIAN_FRONTEND=noninteractive \ + POETRY_VIRTUALENVS_CREATE=false \ + VENV=/root/.venv + + +RUN adduser --disabled-password --gecos "" django + +FROM base as poetry + +ARG POETRY_VERSION=1.8.3 + +RUN : \ + && python -m venv ${VENV} \ + && . ${VENV}/bin/activate \ + && pip install poetry==${POETRY_VERSION} \ + && : + +ENV PATH="${VENV}/bin:${PATH}" + +FROM poetry as deps + +WORKDIR /app + +COPY pyproject.toml poetry.lock ./ + +RUN poetry install --no-interaction --no-ansi -vvv + +COPY scripts/ /usr/local/tmp-bin + +RUN chmod +x /usr/local/tmp-bin/* \ + && mv /usr/local/tmp-bin/* /usr/local/bin \ + && rmdir /usr/local/tmp-bin + +ENTRYPOINT ["entrypoint.sh"] + +FROM deps as production + +WORKDIR /app + +COPY --chown=django . . + +CMD ["run.sh"] diff --git a/poetry.lock b/poetry.lock index 7cf0189..025fd0e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -138,6 +138,31 @@ files = [ {file = "charset_normalizer-3.3.2-py3-none-any.whl", hash = "sha256:3e4d1f6587322d2788836a99c69062fbb091331ec940e02d12d179c1d53e25fc"}, ] +[[package]] +name = "click" +version = "8.1.7" +description = "Composable command line interface toolkit" +optional = false +python-versions = ">=3.7" +files = [ + {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, + {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + [[package]] name = "crispy-bootstrap5" version = "2023.10" @@ -206,6 +231,38 @@ develop = ["coverage[toml] (>=5.0a4)", "furo (>=2021.8.17b43,<2021.9.dev0)", "py docs = ["furo (>=2021.8.17b43,<2021.9.dev0)", "sphinx (>=3.5.0)", "sphinx-notfound-page"] testing = ["coverage[toml] (>=5.0a4)", "pytest (>=4.6.11)"] +[[package]] +name = "gunicorn" +version = "23.0.0" +description = "WSGI HTTP Server for UNIX" +optional = false +python-versions = ">=3.7" +files = [ + {file = "gunicorn-23.0.0-py3-none-any.whl", hash = "sha256:ec400d38950de4dfd418cff8328b2c8faed0edb0d517d3394e457c317908ca4d"}, + {file = "gunicorn-23.0.0.tar.gz", hash = "sha256:f014447a0101dc57e294f6c18ca6b40227a4c90e9bdb586042628030cba004ec"}, +] + +[package.dependencies] +packaging = "*" + +[package.extras] +eventlet = ["eventlet (>=0.24.1,!=0.36.0)"] +gevent = ["gevent (>=1.4.0)"] +setproctitle = ["setproctitle"] +testing = ["coverage", "eventlet", "gevent", "pytest", "pytest-cov"] +tornado = ["tornado (>=0.2)"] + +[[package]] +name = "h11" +version = "0.14.0" +description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" +optional = false +python-versions = ">=3.7" +files = [ + {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, + {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, +] + [[package]] name = "idna" version = "3.7" @@ -217,6 +274,17 @@ files = [ {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, ] +[[package]] +name = "packaging" +version = "24.1" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.8" +files = [ + {file = "packaging-24.1-py3-none-any.whl", hash = "sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"}, + {file = "packaging-24.1.tar.gz", hash = "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002"}, +] + [[package]] name = "requests" version = "2.32.3" @@ -281,7 +349,25 @@ h2 = ["h2 (>=4,<5)"] socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] zstd = ["zstandard (>=0.18.0)"] +[[package]] +name = "uvicorn" +version = "0.30.6" +description = "The lightning-fast ASGI server." +optional = false +python-versions = ">=3.8" +files = [ + {file = "uvicorn-0.30.6-py3-none-any.whl", hash = "sha256:65fd46fe3fda5bdc1b03b94eb634923ff18cd35b2f084813ea79d1f103f711b5"}, + {file = "uvicorn-0.30.6.tar.gz", hash = "sha256:4b15decdda1e72be08209e860a1e10e92439ad5b97cf44cc945fcbee66fc5788"}, +] + +[package.dependencies] +click = ">=7.0" +h11 = ">=0.8" + +[package.extras] +standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)", "pyyaml (>=5.1)", "uvloop (>=0.14.0,!=0.15.0,!=0.15.1)", "watchfiles (>=0.13)", "websockets (>=10.4)"] + [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "fc91f96209fbdf439cf9da459e6b98e3897b9672d0250bc97a7622a190006ff4" +content-hash = "b23715e240b100e65d717f81ec69f1f9fa5ef542cdba6e3c97841789625bc13b" diff --git a/pyproject.toml b/pyproject.toml index 1d7040f..79521b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ description = "" authors = ["Jakub Kropáček "] license = "MIT" readme = "README.md" +package-mode = false [tool.poetry.dependencies] python = "^3.12" @@ -13,6 +14,8 @@ crispy-bootstrap5 = "^2023.10" django-crispy-forms = "^2.1" ares-util = "^0.3.0" django-environ = "^0.11.2" +gunicorn = "^23.0.0" +uvicorn = "^0.30.6" [build-system] diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh new file mode 100644 index 0000000..d30078a --- /dev/null +++ b/scripts/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +#wait-for-it --service db:5432 -- echo "database is running" + +exec "$@" diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100644 index 0000000..85477fa --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,7 @@ +#/bin/sh + +gunicorn \ + --threads 2 \ + --workers 4 \ + --worker-class uvicorn.workers.UvicornWorker \ + facturio.asgi diff --git a/utils/start.sh b/scripts/start.sh similarity index 100% rename from utils/start.sh rename to scripts/start.sh