From 0d39efd0340ea478670363481336ba280691a83b Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Mon, 29 Jun 2026 18:02:10 +0200 Subject: [PATCH] fix: use tailwindcss cli --- .gitignore | 6 +++++- AGENTS.md | 15 +++++++++++++++ Dockerfile | 16 ++++++++++++++-- build-css.sh | 41 +++++++++++++++++++++++++++++++++++++++++ index.html | 2 +- myice/webapi.py | 5 +++++ style-input.css | 3 +++ tailwind.config.js | 8 ++++++++ 8 files changed, 92 insertions(+), 4 deletions(-) create mode 100755 build-css.sh create mode 100644 style-input.css create mode 100644 tailwind.config.js diff --git a/.gitignore b/.gitignore index ad79fa3..51693a2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,11 @@ myice.ini schedule.json .envrc cookies.txt -# Byte-compiled / optimized / DLL files +# Tailwind CSS generated artifacts +style.css +tailwindcss + +# Python bytecode __pycache__/ *.py[cod] *$py.class diff --git a/AGENTS.md b/AGENTS.md index 285d3f6..abea3d3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -48,6 +48,21 @@ pre-commit run ruff-format --files myice/webapi.py pre-commit run mypy --files myice/myice.py ``` +### CSS/Frontend Build + +When modifying `index.html` or the Tailwind CSS setup: + +```bash +# One-off build of style.css +./build-css.sh + +# Watch mode for development +./build-css.sh --watch + +# Or manually with the standalone CLI (if already downloaded) +./tailwindcss -i ./style-input.css -o ./style.css --minify +``` + ### Running the Web API ```bash diff --git a/Dockerfile b/Dockerfile index a307c1d..6018273 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,12 @@ FROM python:3.13-slim AS builder # Create working directory WORKDIR /app -# poetry export -f requirements.txt --output requirements.txt --without-hashes +# Install tools needed for Tailwind CSS build +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + && rm -rf /var/lib/apt/lists/* + # Copy dependency files COPY requirements.txt ./ @@ -12,6 +17,12 @@ COPY requirements.txt ./ RUN --mount=type=cache,target=/root/.cache/pip \ pip install --no-deps --disable-pip-version-check -r requirements.txt +# Build Tailwind CSS +COPY index.html style-input.css tailwind.config.js ./ +RUN curl -sL https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.17/tailwindcss-linux-x64 -o tailwindcss \ + && chmod +x tailwindcss \ + && ./tailwindcss -i ./style-input.css -o ./style.css --minify + # Runtime stage FROM python:3.13-slim AS runtime @@ -29,8 +40,9 @@ RUN useradd --home-dir /app --no-create-home --uid 1000 myice # Copy installed packages from builder stage COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages -# Copy application code +# Copy application code and compiled assets COPY index.html favicon.ico ./ +COPY --from=builder /app/style.css ./style.css COPY myice ./myice # Change ownership of copied files diff --git a/build-css.sh b/build-css.sh new file mode 100755 index 0000000..b2260ab --- /dev/null +++ b/build-css.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -euo pipefail + +# Build CSS using Tailwind CSS standalone CLI +# For local development, run: +# ./build-css.sh # one-off build +# ./build-css.sh --watch # watch mode + +version="v3.4.17" +os="$(uname -s)" +arch="$(uname -m)" + +case "$os" in + Linux*) platform="linux";; + Darwin*) platform="macos";; + *) echo "Unsupported OS: $os"; exit 1;; +esac + +case "$arch" in + x86_64) arch="x64";; + arm64) arch="arm64";; + aarch64) arch="arm64";; + *) echo "Unsupported architecture: $arch"; exit 1;; +esac + +binary="tailwindcss-${platform}-${arch}" +url="https://github.com/tailwindlabs/tailwindcss/releases/download/${version}/${binary}" + +if [ ! -f "tailwindcss" ]; then + echo "Downloading Tailwind CSS standalone CLI (${version} ${platform}/${arch})..." + curl -sL "$url" -o tailwindcss + chmod +x tailwindcss +fi + +if [ "${1:-}" == "--watch" ]; then + echo "Building CSS in watch mode..." + ./tailwindcss -i ./style-input.css -o ./style.css --watch +else + echo "Building CSS..." + ./tailwindcss -i ./style-input.css -o ./style.css --minify +fi diff --git a/index.html b/index.html index e973b47..5c81b76 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ MyIce - Games - + diff --git a/myice/webapi.py b/myice/webapi.py index eebf074..ab01f97 100644 --- a/myice/webapi.py +++ b/myice/webapi.py @@ -140,6 +140,11 @@ def get_health() -> HealthCheck: return HealthCheck(status="OK") +@app.get("/style.css") +async def style_css(): + return FileResponse("style.css") + + @app.get("/favicon.ico") async def favico(): return FileResponse("favicon.ico") diff --git a/style-input.css b/style-input.css new file mode 100644 index 0000000..b5c61c9 --- /dev/null +++ b/style-input.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/tailwind.config.js b/tailwind.config.js new file mode 100644 index 0000000..df138af --- /dev/null +++ b/tailwind.config.js @@ -0,0 +1,8 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: ["./index.html"], + theme: { + extend: {}, + }, + plugins: [], +}