Skip to content

Commit

Permalink
Enable custom env files.
Browse files Browse the repository at this point in the history
  • Loading branch information
antarcticrainforest committed Aug 12, 2024
1 parent f4ad88b commit 11d99ea
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 22 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -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
29 changes: 14 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion django_evaluation/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/config
Submodule config updated 1 files
+58 −0 dev-utils.py
2 changes: 1 addition & 1 deletion history/templatetags/dialogtags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import json
import logging

from django import template
from django.contrib.auth import get_user_model
Expand Down

0 comments on commit 11d99ea

Please sign in to comment.