From 2a090ea7a21c6611ad3182e7582495200ae33bcf Mon Sep 17 00:00:00 2001 From: Untone Date: Sun, 4 Feb 2024 07:29:26 +0300 Subject: [PATCH] granian-precommit --- .gitea/workflows/main.yml | 10 +++++++--- Dockerfile | 2 +- pyproject.toml | 5 +++-- server.py | 16 +++++++++++++--- settings.py | 2 +- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index c88393d..bc40958 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -1,4 +1,4 @@ -name: 'deploy' +name: "Deploy to notifier" on: [push] jobs: @@ -14,9 +14,13 @@ jobs: id: repo_name run: echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY##*/})" + - name: Get Branch Name + id: branch_name + run: echo "::set-output name=branch::$(echo ${GITHUB_REF##*/})" + - name: Push to dokku uses: dokku/github-action@master with: - branch: 'main' - git_remote_url: 'ssh://dokku@staging.discours.io:22/${{ steps.repo_name.outputs.repo }}' + branch: "main" + git_remote_url: "ssh://dokku@v2.discours.io:22/notifier" ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9ce2d47..63ecda5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM python:slim WORKDIR /app # Add metadata to the image to describe that the container is listening on port 80 -EXPOSE 80 +EXPOSE 8000 # Copy the current directory contents into the container at /app COPY . /app diff --git a/pyproject.toml b/pyproject.toml index 0a9a21b..8bd6d8a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ python = "^3.12" SQLAlchemy = "^2.0.22" psycopg2-binary = "^2.9.9" redis = {extras = ["hiredis"], version = "^5.0.1"} -uvicorn = "^0.24.0" +granian = "^1.0.1" strawberry-graphql = {extras = ["asgi", "debug-server"], version = "^0.216.1" } strawberry-sqlalchemy-mapper = "^0.4.0" sentry-sdk = "^1.37.1" @@ -23,10 +23,11 @@ aiohttp = "^3.9.1" setuptools = "^69.0.2" pytest = "^7.4.2" black = { version = "^23.12.0", python = ">=3.12" } -ruff = { version = "^0.1.8", python = ">=3.12" } +ruff = { version = "^0.1.15", python = ">=3.12" } mypy = { version = "^1.7", python = ">=3.12" } isort = "^5.13.2" pyright = "^1.1.341" +pre-commit = "^3.6.0" [tool.black] line-length = 120 diff --git a/server.py b/server.py index 45a093b..41e067b 100644 --- a/server.py +++ b/server.py @@ -1,7 +1,6 @@ import sys -import uvicorn -from uvicorn.main import logger +from granian import Interfaces, Granina from settings import PORT @@ -55,5 +54,16 @@ def exception_handler(_et, exc, _tb): if __name__ == "__main__": + print('[server] started') sys.excepthook = exception_handler - uvicorn.run("main:app", host="0.0.0.0", port=PORT, proxy_headers=True, server_header=True) + granian_instance = Granian("main:app", + address="0.0.0.0", + port=PORT, + proxy_headers=True, + server_header=True, + workers=2, + threads=2, + websockets=False, + interface=Interfaces.ASGI, + ) + granian_instance.serve() diff --git a/settings.py b/settings.py index eaae333..58633a4 100644 --- a/settings.py +++ b/settings.py @@ -1,6 +1,6 @@ from os import environ -PORT = 80 +PORT = 8000 DB_URL = ( environ.get("DATABASE_URL", environ.get("DB_URL", "")).replace("postgres://", "postgresql://") or "postgresql://postgres@localhost:5432/discoursio"