From feb4663a3f78c1bab4427fefb9c403ef5b2624ac Mon Sep 17 00:00:00 2001 From: Rens Houben Date: Fri, 17 Oct 2025 11:55:45 +0200 Subject: [PATCH] Initial build --- .gitea/workflows/unit-tests.yaml | 28 ++++++++++++++++++++++++++++ docker/Dockerfile | 20 ++++++++++++++++++++ src/config/settings.py | 25 ++++++++++++------------- 3 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 .gitea/workflows/unit-tests.yaml create mode 100644 docker/Dockerfile diff --git a/.gitea/workflows/unit-tests.yaml b/.gitea/workflows/unit-tests.yaml new file mode 100644 index 0000000..758f446 --- /dev/null +++ b/.gitea/workflows/unit-tests.yaml @@ -0,0 +1,28 @@ +name: Urania unit tests +run-name: ${{ gitea.actor }} is testing Urania branch ${{ gitea.ref_name }} +on: + push: + branches: + - '*' + +jobs: + Run-unit-tests: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Install python + uses: actions/setup-python@v5 + with: + python-version: 3.13.5 + - name: Install requirements + run: | + pip install --upgrade pip + pip install -r src/requirements.txt + - name: Run unit tests + env: + DJANGO_SECRET_KEY: 'u92=rjf!))-h!1l9z%4i2xwk^t6%l+$z!$a%1_5zba4_9=ypj1' + working-directory: src + run: + python3 manage.py test + diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..1621e45 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.12 + + +COPY src/requirements.txt requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +WORKDIR /pda-new + +# Copy control files and pull in dependencies +COPY src/ ./ + +ENV DJANGO_APP_PORT=8000 +ENV DJANGO_SECRET_KEY='=m=3)ea$s@*u25(8_9197vyh$8d+8_qqd7@*n6t6#^zih(t1rj' +ENV DJANGO_ALLOWED_HOSTS='localhost','127.0.0.1' + +EXPOSE ${DJANGO_APP_PORT} + +ENTRYPOINT ["python","manage.py"] +CMD ["runserver",${DJANGO_APP_PORT}] + diff --git a/src/config/settings.py b/src/config/settings.py index 4ac02c1..72bb7bd 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -1,28 +1,27 @@ """ -Django settings for config project. +Django settings for PDA-New Generated by 'django-admin startproject' using Django 5.2.5. -For more information on this file, see -https://docs.djangoproject.com/en/5.2/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/5.2/ref/settings/ """ import os from pathlib import Path -from dotenv import load_dotenv +from environ import Env BASE_DIR = Path(__file__).resolve().parent.parent +ENV_FILE = os.path.join(BASE_DIR,'.env') -load_dotenv(BASE_DIR / ".env") +env = Env() +env.read_env(ENV_FILE) +SECRET_KEY = env("DJANGO_SECRET_KEY", default='') +print('Starting without a secret key is not recommended in production') if not SECRET_KEY else None -SECRET_KEY = os.environ["DJANGO_SECRET_KEY"] -DEBUG = int(os.environ.get("DJANGO_DEBUG", default=0)) -ALLOWED_HOSTS = os.environ.get( - "DJANGO_ALLOWED_HOSTS", default="localhost 127.0.0.1 0.0.0.0" -).split() +DEBUG = env.bool("DJANGO_DEBUG", default=False) +print('Debug mode ENABLED. Disable this before going into production') if DEBUG else None + +ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", + default="localhost,127.0.0.1,0.0.0.0") INSTALLED_APPS = [ "django.contrib.admin",