From 5297bc1d74cf6081d4972d2c871b60f6121ce28b Mon Sep 17 00:00:00 2001 From: Dennis Siemensma Date: Tue, 11 Jun 2024 23:48:47 +0200 Subject: [PATCH] Rework local dev/test #1196 --- .gitignore | 1 + provisioning/container/Containerfile-dev | 10 +++------- provisioning/container/compose.dev.yml | 22 ++++++---------------- provisioning/container/compose.test.yml | 20 ++++++++++++++------ provisioning/container/dev.env | 6 +++--- provisioning/container/test.env | 20 -------------------- 6 files changed, 27 insertions(+), 52 deletions(-) delete mode 100644 provisioning/container/test.env diff --git a/.gitignore b/.gitignore index e87f5b33..6e2a58a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.pydevproject/ /.project/ /.idea/* +!/.idea/runConfigurations/* *.pyc **/__pycache__ **/.pytest_cache diff --git a/provisioning/container/Containerfile-dev b/provisioning/container/Containerfile-dev index 277682ab..97741b77 100644 --- a/provisioning/container/Containerfile-dev +++ b/provisioning/container/Containerfile-dev @@ -9,6 +9,7 @@ ARG DOCS_PYTHON_VERSION="3.12" FROM python:${APP_PYTHON_VERSION}-alpine AS local-dsmrreader-base WORKDIR /app +ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 RUN apk add --update \ build-base \ @@ -19,21 +20,16 @@ RUN apk add --update \ openjpeg \ mariadb-dev \ postgresql-client +ENV POETRY_VIRTUALENVS_IN_PROJECT=true RUN pip install poetry - +COPY ./src/ /app/ FROM local-dsmrreader-base AS local-dsmrreader-dev -ENV POETRY_VIRTUALENVS_IN_PROJECT=true -COPY ./src/ /app/ RUN poetry install --with dev --no-root EXPOSE 8000 ENTRYPOINT ["poetry", "run"] -FROM local-dsmrreader-dev AS local-dsmrreader-test -EXPOSE "" - - # ----------------------------------------------------------- diff --git a/provisioning/container/compose.dev.yml b/provisioning/container/compose.dev.yml index bfb0e30c..aaf49368 100644 --- a/provisioning/container/compose.dev.yml +++ b/provisioning/container/compose.dev.yml @@ -14,12 +14,10 @@ services: target: local-dsmrreader-dev volumes: - ./src:/app - - /app/.venv # Prevents mirroring it either direction + - /app/.venv # Prevents mirroring it to host ports: - '8000:8000' depends_on: - dev-dsmr-db: - condition: service_healthy mosquitto: condition: service_started influxdb: @@ -33,17 +31,12 @@ services: restart: 'unless-stopped' ports: - '5432:5432' - healthcheck: - test: ["CMD-SHELL", "pg_isready -U dsmrreader"] - interval: 1s - timeout: 5s - retries: 20 env_file: - provisioning/container/dev.env volumes: # Persist database storage between container recreation - ./.container-data/dev-dsmr-db/:/var/lib/postgresql/ - # Only use for restoring DB-backups. E.g.: psql -U dsmrreader -f /run/host/Desktop/dsmrreader-postgresql-backup-Tuesday.sql dsmrreader + # Only use for restoring DB-backups. E.g.: psql -U dbuser -f /run/host/Desktop/dsmrreader-postgresql-backup-Tuesday.sql dsmrreader - ~/Desktop:/run/host/Desktop/ # http://localhost:10000 @@ -96,10 +89,7 @@ services: container_name: tests-dsmr-db image: postgres:15-alpine restart: 'unless-stopped' - healthcheck: - test: ["CMD-SHELL", "pg_isready -U dsmrreader"] - interval: 1s - timeout: 5s - retries: 20 - env_file: - - provisioning/container/test.env + environment: + POSTGRES_DB: 'test_dsmrreader' + POSTGRES_USER: 'testuser' + POSTGRES_PASSWORD: 'testpasswd' diff --git a/provisioning/container/compose.test.yml b/provisioning/container/compose.test.yml index 41a55898..b7053cb7 100644 --- a/provisioning/container/compose.test.yml +++ b/provisioning/container/compose.test.yml @@ -5,19 +5,25 @@ services: tests-dsmr-app: container_name: tests-dsmr-app - restart: 'no' build: context: . dockerfile: provisioning/container/Containerfile-dev - target: local-dsmrreader-test + target: local-dsmrreader-dev volumes: - ./src:/app depends_on: tests-dsmr-db: condition: service_healthy - env_file: - - provisioning/container/test.env + environment: + DJANGO_SETTINGS_MODULE: 'dsmrreader.config.test' + DJANGO_SECRET_KEY: 'automated-tests' + DJANGO_DATABASE_ENGINE: 'django.db.backends.postgresql' + DJANGO_DATABASE_HOST: 'tests-dsmr-db' + DJANGO_DATABASE_PORT: 5432 + DJANGO_DATABASE_NAME: 'test_dsmrreader' + DJANGO_DATABASE_USER: 'dbtestuser' + DJANGO_DATABASE_PASSWORD: 'dbtestpasswd' tests-dsmr-db: container_name: tests-dsmr-db @@ -28,5 +34,7 @@ services: interval: 1s timeout: 5s retries: 20 - env_file: - - provisioning/container/test.env + environment: + POSTGRES_DB: 'test_dsmrreader' + POSTGRES_USER: 'dbtestuser' + POSTGRES_PASSWORD: 'dbtestpasswd' diff --git a/provisioning/container/dev.env b/provisioning/container/dev.env index 3718c55c..5a71ce8f 100644 --- a/provisioning/container/dev.env +++ b/provisioning/container/dev.env @@ -3,15 +3,15 @@ ####################################################################### ### dev-dsmr-app ### +DSMRREADER_LOGLEVEL=DEBUG DJANGO_SETTINGS_MODULE=dsmrreader.config.development DJANGO_DATABASE_ENGINE=django.db.backends.postgresql DJANGO_DATABASE_HOST=dev-dsmr-db DJANGO_DATABASE_PORT=5432 DJANGO_DATABASE_NAME=dsmrreader -DJANGO_DATABASE_USER=dsmrreader -DJANGO_DATABASE_PASSWORD=postgres-password +DJANGO_DATABASE_USER=dbuser +DJANGO_DATABASE_PASSWORD=dbpassword DJANGO_SECRET_KEY=localhost-development -DSMRREADER_LOGLEVEL=DEBUG ### dev-dsmr-db ### diff --git a/provisioning/container/test.env b/provisioning/container/test.env deleted file mode 100644 index 86bf6654..00000000 --- a/provisioning/container/test.env +++ /dev/null @@ -1,20 +0,0 @@ -############################################################################# -# Env file for DSMR-reader AUTOMATED TESTING only, NEVER use in production! # -############################################################################# - -### tests-dsmr-app ### -DJANGO_SETTINGS_MODULE=dsmrreader.config.test -DJANGO_DATABASE_ENGINE=django.db.backends.postgresql -DJANGO_DATABASE_HOST=tests-dsmr-db -DJANGO_DATABASE_PORT=5432 -DJANGO_DATABASE_NAME=test_dsmrreader -DJANGO_DATABASE_USER=testuser -DJANGO_DATABASE_PASSWORD=testpasswd -DJANGO_SECRET_KEY=automated-tests -DSMRREADER_LOGLEVEL=ERROR - - -### tests-dsmr-db ### -POSTGRES_DB=${DJANGO_DATABASE_NAME} -POSTGRES_USER=${DJANGO_DATABASE_USER} -POSTGRES_PASSWORD=${DJANGO_DATABASE_PASSWORD}