From 69a8177c4bc02f1f17a9cd77649303372e70c21c Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Mon, 20 Feb 2023 15:49:17 +0100 Subject: [PATCH] Improve docker setup - add .dockerignore - add entrypoint.sh to switch to user after initial setup - downgrade importlib-metadata for Celery compatibility - add TZ environment variable for consistent Celery timestamps - fix Celery setting deprecation warnings --- .dockerignore | 17 +++++++++++++++++ Dockerfile | 8 +++----- entrypoint.sh | 5 +++++ gvapgsql.sh | 3 ++- gvapgsql/pgsqltasks/settings.py | 20 ++++++++++---------- poetry.lock | 10 +++++----- pyproject.toml | 1 + 7 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 .dockerignore create mode 100755 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ac1c6f1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +**/*.pyc +**/.*.swp +**/.coverage +**/__pycache__ +.dockerignore +.env +.envrc +.git +.gitignore +.idea +.vagrant +Dockerfile +Vagrantfile +change-vmdebootstrap-default-dhcp.sh +coverage-report +docs +salt diff --git a/Dockerfile b/Dockerfile index 06dbbef..62a58b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,10 +59,8 @@ RUN addgroup --gid $GVAGID $GVAAPP ; \ COPY --chown=$GVAAPP:$GVAAPP --from=builder /srv/$GVAAPP/.venv /srv/$GVAAPP/.venv -USER $GVAAPP +VOLUME /srv/$GVAAPP/$GVAAPP -VOLUME /srv/$GVAAPP +COPY ${GVAAPP}.sh entrypoint.sh /srv/ -COPY ${GVAAPP}.sh /srv/ - -ENTRYPOINT ["dumb-init", "/srv/${GVAAPP}.sh"] +ENTRYPOINT ["dumb-init", "/srv/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..a9805b2 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +su -c /srv/gvapgsql.sh gvapgsql diff --git a/gvapgsql.sh b/gvapgsql.sh index e2f5163..66e96ce 100755 --- a/gvapgsql.sh +++ b/gvapgsql.sh @@ -5,7 +5,8 @@ set -e QUEUE=pgsql TASKS=${QUEUE}tasks APP=gvapgsql +export TZ="Europe/Berlin" . "/srv/${APP}/.venv/bin/activate" cd /srv/${APP}/${APP} -celery -A "${TASKS}" worker -Q "${QUEUE}" -l info +celery -A "${TASKS}" worker -Q "${QUEUE}" -E -l info diff --git a/gvapgsql/pgsqltasks/settings.py b/gvapgsql/pgsqltasks/settings.py index f8b1f38..efcd7f1 100644 --- a/gvapgsql/pgsqltasks/settings.py +++ b/gvapgsql/pgsqltasks/settings.py @@ -25,16 +25,16 @@ def get_env_setting(setting): ########## CELERY CONFIGURATION -CELERY_BROKER_URL = get_env_setting("GVAPGSQL_BROKER_URL") -CELERY_RESULT_BACKEND = get_env_setting("GVAPGSQL_RESULTS_REDIS_URL") -CELERY_RESULT_PERSISTENT = True -CELERY_TASK_RESULT_EXPIRES = None -CELERY_ROUTES = ("gvacommon.celeryrouters.GvaRouter",) -CELERY_TIMEZONE = "Europe/Berlin" -CELERY_ENABLE_UTC = True -CELERY_ACCEPT_CONTENT = ["json"] -CELERY_TASK_SERIALIZER = "json" -CELERY_RESULT_SERIALIZER = "json" +accept_content = ["json"] +broker_url = get_env_setting("GVAPGSQL_BROKER_URL") +enable_utc = True +result_backend = get_env_setting("GVAPGSQL_RESULTS_REDIS_URL") +result_expires = None +result_persistent = True +result_serializer = "json" +task_routes = ("gvacommon.celeryrouters.GvaRouter",) +task_serializer = "json" +timezone = "Europe/Berlin" ########## END CELERY CONFIGURATION ########## GVAPGSQL CONFIGURATION diff --git a/poetry.lock b/poetry.lock index bb49e88..d979552 100644 --- a/poetry.lock +++ b/poetry.lock @@ -427,14 +427,14 @@ files = [ [[package]] name = "importlib-metadata" -version = "6.0.0" +version = "4.13.0" description = "Read metadata from Python packages" category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "importlib_metadata-6.0.0-py3-none-any.whl", hash = "sha256:7efb448ec9a5e313a57655d35aa54cd3e01b7e1fbcf72dce1bf06119420f5bad"}, - {file = "importlib_metadata-6.0.0.tar.gz", hash = "sha256:e354bedeb60efa6affdcc8ae121b73544a7aa74156d047311948f6d711cd378d"}, + {file = "importlib_metadata-4.13.0-py3-none-any.whl", hash = "sha256:8a8a81bcf996e74fee46f0d16bd3eaa382a7eb20fd82445c3ad11f4090334116"}, + {file = "importlib_metadata-4.13.0.tar.gz", hash = "sha256:dd0173e8f150d6815e098fd354f6414b0f079af4644ddfe90c71e2fc6174346d"}, ] [package.dependencies] @@ -442,7 +442,7 @@ typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} zipp = ">=0.5" [package.extras] -docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)"] perf = ["ipython"] testing = ["flake8 (<5)", "flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)"] @@ -991,4 +991,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "eaa5e669e28c6448e91e4edbfb8c4608928696547437ec35b19e6615af8dbb6f" +content-hash = "fc678ede4b6df2320ce8b82c4f4bfbdce9fb10630fd390c4a2965c39c21bd94c" diff --git a/pyproject.toml b/pyproject.toml index 8fde229..733b219 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ python = "^3.7" celery = "^5.2.7" redis = "^4.5.1" psycopg2-binary = "^2.9.5" +importlib-metadata = "<5" [tool.poetry.group.dev.dependencies]