From 518d05a5c6482706431c3e67cd11b26f4fc5eb75 Mon Sep 17 00:00:00 2001 From: "Damon L. Montague Jr." Date: Tue, 16 Jan 2024 00:52:34 -0500 Subject: [PATCH] Changing up docker file for now --- .../workflows/docker-publish-api-services.yml | 2 +- api/Dockerfile | 19 +++++++-------- api/api/main.py | 13 +++++----- api/poetry.lock | 24 +------------------ api/pyproject.toml | 3 +-- api/services/history/saver.py | 4 ++-- 6 files changed, 20 insertions(+), 45 deletions(-) diff --git a/.github/workflows/docker-publish-api-services.yml b/.github/workflows/docker-publish-api-services.yml index b51d2ab..184a386 100644 --- a/.github/workflows/docker-publish-api-services.yml +++ b/.github/workflows/docker-publish-api-services.yml @@ -13,7 +13,7 @@ env: IMAGE_NAME: api-microservices jobs: - build-api: + build-api-services: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/api/Dockerfile b/api/Dockerfile index 2b6e456..c027dbd 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,13 +1,10 @@ -# Dockerfile-api -FROM python:3.11.0-slim +FROM python:3.11.0-slim as python-base -WORKDIR /app - -COPY . . -COPY poetry.lock pyproject.toml /app/ - -RUN pip install poetry +WORKDIR /api +COPY /pyproject.toml /api +RUN pip3 install poetry==1.7.1 RUN poetry config virtualenvs.create false -RUN poetry install --no-dev --only api - -CMD ["python", "/app/api/main.py"] \ No newline at end of file +RUN touch README.md +RUN poetry install --only main,api +COPY . . +ENTRYPOINT ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8080"] \ No newline at end of file diff --git a/api/api/main.py b/api/api/main.py index fa34e98..b9863bf 100644 --- a/api/api/main.py +++ b/api/api/main.py @@ -1,11 +1,9 @@ import json +import os import time import uuid from contextlib import asynccontextmanager -import httpx -import tomli -import uvicorn from fastapi import FastAPI, Depends from fastapi.exceptions import RequestValidationError from fastapi.middleware.cors import CORSMiddleware @@ -17,7 +15,11 @@ from api.business.database import DatabaseFactory from api.routes import games, model, ping -with open("../pyproject.toml", "rb") as f: +import httpx +import tomli +import uvicorn + +with open("pyproject.toml", "rb") as f: _META = tomli.load(f) BASE_PATH = "/api/v1" @@ -69,7 +71,6 @@ async def lifespan(_: FastAPI): logger.info(f"Connecting to {db_settings.DATABASE_TYPE}") db = DatabaseFactory.compute_or_get( name=db_settings.DATABASE_TYPE, - db_settings=db_settings, ) await db.connect() yield @@ -180,4 +181,4 @@ async def log(request: Request, call_next): app.include_router(router, prefix=BASE_PATH, dependencies=[Depends(log_body)]) if __name__ == "__main__": - uvicorn.run("main:app", host="0.0.0.0", port=8000, access_log=False, reload=True) + uvicorn.run("main:app", host="0.0.0.0", port=8000, access_log=False, reload=os.getenv("DEBUG", 'True') == 'True') diff --git a/api/poetry.lock b/api/poetry.lock index 30a1474..bf70cd4 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -1430,28 +1430,6 @@ files = [ {file = "protobuf-4.23.4.tar.gz", hash = "sha256:ccd9430c0719dce806b93f89c91de7977304729e55377f872a92465d548329a9"}, ] -[[package]] -name = "psycopg2" -version = "2.9.9" -description = "psycopg2 - Python-PostgreSQL Database Adapter" -optional = false -python-versions = ">=3.7" -files = [ - {file = "psycopg2-2.9.9-cp310-cp310-win32.whl", hash = "sha256:38a8dcc6856f569068b47de286b472b7c473ac7977243593a288ebce0dc89516"}, - {file = "psycopg2-2.9.9-cp310-cp310-win_amd64.whl", hash = "sha256:426f9f29bde126913a20a96ff8ce7d73fd8a216cfb323b1f04da402d452853c3"}, - {file = "psycopg2-2.9.9-cp311-cp311-win32.whl", hash = "sha256:ade01303ccf7ae12c356a5e10911c9e1c51136003a9a1d92f7aa9d010fb98372"}, - {file = "psycopg2-2.9.9-cp311-cp311-win_amd64.whl", hash = "sha256:121081ea2e76729acfb0673ff33755e8703d45e926e416cb59bae3a86c6a4981"}, - {file = "psycopg2-2.9.9-cp312-cp312-win32.whl", hash = "sha256:d735786acc7dd25815e89cc4ad529a43af779db2e25aa7c626de864127e5a024"}, - {file = "psycopg2-2.9.9-cp312-cp312-win_amd64.whl", hash = "sha256:a7653d00b732afb6fc597e29c50ad28087dcb4fbfb28e86092277a559ae4e693"}, - {file = "psycopg2-2.9.9-cp37-cp37m-win32.whl", hash = "sha256:5e0d98cade4f0e0304d7d6f25bbfbc5bd186e07b38eac65379309c4ca3193efa"}, - {file = "psycopg2-2.9.9-cp37-cp37m-win_amd64.whl", hash = "sha256:7e2dacf8b009a1c1e843b5213a87f7c544b2b042476ed7755be813eaf4e8347a"}, - {file = "psycopg2-2.9.9-cp38-cp38-win32.whl", hash = "sha256:ff432630e510709564c01dafdbe996cb552e0b9f3f065eb89bdce5bd31fabf4c"}, - {file = "psycopg2-2.9.9-cp38-cp38-win_amd64.whl", hash = "sha256:bac58c024c9922c23550af2a581998624d6e02350f4ae9c5f0bc642c633a2d5e"}, - {file = "psycopg2-2.9.9-cp39-cp39-win32.whl", hash = "sha256:c92811b2d4c9b6ea0285942b2e7cac98a59e166d59c588fe5cfe1eda58e72d59"}, - {file = "psycopg2-2.9.9-cp39-cp39-win_amd64.whl", hash = "sha256:de80739447af31525feddeb8effd640782cf5998e1a4e9192ebdf829717e3913"}, - {file = "psycopg2-2.9.9.tar.gz", hash = "sha256:d1454bde93fb1e224166811694d600e746430c006fbb031ea06ecc2ea41bf156"}, -] - [[package]] name = "pyasn1" version = "0.5.1" @@ -2619,4 +2597,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "3.11.0" -content-hash = "fa636f30f20e0bf4363b96b7fd703eadd40baee7f204486c5a8b4284357a25a3" +content-hash = "847eb907351d7304d9097cdd22d9c9062c70013d5231d328ca7b57c504437913" diff --git a/api/pyproject.toml b/api/pyproject.toml index 85ff06d..123a21b 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -17,13 +17,12 @@ alembic = "^1.13.1" asyncpg = "^0.29.0" - - [tool.poetry.group.api.dependencies] fastapi = { version = "^0.108.0", extras = ["all"] } tensorflow = "2.15.0" uvicorn = "^0.25.0" pandas = "^2.1.4" +tomli = "^2.0.1" [tool.poetry.dev-dependencies] diff --git a/api/services/history/saver.py b/api/services/history/saver.py index eb1037b..5203d0a 100644 --- a/api/services/history/saver.py +++ b/api/services/history/saver.py @@ -83,7 +83,7 @@ def is_saved(self, games: list[DailyGameResponse]) -> list[DailyGameResponse]: saved_games = [game for game in saved_games if game not in games] return saved_games -class RedisBasedGameSaver(GameSaver): +class PostgresBasedGameSaver(GameSaver): def save(self, game: list[SavedGame]) -> int: """ Saves a game to a datastore @@ -105,6 +105,6 @@ def is_saved(self, games: list[DailyGame]) -> list[DailyGame]: class GameSaverFactory(AbstractFactory): _values: dict[str, FactoryItem] = { - "redis": FactoryItem(name="redis", factory_item=RedisBasedGameSaver), + "postgres": FactoryItem(name="redis", factory_item=PostgresBasedGameSaver), "disk": FactoryItem(name="disk", factory_item=DiskBasedGameSaver), }