diff --git a/Dockerfile b/Dockerfile index 864bc9f..d501bc1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,8 @@ ENV PYTHONFAULTHANDLER=1 ENV PYTHONUNBUFFERED=1 +ENV MODE="DEVELOPMENT" + RUN mkdir -p /app COPY requirements.txt /app diff --git a/Dockerfile.prod b/Dockerfile.prod index 3b0bcf9..f6b1fe6 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -4,6 +4,8 @@ ENV PYTHONFAULTHANDLER=1 ENV PYTHONUNBUFFERED=1 +ENV MODE="PRODUCTION" + RUN mkdir -p /app COPY requirements.txt /app diff --git a/app/models/auto.py b/app/models/auto.py index 0de111f..e16be3a 100644 --- a/app/models/auto.py +++ b/app/models/auto.py @@ -1,7 +1,7 @@ from sqlalchemy import Column, Integer,\ - DECIMAL, Text,\ - VARCHAR, TIMESTAMP, Date, INTEGER -from datetime import datetime, timezone + DECIMAL, TEXT,\ + VARCHAR, TIMESTAMP, DATE, INTEGER +from datetime import datetime from database import Base diff --git a/config.py b/config.py new file mode 100644 index 0000000..7078235 --- /dev/null +++ b/config.py @@ -0,0 +1,20 @@ +import os + +def load_config(mode=os.environ.get('MODE')): + + try: + print(f"mode is {mode}") + if mode == 'PRODUCTION': + + from settings_prod import ApplicationConfig + return ApplicationConfig + elif mode == 'DEVELOPMENT': + + from settings_local import ApplicationConfig + return ApplicationConfig + else: + pass + + except ImportError: + from settings_local import ApplicationConfig + return ApplicationConfig \ No newline at end of file diff --git a/database.py b/database.py index 0242857..f01e05f 100644 --- a/database.py +++ b/database.py @@ -2,14 +2,19 @@ from sqlalchemy import create_engine from sqlalchemy.engine import URL from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import declarative_base +from config import load_config + + +ApplicationConfig = load_config() + url = URL.create( drivername="postgresql", - username="postgres", - password="password", - host="192.168.1.204", - database="eamco", - port=5432 + username=ApplicationConfig.POSTGRES_USERNAME, + password=ApplicationConfig.POSTGRES_PW, + host=ApplicationConfig.POSTGRES_SERVER, + database=ApplicationConfig.POSTGRES_DBNAME00, + port=ApplicationConfig.POSTGRES_PORT ) engine = create_engine(url) diff --git a/main.py b/main.py index e47cff2..9f7bc52 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,11 @@ from fastapi import FastAPI from app.routers import delivery from fastapi.middleware.cors import CORSMiddleware +from config import load_config + + +ApplicationConfig = load_config() + app = FastAPI() diff --git a/settings_local.py b/settings_local.py new file mode 100644 index 0000000..82417a3 --- /dev/null +++ b/settings_local.py @@ -0,0 +1,19 @@ + + +class ApplicationConfig: + """ + Basic Configuration for a generic User + """ + CURRENT_SETTINGS = 'LOCAL' + # databases info + POSTGRES_USERNAME = 'postgres' + POSTGRES_PW = 'password' + POSTGRES_SERVER = '192.168.1.204' + POSTGRES_PORT = '5432' + POSTGRES_DBNAME00 = 'eamco' + SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME, + POSTGRES_PW, + POSTGRES_SERVER, + POSTGRES_DBNAME00 + ) + diff --git a/settings_prod.py b/settings_prod.py new file mode 100644 index 0000000..269c60f --- /dev/null +++ b/settings_prod.py @@ -0,0 +1,17 @@ +class ApplicationConfig: + """ + Basic Configuration for a generic User + """ + CURRENT_SETTINGS = 'LOCAL' + # databases info + POSTGRES_USERNAME = 'postgres' + POSTGRES_PW = 'password' + POSTGRES_SERVER = '192.168.1.204' + POSTGRES_PORT = '5432' + POSTGRES_DBNAME00 = 'auburnoil' + SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME, + POSTGRES_PW, + POSTGRES_SERVER, + POSTGRES_DBNAME00 + ) + SQLALCHEMY_BINDS = {'eamco': SQLALCHEMY_DATABASE_URI}