Skip to content

TEST - Build and image with new Flask and SQLAlchemy #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions devops/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ WORKDIR /src
COPY . /src
RUN npm ci && npm run build

FROM tiangolo/meinheld-gunicorn:python3.7
FROM tiangolo/meinheld-gunicorn:python3.8
LABEL org.opencontainers.image.source=https://github.com/cmu-delphi/delphi-epidata
# use delphi's timezome
RUN ln -s -f /usr/share/zoneinfo/America/New_York /etc/localtime

COPY requirements.txt /app
RUN pip install --no-cache-dir -r requirements.txt
COPY requirements.txt /app/requirements_also.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt -r requirements_also.txt
# the file /tmp/requirements.txt is created in the parent docker definition. (see:
# https://github.com/tiangolo/meinheld-gunicorn-docker/blob/master/docker-images/python3.8.dockerfile#L5 )
# this combined requirements installation ensures all version constrants are accounted for.

# disable python stdout buffering
ENV PYTHONUNBUFFERED 1
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
itsdangerous<2.1
jinja2==3.0.3
werkzeug<2.1
Flask==1.1.2
SQLAlchemy==1.3.22
werkzeug==2.2.2
Flask==2.2.2
SQLAlchemy==1.4.40
mysqlclient==2.0.2
python-dotenv==0.15.0
orjson==3.4.7
Expand Down
11 changes: 10 additions & 1 deletion src/server/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
MAX_COMPATIBILITY_RESULTS = int(3650)

SQLALCHEMY_DATABASE_URI = os.environ.get("SQLALCHEMY_DATABASE_URI", "sqlite:///test.db")
SQLALCHEMY_ENGINE_OPTIONS = json.loads(os.environ.get("SQLALCHEMY_ENGINE_OPTIONS", "{}"))

# defaults
SQLALCHEMY_ENGINE_OPTIONS = {
"pool_pre_ping": True, # enable ping test for validity of recycled pool connections on connect() calls
"pool_recycle": 5 # seconds after which a recycled pool connection is considered invalid
}
# update with overrides of defaults or additions from external configs
SQLALCHEMY_ENGINE_OPTIONS.update(
json.loads(os.environ.get("SQLALCHEMY_ENGINE_OPTIONS", "{}")))

SECRET = os.environ.get("FLASK_SECRET", "secret")
URL_PREFIX = os.environ.get("FLASK_PREFIX", "/")

Expand Down
10 changes: 5 additions & 5 deletions src/server/_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

from sqlalchemy import text
from sqlalchemy.engine import RowProxy
from sqlalchemy.engine import Row

from ._common import db, app
from ._db import metadata
Expand Down Expand Up @@ -197,7 +197,7 @@ def filter_pair(pair: TimePair, i) -> str:


def parse_row(
row: RowProxy,
row: Row,
fields_string: Optional[Sequence[str]] = None,
fields_int: Optional[Sequence[str]] = None,
fields_float: Optional[Sequence[str]] = None,
Expand Down Expand Up @@ -245,7 +245,7 @@ def run_query(p: APrinter, query_tuple: Tuple[str, Dict[str, Any]]):
return db.execution_options(stream_results=True).execute(full_query, **params)


def _identity_transform(row: Dict[str, Any], _: RowProxy) -> Dict[str, Any]:
def _identity_transform(row: Dict[str, Any], _: Row) -> Dict[str, Any]:
"""
identity transform
"""
Expand All @@ -257,7 +257,7 @@ def execute_queries(
fields_string: Sequence[str],
fields_int: Sequence[str],
fields_float: Sequence[str],
transform: Callable[[Dict[str, Any], RowProxy], Dict[str, Any]] = _identity_transform,
transform: Callable[[Dict[str, Any], Row], Dict[str, Any]] = _identity_transform,
):
"""
execute the given queries and return the response to send them
Expand Down Expand Up @@ -317,7 +317,7 @@ def execute_query(
fields_string: Sequence[str],
fields_int: Sequence[str],
fields_float: Sequence[str],
transform: Callable[[Dict[str, Any], RowProxy], Dict[str, Any]] = _identity_transform,
transform: Callable[[Dict[str, Any], Row], Dict[str, Any]] = _identity_transform,
):
"""
execute the given query and return the response to send it
Expand Down