From 9bca9ec45b7dc3e9a39499fc671c6e725000d50d Mon Sep 17 00:00:00 2001 From: egvimo Date: Sat, 21 Oct 2023 19:32:22 +0200 Subject: [PATCH] feat: revert back to FastAPI --- Dockerfile | 2 +- app.py | 9 +++++---- requirements.txt | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8b61e5f..86fbe8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,4 +13,4 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt \ EXPOSE 8000 -CMD ["gunicorn", "app:app", "-b", "0.0.0.0"] +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--no-access-log"] diff --git a/app.py b/app.py index a0a7e4b..2223044 100644 --- a/app.py +++ b/app.py @@ -1,13 +1,14 @@ import os -from flask import Flask, Response +from fastapi import FastAPI +from fastapi.responses import PlainTextResponse import apt_info root_dir = os.environ.get("APT_ROOT_DIR", "/") -app = Flask(__name__) +app = FastAPI() -@app.route("/metrics") +@app.get("/metrics", response_class=PlainTextResponse) def metrics(): data = apt_info.generate_metrics(root_dir=root_dir) - return Response(data, mimetype='text/plain') + return data diff --git a/requirements.txt b/requirements.txt index 90d5ace..f174523 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ python-apt @ git+https://salsa.debian.org/apt-team/python-apt.git@2.5.3 prometheus_client==0.17.1 -Flask==3.0.0 -gunicorn==21.2.0 +fastapi==0.104.0 +uvicorn[standard]==0.23.2