From 10199d71a51e3a66f5331bde0f234b9cbddf142e Mon Sep 17 00:00:00 2001 From: Hayden Date: Fri, 1 Jan 2021 22:33:19 -0900 Subject: [PATCH] rebuild dockerfile and startup.py --- Dockerfile | 6 ++--- mealie/app.py | 4 +++ mealie/services/settings_services.py | 9 ++++--- mealie/startup.py | 40 ++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 mealie/startup.py diff --git a/Dockerfile b/Dockerfile index 3833b47a9d62..50025f77961c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ RUN npm install COPY ./frontend/ . RUN npm run build -FROM python:3 +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8 RUN apt-get update -y && \ apt-get install -y python-pip python-dev @@ -21,6 +21,4 @@ COPY ./mealie /app COPY --from=build-stage /app/dist /app/dist -ENTRYPOINT [ "python" ] -# TODO Reconfigure Command to start a Gunicorn Server that managed the Uvicorn Server. Also Learn how to do that :-/ -CMD [ "app.py" ] \ No newline at end of file +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "9000"] \ No newline at end of file diff --git a/mealie/app.py b/mealie/app.py index d1f3971ef940..66034519e4cf 100644 --- a/mealie/app.py +++ b/mealie/app.py @@ -4,6 +4,7 @@ import uvicorn from fastapi import FastAPI from fastapi.staticfiles import StaticFiles +import startup from routes import ( backup_routes, meal_routes, @@ -42,6 +43,9 @@ def invalid_api(): app.include_router(static_routes.router) +startup.ensure_dirs() +startup.generate_default_theme() + if __name__ == "__main__": logger.info("-----SYSTEM STARTUP-----") diff --git a/mealie/services/settings_services.py b/mealie/services/settings_services.py index 6af176d4e083..b2b55109b28f 100644 --- a/mealie/services/settings_services.py +++ b/mealie/services/settings_services.py @@ -1,12 +1,15 @@ import json from typing import List, Optional -from db.settings_models import (SiteSettingsDocument, SiteThemeDocument, - ThemeColorsDocument, WebhooksDocument) +from db.settings_models import ( + SiteSettingsDocument, + SiteThemeDocument, + ThemeColorsDocument, + WebhooksDocument, +) from pydantic import BaseModel - class Webhooks(BaseModel): webhookTime: str webhookURLs: Optional[List[str]] diff --git a/mealie/startup.py b/mealie/startup.py new file mode 100644 index 000000000000..0810b9019c2d --- /dev/null +++ b/mealie/startup.py @@ -0,0 +1,40 @@ +from pathlib import Path + +from services.settings_services import Colors, SiteTheme +from utils.logger import logger + +CWD = Path(__file__).parent +DATA_DIR = CWD.joinpath("data") +TEMP_DIR = CWD.joinpath("data", "temp") + + +def ensure_dirs(): + DATA_DIR.mkdir(parents=True, exist_ok=True) + DATA_DIR.joinpath("img").mkdir(parents=True, exist_ok=True) + DATA_DIR.joinpath("backups").mkdir(parents=True, exist_ok=True) + DATA_DIR.joinpath("templates").mkdir(parents=True, exist_ok=True) + + +def generate_default_theme(): + default_colors = { + "primary": "#E58325", + "accent": "#00457A", + "secondary": "#973542", + "success": "#5AB1BB", + "info": "#FFFD99", + "warning": "#FF4081", + "error": "#EF5350", + } + + try: + SiteTheme.get_by_name("default") + return "default theme exists" + except: + logger.info("Generating Default Theme") + colors = Colors(**default_colors) + default_theme = SiteTheme(name="default", colors=colors) + default_theme.save_to_db() + + +if __name__ == "__main__": + pass