From 38c82ee799f81fb605786dcf20f29833732d20eb Mon Sep 17 00:00:00 2001 From: ajxudir Date: Tue, 24 Mar 2026 09:59:17 +0100 Subject: [PATCH] DIT-451: Fix dev setup and update packages --- .docker/.env.template | 2 -- .docker/startup.sh | 11 +++++++++-- docker-compose.yml | 2 -- requirements.dev.txt | 2 +- requirements.txt | 15 ++++++++------- statistics_api/definitions.py | 16 +++++++++++++--- statistics_api/settings.py | 4 ++-- 7 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.docker/.env.template b/.docker/.env.template index 3f3ff55..eada661 100644 --- a/.docker/.env.template +++ b/.docker/.env.template @@ -10,8 +10,6 @@ KPAS_DOMAIN=kpas.staging.kompetanse.udir.no GUNICORN_TIMEOUT=60 GUNICORN_LOG_LEVEL=debug -MATOMO_ACCESS_KEY= - ############################################################## # Database ############################################################## diff --git a/.docker/startup.sh b/.docker/startup.sh index db766b4..04d6b5c 100755 --- a/.docker/startup.sh +++ b/.docker/startup.sh @@ -4,7 +4,10 @@ echo -e "\n\n\n[1/4] Copy and import .env variables to the current shell" echo -e "##############################################################\n" ENV_FILE=".env" if [ ! -f "$ENV_FILE" ]; then - cp .docker/.env.template .env + cp .docker/.env.template .env + echo "- .env file created from template. Please review and update the .env file as needed before restarting the container." +else + echo "- .env file already exists, skipping copy. If you want to reset it, please delete the existing .env file and restart the container." fi set -o allexport @@ -17,12 +20,16 @@ while IFS='=' read -r key value; do export "$key=$value" echo "- IMPORTED: $key" else - echo "- ERROR: $key" + echo "- SKIPPED (already set): $key" fi fi done < "$ENV_FILE" set +o allexport +if ! grep -q "source /app/.env" /root/.bashrc 2>/dev/null; then + echo '[ -f /app/.env ] && set -o allexport && source /app/.env && set +o allexport' >> /root/.bashrc +fi + echo -e "\n\n\n[2/4] Install PIP packages" echo -e "##############################################################\n" pip3 --cache-dir=/app/.cache install -r requirements.txt diff --git a/docker-compose.yml b/docker-compose.yml index 7541eb4..db33ffc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.8' services: kpas_stats_db: image: mysql:8.4 @@ -27,7 +26,6 @@ services: kpas_stats_db: condition: service_healthy environment: - ENVIRONMENT: "local" CANVAS_ACCESS_KEY: "" # Generate a new access key here: https://bibsys.test.instructure.com/profile/settings MATOMO_ACCESS_KEY: "" volumes: diff --git a/requirements.dev.txt b/requirements.dev.txt index 1dbcc36..bc0553c 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,3 +1,3 @@ -r requirements.txt uritemplate==3.0.1 -pyyaml==5.4 \ No newline at end of file +pyyaml==6.0.3 diff --git a/requirements.txt b/requirements.txt index b878ec0..6d3039e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,16 +1,17 @@ -APScheduler==3.11.0 +APScheduler==3.11.2 arrow==1.3.0 -Django==4.2.19 +Django==4.2.29 django-cors-headers==4.7.0 djangorestframework==3.15.2 gunicorn==23.0.0 mysql-connector-python==9.2.0 -mysqlclient==2.2.7 +mysqlclient==2.2.8 netifaces==0.11.0 -PyMySQL==1.1.1 +PyMySQL==1.1.2 python-decouple==3.8 python-graphql-client==0.4.3 -requests==2.32.3 -SQLAlchemy==2.0.38 +requests==2.32.5 +SQLAlchemy==2.0.48 SQLAlchemy-Utils==0.41.2 -sentry-sdk[django]==2.20.0 +sentry-sdk[django]==2.55.0 +setuptools>=78.0.0 diff --git a/statistics_api/definitions.py b/statistics_api/definitions.py index 0244440..b65a8f3 100644 --- a/statistics_api/definitions.py +++ b/statistics_api/definitions.py @@ -1,8 +1,18 @@ import os import socket -from distutils import util import netifaces as ni -from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import declarative_base + + +def strtobool(val): + val = str(val).strip().lower() + if val in ('y', 'yes', 't', 'true', 'on', '1'): + return True + elif val in ('n', 'no', 'f', 'false', 'off', '0'): + return False + else: + raise ValueError(f'Invalid truth value {val!r}') + def get_ip_address(): try: @@ -47,7 +57,7 @@ def get_ip_address(): "DATABASE_REFRESH_MINUTE") else "00" DJANGO_SECRET_KEY = os.getenv("DJANGO_SECRET_KEY") -DJANGO_DEBUG = bool(util.strtobool(os.getenv("DJANGO_DEBUG"))) if os.getenv("DJANGO_DEBUG") is not None else False +DJANGO_DEBUG = bool(strtobool(os.getenv("DJANGO_DEBUG"))) if os.getenv("DJANGO_DEBUG") is not None else False allowed_hosts = [s.strip() for s in os.getenv("DJANGO_ALLOWED_HOSTS", "").split(',')] if not allowed_hosts: diff --git a/statistics_api/settings.py b/statistics_api/settings.py index db82c99..a093417 100644 --- a/statistics_api/settings.py +++ b/statistics_api/settings.py @@ -21,11 +21,11 @@ from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.logging import LoggingIntegration -app_env=os.getenv("ENVIRONMENT") if os.getenv("ENVIRONMENT") else "local" +app_env=os.getenv("ENVIRONMENT") if os.getenv("ENVIRONMENT") else "dev" app_version=os.getenv("GIT_COMMIT") if os.getenv("GIT_COMMIT") else "1.0.0" sentry_dsn=None -if app_env != "local": +if app_env != "dev": sentry_dsn="https://b247741da7815fc43bddd20a6032a1a2@o4507468577701888.ingest.de.sentry.io/4508777538519120" def before_send_transaction(event_item, event):