From 11d99ea16cdffdf0a3105b708a80f3531119a1e5 Mon Sep 17 00:00:00 2001 From: antarcticrainforest Date: Mon, 12 Aug 2024 16:37:07 +0200 Subject: [PATCH] Enable custom env files. --- .env | 6 ++++++ Makefile | 29 ++++++++++++++--------------- README.md | 20 ++++++++++++++++++++ django_evaluation/utils.py | 2 +- docker-compose.yaml | 8 ++++---- docker/config | 2 +- history/templatetags/dialogtags.py | 2 +- 7 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 00000000..dc8ec32e --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +REDIS_USER=redis +REDIS_PASSWD=secret +REDIS_SSL_CERTFILE=./docker/config/certs/client-cert.pem +REDIS_SSL_KEYFILE=./docker/config/certs/client-key.pem +REDIS_CONTAINER_CERTFILE=/certs/client-cert.pem +REDIS_CONTAINER_KEYFILE=/certs/client-key.pem diff --git a/Makefile b/Makefile index 5d912319..9fae4468 100644 --- a/Makefile +++ b/Makefile @@ -4,14 +4,14 @@ export EVALUATION_SYSTEM_CONFIG_FILE := $(PWD)/docker/local-eval-system.conf export EVALUATION_SYSTEM_DRS_CONFIG_FILE := $(PWD)/docker/drs_config.toml export DJANGO_SUPERUSER_PASSWORD := secret export DEV_MODE := 1 -export REDIS_USER := redis -export REDIS_PASSWD := secret -export REDIS_SSL_CERTFILE := $(PWD)/docker/config/certs/client-cert.pem -export REDIS_SSL_KEYFILE := $(PWD)/docker/config/certs/client-key.pem - +export ENV_FILE ?= .env +export RE +include $(ENV_FILE) +export .PHONY: all run runserver runfrontend stopserver stopfrontend stop setup + all: setup runserver runfrontend @echo "All services are running in the background." @@ -41,17 +41,16 @@ runserver: runrest: @echo "Starting up freva-rest api" - @CERT_CONTENT=$$(awk 'BEGIN {ORS="\\n"} {print}' $(REDIS_SSL_CERTFILE)) && \ - KEY_CONTENT=$$(awk 'BEGIN {ORS="\\n"} {print}' $(REDIS_SSL_KEYFILE)) && \ - JSON_STRING=$$(printf '{"user": "redis", \ - "passwd": "secret", \ - "host": "redis://localhost:6379", \ - "ssl_cert": "%s", \ - "ssl_key": "%s"}' "$$CERT_CONTENT" "$$KEY_CONTENT") && \ - echo $$JSON_STRING|base64 > .data-portal-cluster-config.json + @echo $(ENV_FILE) + @echo $(REDIS_SSL_CERTFILE) + python docker/config/dev-utils.py redis-config .data-portal-cluster-config.json \ + --user $(REDIS_USER) \ + --passwd $(REDIS_PASSWD) \ + --cert-file $(REDIS_SSL_CERTFILE) \ + --key-file $(REDIS_SSL_KEYFILE) $$(which python) -m data_portal_worker -c .data-portal-cluster-config.json > rest.log 2>&1 & python docker/config/dev-utils.py oidc http://localhost:8080/realms/freva/.well-known/openid-configuration - $$(which python) -m freva_rest.cli -p 7777 --cert-dir ./docker/config/certs --debug --dev >> rest.log 2>&1 & + $$(which python) -m freva_rest.cli -p 7777 --tls-key $(REDIS_SSL_KEYFILE) --tls-cert $(REDIS_SSL_CERTFILE) --debug --dev >> rest.log 2>&1 & @echo "To watch the freva-rest logs, run 'tail -f rest.log'" runfrontend: @@ -64,7 +63,7 @@ stopserver: ps aux | grep '[f]reva_rest.cli' | awk '{print $$2}' | xargs -r kill ps aux | grep '[d]ata_portal_worker' | awk '{print $$2}' | xargs -r kill ps aux | grep '[m]anage.py runserver' | awk '{print $$2}' | xargs -r kill - rm -r .data-portal-cluster-config.json + rm -fr .data-portal-cluster-config.json echo "Stopped Django development server..." > runserver.log echo "Stopped freva-rest development server..." > rest.log diff --git a/README.md b/README.md index 4e6627fa..b3192754 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,20 @@ pomand-compose up -d ```console podman-compose down ``` + +By default the compose command will evaluate environment variables defined in +the `.evn` file. If you want to override these variables, for example to disable +using self signed certificates you can create another environment file and +pass the `--env-file` variable. The following setup would disable certificates: + +```console +cat .env.dev +REDIS_USER=redis +REDIS_PASSWD=secret + +docker compose --env-file .env.dev up -d +``` + ### Running tests There are some rudimentary tests that check the integration of `django` and the @@ -107,6 +121,12 @@ can use: make stop ``` + +> ``📝`` If you have created a custom environment file when starting the docker +> containers you can export the path the env custom environment file by +> using the `ENV_FILE` environment variable: `ENV_FILE=.env.dev make run` + + The django and npm development servers will write output into `runserver.log` and `npm.log`. You can observe the output of the processes using `tail -f` or something similar. diff --git a/django_evaluation/utils.py b/django_evaluation/utils.py index 301875af..99bc29bd 100644 --- a/django_evaluation/utils.py +++ b/django_evaluation/utils.py @@ -1,9 +1,9 @@ """Collection of utility functions.""" from __future__ import annotations -import logging import json +import logging import threading import time from typing import Any, Callable diff --git a/docker-compose.yaml b/docker-compose.yaml index 033500f7..b8317cde 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -33,11 +33,11 @@ services: ports: - "6379:6379" environment: - REDIS_USERNAME: redis - REDIS_PASSWORD: secret + REDIS_USERNAME: ${REDIS_USER} + REDIS_PASSWORD: ${REDIS_PASSWD} REDIS_LOGLEVEL: debug - REDIS_SSL_CERTFILE: /certs/client-cert.pem - REDIS_SSL_KEYFILE: /certs/client-key.pem + REDIS_SSL_CERTFILE: ${REDIS_CONTAINER_CERTFILE} + REDIS_SSL_KEYFILE: ${REDIS_CONTAINER_KEYFILE} hostname: redis volumes: - ./docker/config/redis/redis-cmd.sh:/usr/local/bin/redis-cmd diff --git a/docker/config b/docker/config index 8243df60..71c890bd 160000 --- a/docker/config +++ b/docker/config @@ -1 +1 @@ -Subproject commit 8243df60afc1e9d7978753bc7e1532f0794077bc +Subproject commit 71c890bd833835d58a5f5ca8539b4d473f00075e diff --git a/history/templatetags/dialogtags.py b/history/templatetags/dialogtags.py index 02b1735b..f49f7cd0 100644 --- a/history/templatetags/dialogtags.py +++ b/history/templatetags/dialogtags.py @@ -1,5 +1,5 @@ -import logging import json +import logging from django import template from django.contrib.auth import get_user_model