Skip to content

Commit

Permalink
Update env var setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
fergmac committed Dec 20, 2024
1 parent ec8874c commit 5e9b5a6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
8 changes: 4 additions & 4 deletions backend/.envrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ layout python3

# Set all required environment variables.
export DJANGO_LOG_LEVEL=DEBUG
export DATABASE_SERVICE_NAME=localhost
# export DATABASE_SERVICE_NAME=localhost
export LOCALHOST_SERVICE_HOST=localhost
export BASEURL=http://127.0.0.1:8000/
export LOCALHOST_SERVICE_PORT=5432
export DATABASE_NAME=gwells
export DATABASE_USER=gwells
export DATABASE_PASSWORD=gwells
# export DATABASE_NAME=gwells
# export DATABASE_USER=gwells
# export DATABASE_PASSWORD=gwells
export DATABASE_SCHEMA=public
export DJANGO_SECRET_KEY=blah
export DJANGO_DEBUG=True
Expand Down
26 changes: 21 additions & 5 deletions backend/gwells/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,35 @@
limitations under the License.
"""
import os
import logging

from django.conf import settings
from gwells.settings.base import get_env_variable

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def config():
service_name = get_env_variable('DATABASE_SERVICE_NAME', '').upper().replace('-', '_')
name = get_env_variable('DATABASE_NAME')

# logger.info(f'Django Database Config')
# logger.info(f'service_name: ', service_name[0])
# logger.info(f'database_name: ', name[0])

# return {
# 'ENGINE': 'django.contrib.gis.db.backends.postgis',
# 'NAME': name,
# 'USER': get_env_variable('DATABASE_USER'),
# 'PASSWORD': get_env_variable('DATABASE_PASSWORD'),
# 'HOST': get_env_variable('{}_SERVICE_HOST'.format(service_name)),
# 'PORT': get_env_variable('{}_SERVICE_PORT'.format(service_name)),
# }
return {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': name,
'USER': get_env_variable('DATABASE_USER'),
'PASSWORD': get_env_variable('DATABASE_PASSWORD'),
'HOST': get_env_variable('{}_SERVICE_HOST'.format(service_name)),
'PORT': get_env_variable('{}_SERVICE_PORT'.format(service_name)),
'NAME': os.getenv('DATABASE_NAME'),
'USER': os.getenv('DATABASE_USER'),
'PASSWORD': os.getenv('DATABASE_PASSWORD'),
'HOST': os.getenv('DATABASE_SERVICE_NAME'),
'PORT': os.getenv('DATABASE_PORT')
}
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,16 @@ services:
DATABASE_NAME: gwells
DATABASE_USER: "${DATABASE_USER:-gwells}"
DATABASE_PASSWORD: "${DATABASE_PASSWORD:-test1}"
DATABASE_SERVICE_NAME: gwells
# DATABASE_SERVICE_NAME: gwells
DJANGO_ADMIN_URL: admin
DJANGO_DEBUG: "true"
DJANGO_SECRET_KEY: secret
ENABLE_ADDITIONAL_DOCUMENTS: "true"
ENABLE_AQUIFERS_SEARCH: "true"
# GWELLS_SERVICE_HOST: "${GWELLS_SERVICE_HOST:-db}"
# GWELLS_SERVICE_PORT: "${GWELLS_SERVICE_PORT:-5432}"
DATABASE_SERVICE_NAME: db
DATABASE_PORT: 5432
MINIO_ACCESS_KEY: minio
MINIO_SECRET_KEY: minio1234
PYTHONUNBUFFERED: "1"
Expand Down

0 comments on commit 5e9b5a6

Please sign in to comment.