From 6ee97603509517939ccc539d047e4b97fcabe235 Mon Sep 17 00:00:00 2001 From: Tom Searle Date: Fri, 20 Sep 2024 12:20:01 +0100 Subject: [PATCH 1/2] CU-8695tx30b: fix DEBUG setting in env files --- envs/env | 6 +++--- envs/env-prod | 2 +- webapp/api/core/settings.py | 10 +++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/envs/env b/envs/env index 3d58bcb5..30743e74 100644 --- a/envs/env +++ b/envs/env @@ -11,7 +11,7 @@ ENV=non-prod CSRF_TRUSTED_ORIGINS= ### Django debug setting - to live-reload etc. ### -DEBUG=True +DEBUG=1 ### Load example CDB, Vocab ### LOAD_EXAMPLES=1 @@ -32,7 +32,7 @@ DB_PATH=${DB_DIR}/db.sqlite3 DB_BACKUP_DIR=/home/api/db-backup # Resubmit all on startup -RESUBMIT_ALL_ON_STARTUP=1 +RESUBMIT_ALL_ON_STARTUP=0 # Front end env vars LOAD_NUM_DOC_PAGES=10 @@ -41,4 +41,4 @@ LOAD_NUM_DOC_PAGES=10 EMAIL_USER=example@cogstack.org EMAIL_PASS="to be changed" EMAIL_HOST=mail.cogstack.org -EMAIL_PORT=465 \ No newline at end of file +EMAIL_PORT=465 diff --git a/envs/env-prod b/envs/env-prod index 0728c195..140c94b1 100644 --- a/envs/env-prod +++ b/envs/env-prod @@ -12,7 +12,7 @@ ENV=prod CSRF_TRUSTED_ORIGINS= # Django Debug mode should be False for prod -DEBUG=False +DEBUG=0 ### Load example CDB, Vocab ### LOAD_EXAMPLES=0 diff --git a/webapp/api/core/settings.py b/webapp/api/core/settings.py index 403d6661..0170c729 100644 --- a/webapp/api/core/settings.py +++ b/webapp/api/core/settings.py @@ -38,9 +38,13 @@ SECRET_KEY = 'q$&esydgbn2=#-k5s5i(+^dtxs1@$50_(ln0wuw@zig4m&^m7=' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = os.environ.get('DEBUG', True) -if realm == 'prod' and DEBUG: - log.warning('Running in prod realm with DEBUG=True, are you sure you want to do that?') +try: + DEBUG = bool(int(os.environ.get('DEBUG', 1))) + if realm == 'prod' and DEBUG: + log.warning('Running in prod realm with DEBUG=True, are you sure you want to do that?') +except ValueError as e: + log.error('Error parsing DEBUG env, setting DEBUG to True. DEBUG env var should be set to 0 (false) or 1 (true).') + DEBUG = True ALLOWED_HOSTS = ['*'] From 0f3a437c57b399581f72ef62cad46c3a14a27b6f Mon Sep 17 00:00:00 2001 From: Tom Searle Date: Fri, 20 Sep 2024 12:39:07 +0100 Subject: [PATCH 2/2] CU-8695tx1r8: pass env files in correctly. Setting MCTRAINER_PORT requires `export MCTRAINER_PORT; docker compose up` --- docker-compose-dev.yml | 4 ++++ docker-compose-prod.yml | 6 +++++- docker-compose.yml | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index cad8d993..d03a7f7d 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -31,6 +31,8 @@ services: - api-static:/home/api/static - ./nginx/nginx.conf:/etc/nginx/nginx.conf - ./nginx/sites-enabled/:/etc/nginx/sites-enabled + env_file: + - ./envs/env ports: - ${MCTRAINER_PORT:-8001}:8000 depends_on: @@ -41,6 +43,8 @@ services: container_name: mct_solr image: solr:8 restart: always + env_file: + - ./envs/env ports: - ${SOLR_PORT:-8983}:8983 volumes: diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index 07ecb552..11c612b3 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -31,7 +31,7 @@ services: - api-db:/home/api/db - api-db-backup:/home/api/db-backup env_file: - - ./envs/env + - ./envs/env-prod entrypoint: /home/scripts/entry.sh command: cron -f -l 2 @@ -44,6 +44,8 @@ services: - api-static:/home/api/static - ./nginx/nginx.conf:/etc/nginx/nginx.conf - ./nginx/sites-enabled/:/etc/nginx/sites-enabled + env_file: + - ./envs/env-prod ports: - "${MCTRAINER_PORT:-8001}:8000" depends_on: @@ -54,6 +56,8 @@ services: container_name: mct_solr image: solr:8 restart: always + env_file: + - ./envs/env-prod expose: - "8983" volumes: diff --git a/docker-compose.yml b/docker-compose.yml index a61c559d..f2100e1c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,6 +40,8 @@ services: - api-static:/home/api/static - ./nginx/nginx.conf:/etc/nginx/nginx.conf - ./nginx/sites-enabled/:/etc/nginx/sites-enabled + env_file: + - ./envs/env ports: - ${MCTRAINER_PORT:-8001}:8000 depends_on: @@ -50,6 +52,8 @@ services: container_name: mct_solr image: solr:8 restart: always + env_file: + - ./envs/env ports: - ${SOLR_PORT:-8983}:8983 volumes: