Skip to content

Commit

Permalink
django flexi settings
Browse files Browse the repository at this point in the history
  • Loading branch information
scrungus committed Jul 4, 2024
1 parent 6619597 commit 0cc4d46
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 147 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ RUN groupadd --gid $APP_GID $APP_GROUP && \
# Don't buffer stdout and stderr as it breaks realtime logging
ENV PYTHONUNBUFFERED 1

# TODO(tylerchristie): django flexi settings
# Install application configuration using flexi-settings
ENV DJANGO_SETTINGS_MODULE flexi_settings.settings
ENV DJANGO_FLEXI_SETTINGS_ROOT /etc/coral-credits/settings.py
COPY ./etc/coral-credits /etc/coral-credits
RUN mkdir -p /etc/coral-credits/settings.d

# By default, serve the app on port 8080 using the app user
EXPOSE 8080
Expand Down
2 changes: 2 additions & 0 deletions charts/files/settings/01-django.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SECRET_KEY: {{ .Values.settings.secretKey | default (randAlphaNum 64) }}
DEBUG: {{ .Values.settings.debug }}
11 changes: 10 additions & 1 deletion charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ spec:
volumeMounts:
- name: data
mountPath: /data
- name: runtime-settings
mountPath: /etc/coral-credits/settings.d
readOnly: true
containers:
- name: api
securityContext: {{ toYaml .Values.securityContext | nindent 12 }}
Expand All @@ -48,6 +51,9 @@ spec:
volumeMounts:
- name: data
mountPath: /data
- name: runtime-settings
mountPath: /etc/coral-credits/settings.d
readOnly: true
{{- with .Values.nodeSelector }}
nodeSelector: {{ toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -60,4 +66,7 @@ spec:
volumes:
- name: data
persistentVolumeClaim:
claimName: {{ include "coral-credits.fullname" . }}
claimName: {{ include "coral-credits.fullname" . }}
- name: runtime-settings
secret:
secretName: {{ include "coral-credits.fullname" . }}
11 changes: 11 additions & 0 deletions charts/templates/settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "coral-credits.fullname" . }}
labels: {{ include "coral-credits.labels" . | nindent 4 }}
type: Opaque
# Use data because of https://github.com/helm/helm/issues/10010
# Not doing so means that AWX-related keys are not removed on transition to the CRD
data:
01-django.yaml: |
{{- tpl (.Files.Get "files/settings/01-django.yaml") . | b64enc | nindent 4 }}
9 changes: 9 additions & 0 deletions charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ securityContext:
drop: [ALL]
readOnlyRootFilesystem: true

# Django settings
settings:
# The Django secret key
# If not given, a randomly generated key will be used
# However this will be different on each deployment which may cause sessions to be terminated
secretKey:
# Use debug mode (recommended false in production)
debug: false

# Resource requests and limits for the containers
resources: {}

Expand Down
145 changes: 0 additions & 145 deletions coral_credits/settings.py

This file was deleted.

64 changes: 64 additions & 0 deletions etc/coral-credits/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Application-specific settings.
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "/data/db.sqlite3",
}
}

# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_extensions",
"drf_spectacular",
"rest_framework",
"auditlog",
"coral_credits.api",
]

AUDITLOG_INCLUDE_ALL_MODELS = True

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

REST_FRAMEWORK = {
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}

ROOT_URLCONF = "coral_credits.urls"

SPECTACULAR_SETTINGS = {
"TITLE": "Coral Credits API",
"DESCRIPTION": 'Coral credits is a resource management system that helps build a \
"coral reef style" fixed capacity cloud, cooperatively sharing community \
resources through interfaces such as: Azimuth, OpenStack Blazar and Slurm.',
"VERSION": "0.1.0",
"SERVE_INCLUDE_SCHEMA": False,
# OTHER SETTINGS
}

WSGI_APPLICATION = "coral_credits.wsgi.application"
Loading

0 comments on commit 0cc4d46

Please sign in to comment.