Improve docker setup

- add .dockerignore to reduce build context
- add entrypoint.sh to initialize environment before user switch
- fix Celery setting deprecation warnings
- downgrade importlib-metadata for Celery compatibility
- set TZ environment variable for consistent Celery timestamps
This commit is contained in:
Jan Dittberner 2023-02-20 15:59:08 +01:00
parent 2575afb9f9
commit 88253ee37d
7 changed files with 43 additions and 21 deletions

17
.dockerignore Normal file
View file

@ -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

View file

@ -59,10 +59,8 @@ RUN addgroup --gid $GVAGID $GVAAPP ; \
COPY --chown=$GVAAPP:$GVAAPP --from=builder /srv/$GVAAPP/.venv /srv/$GVAAPP/.venv 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/entrypoint.sh"]
ENTRYPOINT ["dumb-init", "/srv/${GVAAPP}.sh"]

5
entrypoint.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
set -e
su -c /srv/gvamysql.sh gvamysql

View file

@ -5,7 +5,8 @@ set -e
QUEUE=mysql QUEUE=mysql
TASKS=${QUEUE}tasks TASKS=${QUEUE}tasks
APP=gvamysql APP=gvamysql
export TZ="Europe/Berlin"
. "/srv/${APP}/.venv/bin/activate" . "/srv/${APP}/.venv/bin/activate"
cd /srv/${APP}/${APP} cd /srv/${APP}/${APP}
celery -A "${TASKS}" worker -Q "${QUEUE}" -l info celery -A "${TASKS}" worker -Q "${QUEUE}" -E -l info

View file

@ -25,16 +25,16 @@ def get_env_setting(setting):
########## CELERY CONFIGURATION ########## CELERY CONFIGURATION
CELERY_BROKER_URL = get_env_setting("GVAMYSQL_BROKER_URL") accept_content = ["json"]
CELERY_RESULT_BACKEND = get_env_setting("GVAMYSQL_RESULTS_REDIS_URL") broker_url = get_env_setting("GVAMYSQL_BROKER_URL")
CELERY_RESULT_PERSISTENT = True enable_utc = True
CELERY_TASK_RESULT_EXPIRES = None result_backend = get_env_setting("GVAMYSQL_RESULTS_REDIS_URL")
CELERY_ROUTES = ("gvacommon.celeryrouters.GvaRouter",) result_expires = None
CELERY_TIMEZONE = "Europe/Berlin" result_persistent = True
CELERY_ENABLE_UTC = True result_serializer = "json"
CELERY_ACCEPT_CONTENT = ["json"] task_routes = ("gvacommon.celeryrouters.GvaRouter",)
CELERY_TASK_SERIALIZER = "json" task_serializer = "json"
CELERY_RESULT_SERIALIZER = "json" timezone = "Europe/Berlin"
########## END CELERY CONFIGURATION ########## END CELERY CONFIGURATION
########## GVAMYSQL CONFIGURATION ########## GVAMYSQL CONFIGURATION

10
poetry.lock generated
View file

@ -427,14 +427,14 @@ files = [
[[package]] [[package]]
name = "importlib-metadata" name = "importlib-metadata"
version = "6.0.0" version = "4.13.0"
description = "Read metadata from Python packages" description = "Read metadata from Python packages"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"
files = [ files = [
{file = "importlib_metadata-6.0.0-py3-none-any.whl", hash = "sha256:7efb448ec9a5e313a57655d35aa54cd3e01b7e1fbcf72dce1bf06119420f5bad"}, {file = "importlib_metadata-4.13.0-py3-none-any.whl", hash = "sha256:8a8a81bcf996e74fee46f0d16bd3eaa382a7eb20fd82445c3ad11f4090334116"},
{file = "importlib_metadata-6.0.0.tar.gz", hash = "sha256:e354bedeb60efa6affdcc8ae121b73544a7aa74156d047311948f6d711cd378d"}, {file = "importlib_metadata-4.13.0.tar.gz", hash = "sha256:dd0173e8f150d6815e098fd354f6414b0f079af4644ddfe90c71e2fc6174346d"},
] ]
[package.dependencies] [package.dependencies]
@ -442,7 +442,7 @@ typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""}
zipp = ">=0.5" zipp = ">=0.5"
[package.extras] [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"] 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)"] 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)"]
@ -927,4 +927,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools"
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.7" python-versions = "^3.7"
content-hash = "045227be36fac544ef57c28c7881b53918835bd12148cb2006ffb3cac767a4bf" content-hash = "c82d4588426b7e24a0e874a46399a1d4992f561f05d87440f23d2175522d02f3"

View file

@ -11,6 +11,7 @@ python = "^3.7"
celery = "^5.2.7" celery = "^5.2.7"
mysqlclient = "^2.1.1" mysqlclient = "^2.1.1"
redis = "^4.5.1" redis = "^4.5.1"
importlib-metadata = "<5"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]