From a101eb7c1fe692fef0391fb2294a51f09da415c3 Mon Sep 17 00:00:00 2001 From: Redume Date: Fri, 18 Oct 2024 19:58:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D0=B8=D1=82=D0=B8=D0=BA=D1=83,=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=84=D0=B8=D0=BA=D1=81=D0=B8=D0=BB=20=D1=80=D0=BE=D1=83?= =?UTF-8?q?=D1=82=D1=8B,=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20SSL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 10 ++++++---- docker-compose.yaml | 13 +++++++++++++ main.py | 25 ++++++++++++++++++++----- 3 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 docker-compose.yaml diff --git a/Dockerfile b/Dockerfile index 474aca3..1a1989a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,13 @@ FROM python:3.12 -WORKDIR /starlio-web +WORKDIR / -COPY ./requirements.txt /starlio-web/requirements.txt +COPY ./requirements.txt ./ -RUN pip3 install --no-cache-dir --upgrade -r /starlio-web/requirements.txt +RUN pip3 install --no-cache-dir --upgrade -r ./requirements.txt -COPY ./ /starlio-web/ +COPY . . + +EXPOSE 8000 CMD ["python", "main.py"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..b5f7878 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,13 @@ +services: + starlio-web: + build: . + ports: + - '8000:8000' + restart: unless-stopped + volumes: + - './CertSSL:/CertSSL' + - './config.yaml:/config.yaml' + +volumes: + starlio-web: + driver: local \ No newline at end of file diff --git a/main.py b/main.py index 55cef12..7815266 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,20 @@ +import uvicorn +import yaml + from fastapi.staticfiles import StaticFiles from starlette.responses import FileResponse from fastapi import FastAPI -import uvicorn -import os +from src.middleware.plausible_analytics import PlausibleAnalytics + +config = yaml.safe_load(open('./config.yaml')) from src.routes import index from src.routes import wallpaper app = FastAPI() +app.middleware('http')(PlausibleAnalytics()) + app.include_router(index.router) app.include_router(wallpaper.router) @@ -17,12 +23,12 @@ app.mount('/.well-known/', StaticFiles(directory='./.well-known/')) @app.get('/app-ads.txt') -async def app_ads(req): +async def app_ads(): return FileResponse('./app-ads.txt') @app.get('/robots.txt') -async def robots_txt(req): +async def robots_txt(): return FileResponse('./robots.txt') @@ -31,4 +37,13 @@ async def not_found(req, __): return FileResponse('./src/web/html/error/404.html') if __name__ == '__main__': - uvicorn.run(app, host="0.0.0.0", port=int(os.environ['PORT'])) + uvicorn.run(app, + host=config['server']['host'], + port=8000, + ssl_keyfile=config['server']['ssl_privkey'] + if config['server']['ssl_work'] + else None, + ssl_certfile=config['server']['ssl_cert'] + if config['server']['ssl_work'] + else None + )