From 78ae20e542e3c7e5bc6dd0afdcf18966826eeb04 Mon Sep 17 00:00:00 2001 From: Jennifer Everett Date: Sat, 7 Nov 2026 22:53:33 -0600 Subject: [PATCH 1/2] chore(ignore): exclude local case PDF from git and Docker builds Co-Authored-By: Claude Opus 5.5 --- .dockerignore | 3 +++ .gitignore | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.dockerignore b/.dockerignore index d91be67..1ce182b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -59,3 +59,6 @@ backups/ # Screenshots are README assets, not part of the image docs/screenshots/ + +# Local case material (do not include in images) +CFS2303678 EDG Analysis.pdf diff --git a/.gitignore b/.gitignore index be22cf9..cc75a8c 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,6 @@ frontend/coverage/ # Claude Code local settings .claude/ + +# Local case material (do not commit) +CFS2303678 EDG Analysis.pdf From 4ee4e316014b91cada6fff0ef0438ff75e4c4652 Mon Sep 17 00:00:00 2001 From: Jennifer Everett Date: Thu, 19 Nov 2026 23:45:10 -0600 Subject: [PATCH 2/2] chore: update Docker configuration and documentation - Refactor Dockerfile for improved multi-stage builds and dependency management. - Update docker-compose.yml for better environment variable handling. - Exclude unnecessary files in .dockerignore. - Bump frontend package version to 1.3.0 and update licenses. - Add README.Docker.md for clearer Docker usage instructions. --- .dockerignore | 89 +++++---------- Dockerfile | 227 +++++++++++-------------------------- README.Docker.md | 25 ++++ docker-compose.yml | 71 +++--------- frontend/package-lock.json | 12 +- 5 files changed, 141 insertions(+), 283 deletions(-) create mode 100644 README.Docker.md diff --git a/.dockerignore b/.dockerignore index 1ce182b..0d92f03 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,64 +1,37 @@ -# Git -.git -.gitignore -.gitattributes +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ -# Environment files (NEVER include in image) — any depth -**/.env -**/.env.* -**/*.env - -# IDE -.vscode -.idea -**/*.swp -**/*.swo - -# Python — any depth +**/.DS_Store **/__pycache__ -**/*.pyc -**/*.pyo -**/.pytest_cache -**/.mypy_cache -**/.ruff_cache -**/htmlcov -**/.coverage - -# Node — any depth (frontend/node_modules must never enter the build context) +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose.y*ml +**/Dockerfile* **/node_modules - -# Data directories (mounted as volumes; root-level dir by design) -**/data/ -**/*.db - -# Documentation (NOTICE.md and LICENSE ship in the image: the licence terms -# and third-party notices must travel with a distributed copy) -**/*.md -!NOTICE.md - -# CI/CD -.github -.gitlab-ci.yml - -# Docker -docker-compose*.yml -Dockerfile.* - -# Backups (database dumps and data archives; never part of a build context) -backups/ -**/*.sql -**/*.sql.gz* -**/*.tar.gz* -**/*.enc - -# Secrets — any depth -**/*.pem -**/*.key -**/*.crt -**/credentials.json - -# Screenshots are README assets, not part of the image -docs/screenshots/ +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md # Local case material (do not include in images) CFS2303678 EDG Analysis.pdf diff --git a/Dockerfile b/Dockerfile index 373c174..176c84a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,163 +1,68 @@ -# Multi-stage Dockerfile for Coolify deployment -# Stage 1: Build frontend with Vite -# Stage 2: Serve both backend API and frontend from one container - -# ---- Stage 1: Frontend Build ---- -# Base images float on the minor line on purpose (node:24, python:3.11): a -# rebuild picks up OS security fixes, and Trivy gates the image in CI, so a -# digest pin that nobody bumps means a permanently red build job. For a fully -# reproducible build, replace the tags with `image@sha256:` (resolve -# with `docker buildx imagetools inspect `); Dependabot's docker -# ecosystem (.github/dependabot.yml) will then propose digest bumps. -FROM node:24-slim AS frontend-build - -WORKDIR /frontend -COPY frontend/package.json frontend/package-lock.json* ./ -RUN npm ci -COPY frontend/ . -RUN npm run build && \ - test -f dist/index.html && \ - echo "✓ Vite build successful" || \ - (echo "✗ FATAL: Vite build failed - dist/index.html not found" && exit 1) - -# ---- Stage 1b: Word add-in build ---- -# The task pane is plain static files; built here and served at /addin/ on the -# app's own origin, so the add-in deploys with the stack. The manifest for a -# deployment is rendered by the backend (GET /api/v1/addin/manifest.xml). -FROM node:24-slim AS addin-build - -WORKDIR /addin -COPY word-addin/package.json word-addin/package-lock.json* ./ -RUN npm ci -COPY word-addin/ . -RUN ADDIN_BASE=/addin/ npm run build && \ - test -f dist/index.html && \ - echo "✓ Word add-in build successful" || \ - (echo "✗ FATAL: Word add-in build failed - dist/index.html not found" && exit 1) - -# ---- Stage 2: Python Runtime ---- -# Floating patch tag (see note above on the frontend stage). -FROM python:3.11-slim AS python-base -ENV PYTHONUTF8=1 \ - PYTHONIOENCODING=utf-8 \ - LANG=C.UTF-8 \ - LC_ALL=C.UTF-8 - -# Install nginx, system dependencies, and security updates (distro versions, -# not pinned — see the base-image note above) -RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends \ - nginx \ - curl \ - gosu \ - libmagic1 \ - libffi8 \ - tesseract-ocr \ - tesseract-ocr-eng \ - && rm -rf /var/lib/apt/lists/* - -# Create non-root user for running the application -RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser - -# Set working directory +# syntax=docker/dockerfile:1 + +ARG PYTHON_VERSION=3.11 + +# Install Python dependencies separately so the source and frontend changes do +# not invalidate the dependency layer. +FROM python:${PYTHON_VERSION}-slim AS python-deps +ENV VIRTUAL_ENV=/opt/venv +ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" +RUN python -m venv "${VIRTUAL_ENV}" +WORKDIR /build +COPY backend/requirements.txt ./requirements.txt +# Keep pip's download/wheel cache in the BuildKit mount for faster rebuilds. +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r requirements.txt + +# Frontend SPA build. +FROM node:22-alpine3.22 AS frontend-build +WORKDIR /src/frontend +COPY frontend/package*.json ./ +RUN --mount=type=cache,target=/root/.npm npm ci +COPY frontend/ ./ +RUN npm run build + +# Word add-in build. Vite's base path matches the bundled serving path. +FROM node:22-alpine3.22 AS addin-build +WORKDIR /src/word-addin +COPY word-addin/package*.json ./ +RUN --mount=type=cache,target=/root/.npm npm ci +COPY word-addin/ ./ +ENV ADDIN_BASE=/addin/ +RUN npm run build + +# Development target used by docker-compose.dev.yml. +FROM python:${PYTHON_VERSION}-slim AS python-base +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + VIRTUAL_ENV=/opt/venv \ + PATH="/opt/venv/bin:${PATH}" WORKDIR /app - -# Copy backend requirements and install (prefer lock file for reproducible builds) -COPY backend/requirements.txt backend/requirements.lock* ./ - -# Base-image tooling is not in the lock file but ships in the image, so Trivy -# scans it. Pin it to current releases (pip/setuptools/wheel/jaraco.context -# CVEs in 2026) instead of whatever python:3.11-slim happens to bundle. -RUN pip install --no-cache-dir --upgrade "pip==26.2.1" "setuptools==84.0.0" "wheel==0.48.0" "jaraco.context==6.1.2" - -# Install Python dependencies (prefer lock file for reproducible builds) -RUN if [ -f requirements.lock ]; then \ - pip install --no-cache-dir -r requirements.lock; \ - else \ - pip install --no-cache-dir -r requirements.txt; \ - fi - -# pip and wheel are build-time tools: strip them from the runtime filesystem. -# Nothing installs packages at runtime, and pip's vendored copies of its own -# dependencies (pip/_vendor/vendor.txt) otherwise surface in image scans with -# no fix available short of a new pip release. setuptools stays: greenlet, pillow -# and uvloop declare it as a runtime requirement. -RUN python -m pip uninstall -y pip wheel - -# tiktoken downloads its encoding table on first use. Fetch it at build time so -# the app starts and chunks documents with no outbound network access. -ENV TIKTOKEN_CACHE_DIR=/opt/tiktoken -RUN python -c "import tiktoken; tiktoken.get_encoding('cl100k_base')" \ - && chmod -R a+rX /opt/tiktoken - -# Copy backend code -COPY --chown=appuser:appuser backend/app ./app - -# Copy Alembic config + migrations so `alembic upgrade head` can run at startup. -# Without these, schema changes never apply in production (create_all only adds -# whole tables, never columns). -COPY --chown=appuser:appuser backend/alembic.ini ./alembic.ini -COPY --chown=appuser:appuser backend/migrations ./migrations - -# Copy built frontend from stage 1 -COPY --chown=appuser:appuser --from=frontend-build /frontend/dist /var/www/html -# The Word add-in pane, served at /addin/ (nginx here, Caddy in the bundled -# stack), and the manifest template the backend renders per deployment. -COPY --chown=appuser:appuser --from=addin-build /addin/dist /var/www/html/addin -COPY --chown=appuser:appuser word-addin/manifest.xml /app/addin-manifest.xml - -# Verify the built index.html references assets (not /src/main.jsx) -RUN grep -q '/assets/' /var/www/html/index.html && \ - echo "✓ Frontend dist verified" || \ - (echo "✗ FATAL: /var/www/html/index.html missing asset references" && cat /var/www/html/index.html && exit 1) - -# Copy logo asset for favicon/branding -COPY --chown=appuser:appuser frontend/logo.webp /var/www/html/logo.webp - -# Copy nginx config. Root-owned and read-only for everyone else: the root -# master process reads it, and appuser (the workers and the application) must -# not be able to rewrite what nginx serves or proxies to. -COPY nginx.unified.conf /etc/nginx/sites-enabled/default -RUN chown root:root /etc/nginx/sites-enabled/default \ - && chmod 0644 /etc/nginx/sites-enabled/default - -# Create data directories with broad permissions (Coolify may run as non-root) -RUN mkdir -p /app/data/chroma /app/data/uploads /app/data/audit_logs /app/data/user_settings \ - && chmod -R 755 /app/data - -# nginx workers run as appuser (the master is started by start.sh, see below) -RUN chown -R appuser:appuser /var/log/nginx /var/lib/nginx /run \ - && sed -i 's/user www-data;/user appuser;/' /etc/nginx/nginx.conf \ - && grep -q '^user appuser;' /etc/nginx/nginx.conf - -# License terms and third-party notices travel with the image -COPY LICENSE NOTICE.md /app/ - -# Declare data volume -VOLUME ["/app/data"] - -# Expose port 80 (Coolify expects this) +RUN apt-get update && apt-get install -y --no-install-recommends \ + curl libmagic1 libgomp1 tesseract-ocr tesseract-ocr-eng \ + && rm -rf /var/lib/apt/lists/* \ + && adduser --disabled-password --gecos "" --home /nonexistent \ + --shell /usr/sbin/nologin --no-create-home --uid 10001 appuser +COPY --from=python-deps /opt/venv /opt/venv +COPY backend/app/ /app/app/ +COPY backend/alembic.ini /app/alembic.ini +COPY backend/migrations/ /app/migrations/ +COPY start.sh /app/start.sh +RUN chmod 755 /app/start.sh && mkdir -p /app/data && chown appuser:appuser /app/data +EXPOSE 8000 +USER appuser +CMD ["uvicorn", "app.main:app", "--host=0.0.0.0", "--port=8000"] + +# Production image: nginx serves the compiled frontend and proxies API traffic; +# start.sh performs migrations, drops privileges for Uvicorn, and handles shutdown. +FROM python-base AS app +USER root +RUN apt-get update && apt-get install -y --no-install-recommends nginx gosu \ + && rm -f /etc/nginx/sites-enabled/default \ + && rm -rf /var/lib/apt/lists/* +COPY nginx.unified.conf /etc/nginx/conf.d/default.conf +COPY --from=frontend-build /src/frontend/dist/ /var/www/html/ +COPY --from=addin-build /src/word-addin/dist/ /var/www/html/addin/ +COPY word-addin/manifest.xml /app/addin-manifest.xml EXPOSE 80 - -# Health check — through nginx (:80), so a dead nginx OR a dead uvicorn marks -# the container unhealthy. The start period covers migrations and first boot. -HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \ - CMD curl -fsS http://localhost/health || exit 1 - -# Start script - runs both nginx and uvicorn -COPY start.sh /start.sh -RUN chmod +x /start.sh - -# Bake the git sha into the runtime env so /health can report which build is -# serving. CI and Coolify pass SOURCE_COMMIT as a build arg. Declared last so a -# new commit does not invalidate the dependency layers above. -ARG SOURCE_COMMIT=unknown -ENV SOURCE_COMMIT=$SOURCE_COMMIT - -# No USER directive on purpose: start.sh must begin as root to chown the mounted -# /app/data volume (Docker/Coolify create named volumes root-owned) and to let -# nginx bind :80. It then drops privileges: nginx workers run as appuser (see -# the nginx.conf edit above) and uvicorn — the only process that touches client -# data — is started as appuser via gosu. start.sh refuses to start if the drop -# does not work. Alembic migrations run as appuser too: importing the models -# touches files under /app/data, which must stay appuser-owned. -CMD ["/start.sh"] +ENTRYPOINT ["/app/start.sh"] diff --git a/README.Docker.md b/README.Docker.md new file mode 100644 index 0000000..e22e0b2 --- /dev/null +++ b/README.Docker.md @@ -0,0 +1,25 @@ +# Docker + +### Building and running your application + +When you're ready, start your application by running: +`docker compose up --build`. + +Your application will be available at . + +### Deploying your application to the cloud + +First, build your image, e.g.: `docker build -t myapp .`. +If your cloud uses a different CPU architecture than your development +machine (e.g., you are on a Mac M1 and your cloud provider is amd64), +you'll want to build the image for that platform, e.g.: +`docker build --platform=linux/amd64 -t myapp .`. + +Then, push it to your registry, e.g. `docker push myregistry.com/myapp`. + +Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/) +docs for more detail on building and pushing. + +### References + +* [Docker's Python guide](https://docs.docker.com/language/python/) diff --git a/docker-compose.yml b/docker-compose.yml index 6bf40fe..0bb96de 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,77 +1,32 @@ -# Coolify Docker Compose - SSL handled by Coolify/Traefik automatically -# One unified image (root Dockerfile): nginx serves the built frontend on :80 -# and proxies /api/* to uvicorn in the same container. -# -# This file does NOT include PostgreSQL or Redis: provision both in Coolify -# (or use managed services) and pass their URLs below. The Redis instance must -# run with `maxmemory-policy noeviction` — it holds revoked-token markers and -# lockout counters, which an LRU policy would silently drop. -# See deploy/COOLIFY-SETUP.md. - +# Single-app deployment behind a platform proxy (Coolify/Traefik/nginx). +# Configure external PostgreSQL and Redis URLs in .env and persist /app/data. services: app: + image: ${CASECITE_IMAGE:-ghcr.io/thomasunise/casecite}:${CASECITE_TAG:-latest} build: context: . dockerfile: Dockerfile + restart: unless-stopped + env_file: + - .env environment: - # Real (fail-closed) production posture: DEBUG is off, so every secret - # and backing service below must be set or the app refuses to start. - # For local development use docker-compose.dev.yml (DEBUG=true). - # --- Required in production (startup fails closed if unset) --- - # Generate secrets with: openssl rand -hex 32 (salt: openssl rand -hex 16) - - SECRET_KEY=${SECRET_KEY:?SECRET_KEY is required (openssl rand -hex 32)} - - ENCRYPTION_SALT=${ENCRYPTION_SALT:?ENCRYPTION_SALT is required (openssl rand -hex 16)} - - AUDIT_HMAC_KEY=${AUDIT_HMAC_KEY:?AUDIT_HMAC_KEY is required (openssl rand -hex 32)} - - DATABASE_URL=${DATABASE_URL:?DATABASE_URL is required (postgresql+asyncpg://...)} - - REDIS_URL=${REDIS_URL:?REDIS_URL is required (redis://host:6379/0)} - - CORS_ORIGINS=${CORS_ORIGINS:?CORS_ORIGINS is required (https://app.example.com)} - # Required: the public hostname(s) this instance serves. Without it - # TrustedHost falls back to localhost-only and 400s every real request. - - ALLOWED_HOSTS=${ALLOWED_HOSTS:?ALLOWED_HOSTS is required (comma-separated hostnames, e.g. app.example.com)} - # Confirm storage is encrypted at rest (LUKS or provider disk encryption): - # this container's data volume AND the disks behind the Postgres and - # Redis instances named in DATABASE_URL / REDIS_URL. Derived privileged - # text (vector chunks, extracted clauses, chat history, job results) is - # stored in cleartext; the app refuses to start until you acknowledge it. - - DISK_ENCRYPTION_ACKNOWLEDGED=${DISK_ENCRYPTION_ACKNOWLEDGED:?DISK_ENCRYPTION_ACKNOWLEDGED is required - enable full-disk encryption on the data volume, then set to true} - # Required: the reverse proxy's IP/CIDR (Coolify/Traefik connects from its - # Docker-network address, e.g. 10.0.1.0/24 — find it with - # `docker network inspect `). There is deliberately no - # default: if the proxy is not trusted, every client resolves to the proxy - # IP, so one user's failed logins lock out the whole firm and rate limits - # apply to everyone at once. IPs/CIDRs only, not hostnames. - - TRUSTED_PROXIES=${TRUSTED_PROXIES:?TRUSTED_PROXIES is required - set it to the reverse proxy's IP/CIDR (e.g. the Coolify/Traefik Docker network subnet), otherwise every client collapses to one IP and lockouts/rate limits hit the whole firm} - # Required to create the FIRST (admin) account: production refuses that - # registration unless it carries this token (openssl rand -hex 16). - - REGISTRATION_BOOTSTRAP_TOKEN=${REGISTRATION_BOOTSTRAP_TOKEN:?REGISTRATION_BOOTSTRAP_TOKEN is required (openssl rand -hex 16)} - # PostgreSQL TLS: "require" (default) for a database reached over a - # network; "internal" only for a Postgres on the same private Docker network. - - DB_SSL=${DB_SSL:-require} - # --- Optional --- - - FRONTEND_URL=${FRONTEND_URL:-} - - ALLOW_REGISTRATION=${ALLOW_REGISTRATION:-false} - - COURTLISTENER_API_TOKEN=${COURTLISTENER_API_TOKEN:-} - - SENDGRID_API_KEY=${SENDGRID_API_KEY:-} - # --- Providers (optional: without one, each user saves their own key) --- - - OPENAI_API_KEY=${OPENAI_API_KEY:-} - - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-} - - VOYAGE_API_KEY=${VOYAGE_API_KEY:-} - - VECTOR_DB=chroma - - CHROMA_PERSIST_DIR=/app/data/chroma - - UPLOAD_DIR=/app/data/uploads + DEBUG: "false" + ENVIRONMENT: production + VECTOR_DB: ${VECTOR_DB:-chroma} + CHROMA_PERSIST_DIR: /app/data/chroma + UPLOAD_DIR: /app/data/uploads + BACKUP_ENCRYPTION_KEY: "" volumes: - casecite_data:/app/data expose: - "80" healthcheck: - # Through nginx (:80) so a dead nginx or a dead uvicorn both show up. test: ["CMD", "curl", "-fsS", "http://localhost/health"] interval: 30s timeout: 10s retries: 3 - # Migrations and first-boot seeding run before uvicorn listens. start_period: 90s - restart: unless-stopped volumes: casecite_data: + driver: local diff --git a/frontend/package-lock.json b/frontend/package-lock.json index e0eb371..9ce2dfd 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,13 +1,13 @@ { "name": "casecite-frontend", - "version": "1.2.0", + "version": "1.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "casecite-frontend", - "version": "1.2.0", - "license": "Elastic-2.0", + "version": "1.3.0", + "license": "Apache-2.0", "dependencies": { "@azure/msal-browser": "^3.10.0", "@fontsource/inter": "^5.3.0", @@ -1941,7 +1941,7 @@ "version": "15.7.15", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz", "integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/@types/qrcode": { @@ -1958,7 +1958,7 @@ "version": "18.3.31", "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.31.tgz", "integrity": "sha512-vfEqpXTvwT91yhmwdfouStN2hSKwTvyRs8qpLfADyrq/kxDw0hZM7Wk9Ug1FELj8hIby+S/+kQCSRFF32nv2Qw==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "@types/prop-types": "*", @@ -3020,7 +3020,7 @@ "version": "3.2.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/data-urls": {