Skip to content

Commit

Permalink
FWF-3424 [feature] fetching db values from env
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhaib-aot committed Sep 26, 2024
1 parent 5724c20 commit 92cd59a
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 24 deletions.
5 changes: 5 additions & 0 deletions deployment/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ services:
INSIGHT_API_KEY: ${INSIGHT_API_KEY}
INSIGHT_API_URL: ${INSIGHT_API_URL}
DATABASE_URL: ${FORMSFLOW_API_DB_URL:-postgresql://postgres:changeme@forms-flow-webapi-db:5432/webapi}
DATABASE_USERNAME: ${FORMSFLOW_API_DB_USER}
DATABASE_PASSWORD: ${FORMSFLOW_API_DB_PASSWORD}
DATABASE_HOST: ${FORMSFLOW_API_DB_HOST}
DATABASE_PORT: ${FORMSFLOW_API_DB_PORT}
DATABASE_NAME: ${FORMSFLOW_API_DB_NAME}
BPM_TOKEN_API: ${KEYCLOAK_URL}${KEYCLOAK_URL_HTTP_RELATIVE_PATH:-/auth}/realms/${KEYCLOAK_URL_REALM:-forms-flow-ai}/protocol/openid-connect/token
BPM_CLIENT_ID: ${KEYCLOAK_BPM_CLIENT_ID:-forms-flow-bpm}
BPM_CLIENT_SECRET: ${KEYCLOAK_BPM_CLIENT_SECRET:-e4bdbd25-1467-4f7f-b993-bc4b1944c943}
Expand Down
10 changes: 10 additions & 0 deletions deployment/docker/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,17 @@ INSIGHT_API_KEY={API Key from Redash}

#----Environment variables for adaptive tier (Python Webapi) Datastore----#
##JDBC DB Connection URL for formsflow.ai

## DATABASE URL configuration
#FORMSFLOW_API_DB_URL=postgresql://postgres:changeme@forms-flow-webapi-db:5432/webapi
# You can pass the full database URL or split it into the following variables:
FORMSFLOW_API_DB_USER=""
FORMSFLOW_API_DB_PASSWORD=""
FORMSFLOW_API_DB_HOST=""
FORMSFLOW_API_DB_PORT=""
FORMSFLOW_API_DB_NAME=""


##formsflow.ai database postgres user
#FORMSFLOW_API_DB_USER=postgres
##formsflow.ai database postgres password
Expand Down
14 changes: 8 additions & 6 deletions deployment/openshift/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ INSIGHT_API_KEY={API Key from Redash}

#----Environment variables for adaptive tier (Python Webapi) Datastore----#
##JDBC DB Connection URL for formsflow.ai

## DATABASE URL configuration
#FORMSFLOW_API_DB_URL=postgresql://postgres:changeme@forms-flow-webapi-db:5432/webapi
##formsflow.ai database postgres user
#FORMSFLOW_API_DB_USER=postgres
##formsflow.ai database postgres password
#FORMSFLOW_API_DB_PASSWORD=changeme
##formsflow.ai database name
#FORMSFLOW_API_DB_NAME=webapi
# You can pass the full database URL or split it into the following variables:
FORMSFLOW_API_DB_USER=postgres
FORMSFLOW_API_DB_PASSWORD=changeme
FORMSFLOW_API_DB_HOST=localhost
FORMSFLOW_API_DB_PORT=5432
FORMSFLOW_API_DB_NAME=webapi

#----Integration variable settings----#
##Define project level configuration, possible values development,test,production
Expand Down
5 changes: 5 additions & 0 deletions forms-flow-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ services:
INSIGHT_API_KEY: ${INSIGHT_API_KEY}
INSIGHT_API_URL: ${INSIGHT_API_URL}
DATABASE_URL: ${FORMSFLOW_API_DB_URL:-postgresql://postgres:changeme@forms-flow-webapi-db:5432/webapi}
DATABASE_USERNAME: ${FORMSFLOW_API_DB_USER:-postgres}
DATABASE_PASSWORD: ${FORMSFLOW_API_DB_PASSWORD:-changeme}
DATABASE_HOST: ${FORMSFLOW_API_DB_HOS:-forms-flow-webapi-dbT}
DATABASE_PORT: ${FORMSFLOW_API_DB_PORT:-5432}
DATABASE_NAME: ${FORMSFLOW_API_DB_NAME:-webapi}
BPM_TOKEN_API: ${KEYCLOAK_URL}${KEYCLOAK_URL_HTTP_RELATIVE_PATH:-/auth}/realms/${KEYCLOAK_URL_REALM:-forms-flow-ai}/protocol/openid-connect/token
BPM_CLIENT_ID: ${KEYCLOAK_BPM_CLIENT_ID:-forms-flow-bpm}
BPM_CLIENT_SECRET: ${KEYCLOAK_BPM_CLIENT_SECRET:-e4bdbd25-1467-4f7f-b993-bc4b1944c943}
Expand Down
9 changes: 8 additions & 1 deletion forms-flow-api/src/formsflow_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ class _Config: # pylint: disable=too-few-public-methods
ALEMBIC_INI = "migrations/alembic.ini"

# POSTGRESQL
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URL", "")
# PostgreSQL configuration
DB_USER = os.getenv("DATABASE_USERNAME", "postgres")
DB_PASSWORD = os.getenv("DATABASE_PASSWORD", "changeme")
DB_HOST = os.getenv("DATABASE_HOST", "localhost")
DB_PORT = os.getenv("DATABASE_PORT", "6432")
DB_NAME = os.getenv("DATABASE_NAME", "webapi")
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URL",
f"postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}")

TESTING = False
DEBUG = False
Expand Down
9 changes: 6 additions & 3 deletions forms-flow-data-analysis-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ services:
volumes:
- ./:/app:rw
environment:
POSTGRES_USER: ${DATA_ANALYSIS_DB_USER:-general}
POSTGRES_PASSWORD: ${DATA_ANALYSIS_DB_PASSWORD:-changeme}
POSTGRES_DB: ${DATA_ANALYSIS_DB_NAME:-dataanalysis}
DATABASE_URL: ${DATA_ANALYSIS_DB_URL}
DATABASE_USERNAME: ${DATA_ANALYSIS_DB_USER}
DATABASE_PASSWORD: ${DATA_ANALYSIS_DB_PASSWORD}
DATABASE_HOST: ${DATA_ANALYSIS_DB_HOST}
DATABASE_PORT: ${DATA_ANALYSIS_DB_PORT}
DATABASE_NAME: ${DATA_ANALYSIS_DB_NAME}
JWT_OIDC_WELL_KNOWN_CONFIG: ${KEYCLOAK_URL}${KEYCLOAK_URL_HTTP_RELATIVE_PATH:-/auth}/realms/${KEYCLOAK_URL_REALM:-forms-flow-ai}/.well-known/openid-configuration
JWT_OIDC_ALGORITHMS: 'RS256'
JWT_OIDC_JWKS_URI: ${KEYCLOAK_URL}${KEYCLOAK_URL_HTTP_RELATIVE_PATH:-/auth}/realms/${KEYCLOAK_URL_REALM:-forms-flow-ai}/protocol/openid-connect/certs
Expand Down
11 changes: 8 additions & 3 deletions forms-flow-data-analysis-api/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ KEYCLOAK_URL=http://{your-ip-address}:8080
KEYCLOAK_URL_REALM=forms-flow-ai
KEYCLOAK_WEB_CLIENT_ID=forms-flow-web

DATA_ANALYSIS_DB_USER=general
DATA_ANALYSIS_DB_PASSWORD=changeme
DATA_ANALYSIS_DB_NAME=dataanalysis
#DATABASE URL configuration
DATA_ANALYSIS_DB_URL=postgresql://general:changeme@forms-flow-data-analysis-db:5432/dataanalysis
# You can pass the full database URL or split it into the following variables:
DATA_ANALYSIS_DB_USER=""
DATA_ANALYSIS_DB_PASSWORD=""
DATA_ANALYSIS_DB_HOST=""
DATA_ANALYSIS_DB_PORT=""
DATA_ANALYSIS_DB_NAME=""

MODEL_ID=Seethal/sentiment_analysis_generic_dataset
DATABASE_SUPPORT=DISABLED

Expand Down
21 changes: 10 additions & 11 deletions forms-flow-data-analysis-api/src/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,17 @@ class _Config: # pylint: disable=too-few-public-methods

DATABASE_SUPPORT = os.getenv("DATABASE_SUPPORT", default=Service.DISABLED.value)

DB_PG_CONFIG = {
"host": os.getenv("POSTGRES_DB_HOST", "forms-flow-data-analysis-db"),
"port": os.getenv("POSTGRES_DB_PORT", "5432"),
"dbname": os.getenv("POSTGRES_DB"),
"user": os.getenv("POSTGRES_USER"),
"password": os.getenv("POSTGRES_PASSWORD"),
}
SQLALCHEMY_DATABASE_URI = (
f"postgresql://"
f"{DB_PG_CONFIG['user']}:{DB_PG_CONFIG['password']}"
f"@{DB_PG_CONFIG['host']}:{int(DB_PG_CONFIG['port'])}/{DB_PG_CONFIG['dbname']}"

# PostgreSQL configuration
DB_USER = os.getenv("DATABASE_USERNAME", "general")
DB_PASSWORD = os.getenv("DATABASE_PASSWORD", "changeme")
DB_HOST = os.getenv("DATABASE_HOST", "localhost")
DB_PORT = os.getenv("DATABASE_PORT", "5432")
DB_NAME = os.getenv("DATABASE_NAME", "dataanalysis")
SQLALCHEMY_DATABASE_URI = os.getenv(
"DATABASE_URL", f"postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
)

MODEL_ID = os.getenv("MODEL_ID")

# Configure LOG
Expand Down
5 changes: 5 additions & 0 deletions forms-flow-documents/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ services:
- ./:/app:rw
environment:
DATABASE_URL: ${FORMSFLOW_API_DB_URL:-postgresql://postgres:changeme@forms-flow-webapi-db:5432/webapi}
DATABASE_USERNAME: ${FORMSFLOW_API_DB_USER}
DATABASE_PASSWORD: ${FORMSFLOW_API_DB_PASSWORD}
DATABASE_HOST: ${FORMSFLOW_API_DB_HOST}
DATABASE_PORT: ${FORMSFLOW_API_DB_PORT}
DATABASE_NAME: ${FORMSFLOW_API_DB_NAME}
FORMSFLOW_API_CORS_ORIGINS: ${FORMSFLOW_API_CORS_ORIGINS:-*}
JWT_OIDC_WELL_KNOWN_CONFIG: ${KEYCLOAK_URL}${KEYCLOAK_URL_HTTP_RELATIVE_PATH:-/auth}/realms/${KEYCLOAK_URL_REALM:-forms-flow-ai}/.well-known/openid-configuration
JWT_OIDC_JWKS_URI: ${KEYCLOAK_URL}${KEYCLOAK_URL_HTTP_RELATIVE_PATH:-/auth}/realms/${KEYCLOAK_URL_REALM:-forms-flow-ai}/protocol/openid-connect/certs
Expand Down

0 comments on commit 92cd59a

Please sign in to comment.