Skip to content

Commit

Permalink
Update environment variable names
Browse files Browse the repository at this point in the history
- Changed the variable names to match Platta configuration
- Define all default values in the same place in settings.py
- Define testpaths and remove unnecessary test commands
  • Loading branch information
laurigates authored Oct 11, 2023
1 parent 9827ed5 commit 41f7135
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 29 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/test-deviceregistry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ jobs:
ruff check --output-format=github .
- name: Test with pytest
env:
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DJANGO_DB_HOST: localhost
DJANGO_DB_PORT: 5432
MEDIA_ROOT: /tmp
PYTEST_ADDOPTS: "--color=yes"
run: |
python manage.py test devices/tests
pytest devices/tests/test_api_device.py
pytest devices/tests/test_api_devicetype.py
pytest
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Override these in the docker-compose.yml file or elsewhere
ENV DATABASE_NAME=postgres
ENV DATABASE_USER=postgres
ENV DATABASE_PASSWORD=postgres
ENV DATABASE_HOST=db
ENV DATABASE_PORT=5432

# PostgreSQL config
ENV DJANGO_DB_NAME=postgres
ENV DJANGO_DB_USER=postgres
ENV DJANGO_DB_PASSWORD=postgres
ENV DJANGO_DB_HOST=db
ENV DJANGO_DB_PORT=5432

# Device registry config
ENV MEDIA_HOME=/media
ENV DJANGO_SETTINGS_MODULE=deviceregistry.settings

Expand Down
8 changes: 4 additions & 4 deletions deploy/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ data:
KAFKA_RAW_DATA_TOPIC_NAME: "{{ .Values.kafka.kafkaRawDataTopicName }}"
DEVICE_REGISTRY_URL: "{{ .Values.parser.deviceRegistryUrl }}"
DEVICE_REGISTRY_TOKEN: "{{ .Values.parser.deviceRegistryToken }}"
DATABASE_HOST: "{{ .Release.Name }}-{{ .Values.deviceregistry.databaseHost }}"
DATABASE_USER: "{{ .Values.deviceregistry.databaseUser }}"
DATABASE_PASSWORD: "{{ .Values.deviceregistry.databasePassword }}"
DATABASE_PORT: "{{ .Values.deviceregistry.databasePort }}"
DJANGO_DB_HOST: "{{ .Release.Name }}-{{ .Values.deviceregistry.databaseHost }}"
DJANGO_DB_USER: "{{ .Values.deviceregistry.databaseUser }}"
DJANGO_DB_PASSWORD: "{{ .Values.deviceregistry.databasePassword }}"
DJANGO_DB_PORT: "{{ .Values.deviceregistry.databasePort }}"
ALLOWED_HOSTS: "{{ .Values.deviceregistry.allowedHosts | toStrings }}"
SECRET_KEY: "{{ .Values.deviceregistry.secretKey }}"
40 changes: 30 additions & 10 deletions deviceregistry/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@

env = environ.Env(
# set casting, default value
DEBUG=(bool, False)
DEBUG=(bool, False),
SECRET_KEY=(str, "django-insecure-vz&7byj9esv1ncrv(7805g7w%h+-(-k_q82q(woh%1pcxr)^jf"),
# Platta uses mSECRET_KEY as the name for the variable.
mSECRET_KEY=(str, ""),
ALLOWED_HOSTS=(list, ["devreg", "localhost", "127.0.0.1", "[::1]"]),
DJANGO_DB_NAME=(str, "postgres"),
DJANGO_DB_USER=(str, "postgres"),
DJANGO_DB_PASSWORD=(str, "postgres"),
DJANGO_DB_HOST=(str, "db"),
DJANGO_DB_PORT=(str, 5432)
)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand All @@ -26,12 +35,13 @@
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env("SECRET_KEY", default="django-insecure-vz&7byj9esv1ncrv(7805g7w%h+-(-k_q82q(woh%1pcxr)^jf")
# Use mSECRET_KEY if it is defined.
SECRET_KEY = env("mSECRET_KEY") or env("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env("DEBUG")

ALLOWED_HOSTS = env("ALLOWED_HOSTS", default=["devreg", "localhost", "127.0.0.1", "[::1]"])
ALLOWED_HOSTS = env("ALLOWED_HOSTS")

# Application definition

Expand Down Expand Up @@ -83,16 +93,26 @@
# Database https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
"default": {
# "ENGINE": "django.db.backends.postgresql",
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": env("DATABASE_NAME", default="postgres"),
"USER": env("DATABASE_USER", default="postgres"),
"PASSWORD": env("DATABASE_PASSWORD", default="postgres"),
"HOST": env("DATABASE_HOST", default="db"),
"PORT": env("DATABASE_PORT", default=5432),
"NAME": env("DJANGO_DB_NAME"),
"USER": env("DJANGO_DB_USER"),
"PASSWORD": env("DJANGO_DB_PASSWORD"),
"HOST": env("DJANGO_DB_HOST"),
"PORT": env("DJANGO_DB_PORT"),
}
}

# if env("DATABASE_LOCAL", default=False):
# # Temp database for development
# DATABASES = {
# "default": {
# "ENGINE": "django.contrib.gis.db.backends.postgis",
# "NAME": "deviceregistry",
# # "USER": env("DJANGO_DB_USER", default="postgres"),
# # "PASSWORD": env("DJANGO_DB_PASSWORD", default="postgres"),
# # "HOST": env("DJANGO_DB_HOST", default="db"),
# # "PORT": env("DJANGO_DB_PORT", default=5432),
# }
# }

# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ services:
ALLOWED_HOSTS:
SECRET_KEY:
# PostgreSQL config
DATABASE_HOST:
DATABASE_USER:
DATABASE_PASSWORD:
DATABASE_PORT:
DJANGO_DB_HOST:
DJANGO_DB_USER:
DJANGO_DB_PASSWORD:
DJANGO_DB_PORT:
# Debug config
DEBUG: 1
depends_on:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ exclude = ["migrations", "venv"]
DJANGO_SETTINGS_MODULE = "deviceregistry.settings"
log_cli = 1
log_cli_level = 20
testpaths = ["devices/tests"]
addopts = ["--color=yes"]

0 comments on commit 41f7135

Please sign in to comment.