Skip to content

Commit

Permalink
feat/refactor: migrate to uvicorn-gunicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Feb 27, 2024
1 parent 56f7c6b commit 6cae78a
Show file tree
Hide file tree
Showing 21 changed files with 448 additions and 172 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ on:
jobs:
test:
uses: winstxnhdw/actions/.github/workflows/python.yml@main
with:
python-version: 3.11

build:
uses: winstxnhdw/actions/.github/workflows/docker-push.yml@main
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on: pull_request
jobs:
test:
uses: winstxnhdw/actions/.github/workflows/python.yml@main
with:
python-version: 3.11

auto-merge:
needs: test
Expand Down
18 changes: 13 additions & 5 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
order rate_limit before basicauth
}

:{$APP_PORT} {
handle_path /api/* {
reverse_proxy http://localhost:{$SERVER_PORT} {
transport http {
versions h2c
}
rate_limit {
zone dynamic_example {
key {remote_host}
events {$EVENTS_PER_WINDOW}
window 60s
}
}

handle_path /api/* {
reverse_proxy http://localhost:{$SERVER_PORT}
}
}
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM ghcr.io/winstxnhdw/capgen:main

ENV SERVER_PORT 5000
ENV APP_PORT 7860

ENV OMP_NUM_THREADS 4
ENV OMP_NUM_THREADS 8
ENV CT2_USE_EXPERIMENTAL_PACKED_GEMM 1
ENV CT2_FORCE_CPU_ISA AVX512
ENV EVENTS_PER_WINDOW 5

EXPOSE $APP_PORT
10 changes: 6 additions & 4 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11.6-slim as python-builder
FROM python:slim as python-builder

ENV POETRY_VIRTUALENVS_CREATE false
ENV POETRY_HOME /opt/poetry
Expand All @@ -16,14 +16,16 @@ RUN poetry install --without=dev

FROM caddy:builder-alpine as caddy-builder

RUN xcaddy build
RUN xcaddy build --with github.com/mholt/caddy-ratelimit


FROM python:3.11.6-slim
FROM python:slim

ENV HOME /home/user
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV SERVER_PORT 5000
ENV EVENTS_PER_WINDOW 100000

RUN useradd -m -u 1000 user

Expand All @@ -33,7 +35,7 @@ WORKDIR $HOME/app

COPY --chown=user --from=caddy-builder /usr/bin/caddy /usr/bin/caddy
COPY --chown=user --from=python-builder /usr/local/bin /usr/local/bin
COPY --chown=user --from=python-builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --chown=user --from=python-builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --chown=user . $HOME/app

CMD ["supervisord"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ You can spin the server up locally with the following. You can access the Swagge

```bash
docker build -f Dockerfile.build -t capgen .
docker run --rm -e SERVER_PORT=5000 -e APP_PORT=7860 -p 7860:7860 capgen
docker run --rm -e APP_PORT=7860 -p 7860:7860 capgen
```
13 changes: 13 additions & 0 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# pylint: skip-file

from server import initialise
from server.config import Config

wsgi_app = f'{initialise.__module__}:{initialise.__name__}()'
reload = False
accesslog = '-'
preload_app = True
bind = f'0.0.0.0:{Config.server_port}'
workers = Config.worker_count
worker_class = 'uvicorn.workers.UvicornWorker'
timeout = 300
16 changes: 0 additions & 16 deletions main.py

This file was deleted.

Loading

0 comments on commit 6cae78a

Please sign in to comment.