Skip to content

Commit ec0db81

Browse files
authored
Issue 12 - Adjustments for non-local deployments (#17)
* add whitenoise middleware to serve static files * move more local/env-dependent settings from settings.py to settings.ini or env-vars * add an example for settings.ini Closes #12
2 parents c5c2e80 + ae44c0a commit ec0db81

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

.github/workflows/actions.yml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ jobs:
3838
- name: Test with pytest
3939
run: |
4040
python -m pytest -sv tests
41+
- name: Ruff linting
42+
run: |
43+
ruff check .
44+
- name: Ruff formatting
45+
run: |
46+
ruff format . --check --verbose
4147
build-and-install:
4248
runs-on: ubuntu-latest
4349
steps:
@@ -55,18 +61,4 @@ jobs:
5561
python -m build --sdist
5662
- name: Install the package
5763
run: |
58-
uv pip install dist/*.tar.gz
59-
ruff-linting:
60-
runs-on: ubuntu-latest
61-
steps:
62-
- uses: actions/checkout@v4
63-
- uses: chartboost/ruff-action@v1
64-
with:
65-
args: "check ."
66-
ruff-formatting:
67-
runs-on: ubuntu-latest
68-
steps:
69-
- uses: actions/checkout@v4
70-
- uses: chartboost/ruff-action@v1
71-
with:
72-
args: "format . --check --verbose"
64+
uv pip install dist/*.tar.gz
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[settings]
2+
DEBUG=False
3+
SECRET_KEY=django-insecure-wiq2-hvjf4#jgoq-&#rg!)hw*(wa9l9^&cgcohq8k6ihitx9f#
4+
SECRET_ENCRYPTION_KEY=x1_JDNmuikh7MQFzIQJFvmJDFbeOsacJRvvvwq3xv6a=
5+
ALLOWED_HOSTS = 127.0.0.1, localhost
6+
CSRF_TRUSTED_ORIGINS = https://mdc.domain.local
7+

masterdata_checker/checker/settings.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@
3030
OPENBIS_URL = "https://main.datastore.bam.de/"
3131

3232
# SECURITY WARNING: don't run with debug turned on in production!
33-
DEBUG = False
33+
DEBUG = environ("DEBUG", default=False, cast=bool)
3434

35-
ALLOWED_HOSTS = ["localhost", "127.0.0.1", "141.63.249.193", "141.63.249.2"]
35+
ALLOWED_HOSTS = environ(
36+
"ALLOWED_HOSTS",
37+
default=["127.0.0.1", "localhost"],
38+
cast=lambda v: [s.strip() for s in v.split(",")],
39+
)
3640

3741
CACHES = {
3842
"default": {
@@ -55,6 +59,7 @@
5559

5660
MIDDLEWARE = [
5761
"django.middleware.security.SecurityMiddleware",
62+
"whitenoise.middleware.WhiteNoiseMiddleware",
5863
"django.contrib.sessions.middleware.SessionMiddleware",
5964
"django.middleware.common.CommonMiddleware",
6065
"django.middleware.csrf.CsrfViewMiddleware",
@@ -63,9 +68,11 @@
6368
"django.middleware.clickjacking.XFrameOptionsMiddleware",
6469
]
6570

66-
CSRF_TRUSTED_ORIGINS = ["http://141.63.249.193:8000"]
71+
CSRF_TRUSTED_ORIGINS = environ(
72+
"CSRF_TRUSTED_ORIGINS", default=[], cast=lambda v: [s.strip() for s in v.split(",")]
73+
)
6774

68-
ROOT_URLCONF = "checker.urls"
75+
ROOT_URLCONF = "masterdata_checker.checker.urls"
6976

7077
TEMPLATES = [
7178
{
@@ -83,7 +90,7 @@
8390
},
8491
]
8592

86-
WSGI_APPLICATION = "checker.wsgi.application"
93+
WSGI_APPLICATION = "masterdata_checker.checker.wsgi.application"
8794

8895

8996
# Database
@@ -148,6 +155,8 @@
148155

149156
STATIC_URL = "/static/"
150157
STATICFILES_DIRS = [BASE_DIR / "app/static"]
158+
STATIC_ROOT = BASE_DIR / "staticfiles"
159+
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
151160

152161
# Default primary key field type
153162
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field

masterdata_checker/manage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
def main():
99
"""Run administrative tasks."""
10-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "checker.settings")
10+
os.environ.setdefault(
11+
"DJANGO_SETTINGS_MODULE", "masterdata_checker.checker.settings"
12+
)
1113
try:
1214
from django.core.management import execute_from_command_line
1315
except ImportError as exc:

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ license = { file = "LICENSE" }
3030
dependencies = [
3131
"bam-masterdata>=0.4.2",
3232
"django",
33+
"whitenoise",
3334
"pybis~=1.37.1rc4",
3435
"cryptography>=45.0.2",
3536
"python-decouple",
@@ -42,7 +43,7 @@ dependencies = [
4243
[project.optional-dependencies]
4344
dev = [
4445
"mypy==1.0.1",
45-
"ruff",
46+
"ruff==0.11.4",
4647
"pytest",
4748
"pytest-timeout",
4849
"pytest-cov",

0 commit comments

Comments
 (0)