Skip to content
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

changes to create demo on python-anywhere.com #16

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ jobs:
#docker buildx build --output type=docker -t $IMAGE_TAG -t $IMAGE_NAME:latest .
#why we issue build twice ?-> bug-> https://github.com/docker/buildx/issues/59, one is build and one is to load to local registry
# todo: linux/arm64 takes a long time

#clean up disk space - we get error
#could not get the image local://***/radio-duck:0.1.3-0.9.0-0.3 from cache: failed to copy image: Error response from daemon: write /var/lib/docker/tmp/docker-export-920748090/7864e000623cab3c4f606105cf570d4966620fbaba80bb98d3ecd8a922245bcc/layer.tar: no space left on device
rm -rf /opt/hostedtoolcache
- name: Docker Scout
id: docker-scout
if: ${{ github.event_name == 'pull_request' }}
Expand Down
26 changes: 13 additions & 13 deletions poetry.lock

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

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "radio-duck"
version = "0.1.2"
version = "0.1.3"
description = "duckDb server"
authors = ["vishnu rao"]
license = "mit license"
Expand All @@ -9,7 +9,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
duckdb = "0.9.0"
fastapi = "0.101.0"
fastapi = "0.110.0"
uvicorn = "0.23.2"
httpx = "^0.25.0"
pytz = "^2023.3.post1"
Expand Down
10 changes: 10 additions & 0 deletions python-anywhere.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import server

# entrypoint for pythonanywhere.com demo app
server.load_config(["default.ini"])
server.congfigure_logging()
server.setup_duck()
server.configure_router()

# uvicorn python-anywhere:demo --app-dir '.'
demo = server.app
33 changes: 24 additions & 9 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async def shutdown_hook(app: FastAPI):

app = FastAPI(lifespan=shutdown_hook)

if __name__ == "__main__":
arguments = sys.argv[0:]

def load_config(arguments: list[str]):
config_file = "/fubar.ini"
if len(arguments) > 1:
config_file = arguments[1]
Expand All @@ -34,20 +34,19 @@ async def shutdown_hook(app: FastAPI):
print("loading user provided config from", config_file)
config.setup_app_config(config_file)

host = config.get_config()["serve"]["host"]
port_str = config.get_config()["serve"]["port"]

def congfigure_logging():
log_level = config.get_config()["logging"]["level"]
# set default loglevel
logging.basicConfig(level=logging._nameToLevel[log_level.upper()])

# setup db
duck.setup_duck()

# configure secrets
def setup_duck():
duck.setup_duck()
config.configure_sekrets(duck.connection)
# start server
import uvicorn


def configure_router():
app.include_router(
api.router,
prefix="/v1",
Expand All @@ -56,4 +55,20 @@ async def shutdown_hook(app: FastAPI):
Depends(duck.get_db_connection),
],
)


if __name__ == "__main__":
arguments = sys.argv[0:]
load_config(arguments)
congfigure_logging()
configure_router()
setup_duck()

# start server
import uvicorn

host = config.get_config()["serve"]["host"]
port_str = config.get_config()["serve"]["port"]

log_level = config.get_config()["logging"]["level"]
uvicorn.run(app, host=host, port=int(port_str), log_level=log_level)