Skip to content

Commit

Permalink
Changing up docker file for now
Browse files Browse the repository at this point in the history
  • Loading branch information
day-mon committed Jan 16, 2024
1 parent 0f41138 commit 518d05a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish-api-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
IMAGE_NAME: api-microservices

jobs:
build-api:
build-api-services:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
19 changes: 8 additions & 11 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
RUN touch README.md
RUN poetry install --only main,api
COPY . .
ENTRYPOINT ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8080"]
13 changes: 7 additions & 6 deletions api/api/main.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
24 changes: 1 addition & 23 deletions api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions api/services/history/saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
}

0 comments on commit 518d05a

Please sign in to comment.