diff --git a/Dockerfile b/Dockerfile index 3f51154..16592c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,6 @@ RUN pip3 install . COPY . /app RUN pip3 install . +EXPOSE 5000 + ENTRYPOINT ["learn-sql-model", "api", "run"] diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..618d4c9 --- /dev/null +++ b/fly.toml @@ -0,0 +1,40 @@ +# fly.toml app configuration file generated for learn-sql-model on 2023-06-13T20:34:33-05:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = "learn-sql-model" +primary_region = "ord" +console_command = "learn-sql-model api run" + +[experimental] + auto_rollback = true + +[build] + dockerfile = "Dockerfile" + +[env] + PORT = "5000" + +[[services]] + protocol = "tcp" + internal_port = 5000 + processes = ["app"] + + [[services.ports]] + port = 80 + handlers = ["http"] + + [[services.ports]] + port = 443 + handlers = ["tls", "http"] + [services.concurrency] + type = "connections" + hard_limit = 25 + soft_limit = 20 + + [[services.tcp_checks]] + interval = "15s" + timeout = "2s" + grace_period = "1s" + restart_limit = 0 diff --git a/learn_sql_model/cli/app.py b/learn_sql_model/cli/app.py index a5e1c21..197b9e0 100644 --- a/learn_sql_model/cli/app.py +++ b/learn_sql_model/cli/app.py @@ -6,6 +6,7 @@ from learn_sql_model.cli.api import api_app from learn_sql_model.cli.config import config_app from learn_sql_model.cli.hero import hero_app from learn_sql_model.cli.model import model_app +from learn_sql_model.game.game import game_app app = typer.Typer( name="learn_sql_model", @@ -16,6 +17,7 @@ app.add_typer(config_app, name="config") app.add_typer(model_app, name="model") app.add_typer(api_app, name="api") app.add_typer(hero_app, name="hero") +app.add_typer(game_app, name="game") def version_callback(value: bool) -> None: diff --git a/learn_sql_model/config.py b/learn_sql_model/config.py index c764122..e82b73c 100644 --- a/learn_sql_model/config.py +++ b/learn_sql_model/config.py @@ -2,7 +2,7 @@ from contextvars import ContextVar from typing import TYPE_CHECKING from fastapi import Depends -from pydantic import BaseModel, BaseSettings +from pydantic import BaseModel, BaseSettings, validator from sqlalchemy import create_engine from sqlmodel import SQLModel, Session @@ -61,6 +61,12 @@ class Config(BaseSettings): env_nested_delimiter = "__" env_file = ".env", ".env.dev", ".env.qa", ".env.prod" + @validator("database_url") + def validate_database_url(cls, v: str) -> str: + if v.startswith("postgres://"): + return v.replace("postgres://", "postgresql+psycopg2://") + return v + @property def database(self) -> Database: return get_database(config=self) diff --git a/learn_sql_model/game/game.py b/learn_sql_model/game/game.py index fcf58fe..16b0f2c 100644 --- a/learn_sql_model/game/game.py +++ b/learn_sql_model/game/game.py @@ -1,15 +1,7 @@ -# using pygame make a game using Hero -# it should be gamepad and mouse compatible -# it should have a server that keeps track of the game logic -# it should have a renderer that renders the game -# it should have a client that sends commands to the server -# - - import atexit +from faker import Faker import pygame -import typer from typer import Typer from websocket import create_connection @@ -49,7 +41,7 @@ class Client: def ws(self): def connect(): self._ws = create_connection( - f"ws://{config.api_client.host}:{config.api_client.port}/wsecho" + f"ws://{config.api_client.url.replace('https://', '')}/wsecho" ) if not hasattr(self, "_ws"): @@ -176,17 +168,17 @@ class Client: pass -app = Typer() +game_app = Typer() -@app.command() -def run( - name: str = typer.Option(...), - secret_name: str = typer.Option(...), -): +@game_app.command() +def run(): + f = Faker() + name = "-".join(f.words(2)) + secret_name = "-".join(f.words(2)) client = Client(name, secret_name) client.run() if __name__ == "__main__": - app() + game_app() diff --git a/pyproject.toml b/pyproject.toml index 817fd9e..950d197 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,9 @@ dependencies = [ "psycopg2-binary", 'pygame', 'black', +'alembic', +'pygame', + "pyflyby", "anyconfig", "copier", "engorgio",