diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5345651 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM python:3.12-slim-bookworm + +WORKDIR /app + +# Install system deps, download frontend assets, purge curl in one layer +RUN apt-get update && apt-get install -y --no-install-recommends curl \ + && mkdir -p /app/imptune/static \ + && curl -sL --fail -o /app/imptune/static/pico.min.css \ + "https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" \ + && curl -sL --fail -o /app/imptune/static/htmx.min.js \ + "https://unpkg.com/htmx.org@2/dist/htmx.min.js" \ + && curl -sL --fail -o /app/imptune/static/alpine.min.js \ + "https://cdn.jsdelivr.net/npm/alpinejs@3/dist/cdn.min.js" \ + && apt-get purge -y curl && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY imptune/ /app/imptune/ + +VOLUME ["/data"] + +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1 + +EXPOSE 8000 + +CMD ["uvicorn", "imptune.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..de34fa7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +services: + imptune: + build: . + ports: + - "8000:8000" + volumes: + - imptune_data:/data + restart: unless-stopped + environment: + - DATA_DIR=/data + +volumes: + imptune_data: diff --git a/imptune/__init__.py b/imptune/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/imptune/api/__init__.py b/imptune/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/imptune/api/health.py b/imptune/api/health.py new file mode 100644 index 0000000..b4cb63b --- /dev/null +++ b/imptune/api/health.py @@ -0,0 +1,8 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("/health") +def health(): + return {"status": "ok"} diff --git a/imptune/api/pages.py b/imptune/api/pages.py new file mode 100644 index 0000000..344b10c --- /dev/null +++ b/imptune/api/pages.py @@ -0,0 +1,20 @@ +from fastapi import APIRouter, Request +from fastapi.responses import HTMLResponse +from fastapi.templating import Jinja2Templates +from pathlib import Path + +router = APIRouter() + +templates = Jinja2Templates(directory=str(Path(__file__).parent.parent / "templates")) + + +@router.get("/", response_class=HTMLResponse) +def dashboard(request: Request): + return templates.TemplateResponse( + "dashboard.html", + { + "request": request, + "recent_printers": [], + "recent_packages": [], + }, + ) diff --git a/imptune/config.py b/imptune/config.py new file mode 100644 index 0000000..bb55eeb --- /dev/null +++ b/imptune/config.py @@ -0,0 +1,12 @@ +import os +from pathlib import Path + +from dotenv import load_dotenv + +load_dotenv() + +DATA_DIR = os.environ.get("DATA_DIR", "/data") +PORT = int(os.environ.get("PORT", "8000")) + +DB_PATH = str(Path(DATA_DIR) / "imptune.db") +DRIVERS_DIR = str(Path(DATA_DIR) / "drivers") diff --git a/imptune/main.py b/imptune/main.py new file mode 100644 index 0000000..3da307d --- /dev/null +++ b/imptune/main.py @@ -0,0 +1,25 @@ +from pathlib import Path + +from fastapi import FastAPI +from fastapi.staticfiles import StaticFiles + +from imptune.api import health, pages +from imptune.config import DATA_DIR, DRIVERS_DIR + +app = FastAPI(title="ImpTune") + +# Serve baked-in static assets (pico.min.css, htmx.min.js, alpine.min.js) +_static_dir = Path(__file__).parent / "static" +app.mount("/static", StaticFiles(directory=str(_static_dir)), name="static") + +# Register routers +app.include_router(health.router) +app.include_router(pages.router) + + +@app.on_event("startup") +def on_startup(): + import os + + os.makedirs(DATA_DIR, exist_ok=True) + os.makedirs(DRIVERS_DIR, exist_ok=True) diff --git a/imptune/static/app.css b/imptune/static/app.css new file mode 100644 index 0000000..95e649e --- /dev/null +++ b/imptune/static/app.css @@ -0,0 +1,93 @@ +/* ImpTune layout — supplements Pico CSS */ + +.layout { + display: flex; + min-height: 100vh; +} + +/* Sidebar */ +.sidebar { + width: 220px; + flex-shrink: 0; + border-right: 1px solid var(--pico-muted-border-color, #e0e0e0); + padding: 1rem 0; + display: flex; + flex-direction: column; +} + +.sidebar-brand { + padding: 0.5rem 1rem 1rem; + font-size: 1.1rem; + border-bottom: 1px solid var(--pico-muted-border-color, #e0e0e0); + margin-bottom: 0.5rem; +} + +.sidebar-nav { + list-style: none; + padding: 0; + margin: 0; +} + +.sidebar-nav li { + margin: 0; +} + +.sidebar-nav a { + display: block; + padding: 0.6rem 1rem; + text-decoration: none; + color: inherit; + font-weight: 400; +} + +.sidebar-nav a:hover { + background-color: var(--pico-secondary-background, rgba(0,0,0,0.05)); +} + +.sidebar-nav a.active { + font-weight: 600; + background-color: var(--pico-primary-background, rgba(0,0,0,0.08)); + border-left: 3px solid var(--pico-primary, #1a73e8); +} + +/* Main content */ +.main-content { + flex: 1; + padding: 1.5rem; + overflow-y: auto; +} + +/* Quick action buttons */ +.quick-actions { + display: flex; + gap: 0.75rem; + margin-bottom: 1.5rem; + flex-wrap: wrap; +} + +.btn-action { + display: inline-block; + padding: 0.5rem 1rem; + border: 1px solid var(--pico-primary, #1a73e8); + border-radius: 4px; + text-decoration: none; + color: var(--pico-primary, #1a73e8); + font-weight: 500; +} + +.btn-action[aria-disabled="true"] { + opacity: 0.5; + cursor: not-allowed; + pointer-events: none; +} + +/* Empty state */ +.empty-state { + color: var(--pico-muted-color, #666); + font-style: italic; +} + +/* Recent activity */ +.activity-section { + margin-bottom: 1.5rem; +} diff --git a/imptune/templates/base.html b/imptune/templates/base.html new file mode 100644 index 0000000..399d157 --- /dev/null +++ b/imptune/templates/base.html @@ -0,0 +1,31 @@ + + +
+ + +No printers configured yet.
+ {% endif %} +No packages exported yet.
+ {% endif %} +