From 9266a1f13167b2cc172a9be3217433a643292cae Mon Sep 17 00:00:00 2001 From: Tris Forster Date: Mon, 29 Sep 2025 23:02:39 +1000 Subject: [PATCH] Fixed packaging of static files --- .gitignore | 1 + Dockerfile | 10 +++++----- squirrel/api.py | 7 +++++-- {app => squirrel/app}/static/css/search-source.css | 0 {app => squirrel/app}/static/css/search.css | 0 .../app}/static/fonts/beyond_the_mountains.ttf | Bin {app => squirrel/app}/static/images/squirrel_32.png | Bin {app => squirrel/app}/templates/base.html | 0 {app => squirrel/app}/templates/home.html | 0 {app => squirrel/app}/templates/search_results.html | 0 10 files changed, 11 insertions(+), 7 deletions(-) rename {app => squirrel/app}/static/css/search-source.css (100%) rename {app => squirrel/app}/static/css/search.css (100%) rename {app => squirrel/app}/static/fonts/beyond_the_mountains.ttf (100%) rename {app => squirrel/app}/static/images/squirrel_32.png (100%) rename {app => squirrel/app}/templates/base.html (100%) rename {app => squirrel/app}/templates/home.html (100%) rename {app => squirrel/app}/templates/search_results.html (100%) diff --git a/.gitignore b/.gitignore index 8d35cb3..f837b08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ +dist *.pyc diff --git a/Dockerfile b/Dockerfile index 965f289..42bc282 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ FROM recoll -RUN apt-get install breeze-icon-theme +RUN apt-get -y install breeze-icon-theme python3-venv -COPY . /opt/squirrel -WORKDIR /opt/squirrel +COPY dist/squirrel-0.3.0-py3-none-any.whl squirrel-0.3.0-py3-none-any.whl -RUN pip install --break-system-packages -e . +RUN python3 -m venv --system-site-packages /opt/squirrel +RUN /opt/squirrel/bin/pip install squirrel-0.3.0-py3-none-any.whl EXPOSE 8000 -ENTRYPOINT ["/bin/bash"] +ENTRYPOINT ["/opt/squirrel/bin/squirrel"] diff --git a/squirrel/api.py b/squirrel/api.py index 92ad5e2..805712a 100644 --- a/squirrel/api.py +++ b/squirrel/api.py @@ -5,6 +5,7 @@ from fastapi.templating import Jinja2Templates from typing import Any import logging import subprocess +import os.path from recoll import recoll @@ -15,6 +16,8 @@ from fastapi import BackgroundTasks logger = logging.getLogger() logging.basicConfig(level=logging.DEBUG) +SQUIRREL_FOLDER = os.path.dirname(os.path.realpath(__file__)) + DOC_FOLDER = "/mnt/docs" STRIP_CHARS = len(DOC_FOLDER) + len("file:///") @@ -35,14 +38,14 @@ class Recoll(object): repo = Recoll() app = FastAPI() -app.mount("/static", StaticFiles(directory="app/static")) +app.mount("/static", StaticFiles(directory=f"{SQUIRREL_FOLDER}/app/static")) app.mount("/docs", StaticFiles(directory=DOC_FOLDER)) app.mount( "/icons", StaticFiles(directory="/usr/share/icons/breeze/mimetypes/32", follow_symlink=True), ) -templates = Jinja2Templates(directory="app/templates") +templates = Jinja2Templates(directory=f"{SQUIRREL_FOLDER}/app/templates") @app.get("/") diff --git a/app/static/css/search-source.css b/squirrel/app/static/css/search-source.css similarity index 100% rename from app/static/css/search-source.css rename to squirrel/app/static/css/search-source.css diff --git a/app/static/css/search.css b/squirrel/app/static/css/search.css similarity index 100% rename from app/static/css/search.css rename to squirrel/app/static/css/search.css diff --git a/app/static/fonts/beyond_the_mountains.ttf b/squirrel/app/static/fonts/beyond_the_mountains.ttf similarity index 100% rename from app/static/fonts/beyond_the_mountains.ttf rename to squirrel/app/static/fonts/beyond_the_mountains.ttf diff --git a/app/static/images/squirrel_32.png b/squirrel/app/static/images/squirrel_32.png similarity index 100% rename from app/static/images/squirrel_32.png rename to squirrel/app/static/images/squirrel_32.png diff --git a/app/templates/base.html b/squirrel/app/templates/base.html similarity index 100% rename from app/templates/base.html rename to squirrel/app/templates/base.html diff --git a/app/templates/home.html b/squirrel/app/templates/home.html similarity index 100% rename from app/templates/home.html rename to squirrel/app/templates/home.html diff --git a/app/templates/search_results.html b/squirrel/app/templates/search_results.html similarity index 100% rename from app/templates/search_results.html rename to squirrel/app/templates/search_results.html