Skip to content

Commit

Permalink
🕸 Debug (#45)
Browse files Browse the repository at this point in the history
* Adds debug option, fixes production config bug

* Copies static + templates, sets prod env var
  • Loading branch information
mrharpo authored May 19, 2023
1 parent db8e05b commit dce0e02
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUN pip install -U pip
COPY pyproject.toml pdm.lock README.md ./
COPY chowda chowda


###########################
# 'dev' build stage
###########################
Expand Down Expand Up @@ -54,4 +55,9 @@ CMD poetry run locust
############################
FROM base as production
RUN pip install .[production]

COPY static static
COPY templates templates
ENV ENVIRONMENT=production

CMD gunicorn chowda.app:app -b 0.0.0.0:8000 -w 2 --worker-class uvicorn.workers.UvicornWorker
2 changes: 2 additions & 0 deletions chowda/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from os import environ

ENVIRONMENT = environ.get('ENVIRONMENT', 'development')
DEBUG = bool(environ.get('DEBUG', ENVIRONMENT == 'development'))

DB_URL = environ.get('DB_URL', 'sqlite:///chowda.development.sqlite')

TEMPLATES_DIR = environ.get('TEMPLATES_DIR', 'templates')
Expand Down
11 changes: 5 additions & 6 deletions chowda/db.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from sqlalchemy import create_engine
from sqlmodel import SQLModel
from sqlmodel.pool import StaticPool

from chowda import models # noqa F401
from chowda.config import ENVIRONMENT, DB_URL
from chowda.config import DB_URL, DEBUG, ENVIRONMENT


def get_engine(env=ENVIRONMENT):
Expand All @@ -11,19 +12,17 @@ def get_engine(env=ENVIRONMENT):
return create_engine(
'sqlite:///:memory:',
connect_args={'check_same_thread': False},
echo=True,
echo=DEBUG,
poolclass=StaticPool,
)
if env == 'development':
return create_engine(
DB_URL,
connect_args={'check_same_thread': False},
echo=True,
echo=DEBUG,
)
if env == 'production':
return create_engine(
DB_URL, connect_args={'check_same_thread': True}, echo=False
)
return create_engine(DB_URL, echo=DEBUG)
raise Exception(f'Unknown environment: {env}')


Expand Down

0 comments on commit dce0e02

Please sign in to comment.