From f5d89cee2fce589d7bae2dea29a34967d3d22e43d60508b214d82e413b1734a1 Mon Sep 17 00:00:00 2001 From: Hadrian Burkhardt Date: Fri, 1 May 2026 01:47:55 +0000 Subject: [PATCH] docker compose --- .env.local.example | 2 ++ .gitignore | 1 + Caddyfile | 3 ++ compose.local.yml | 29 +++++++++++++++++ docs/fritzbox-hosting.md | 67 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 .env.local.example create mode 100644 Caddyfile create mode 100644 compose.local.yml create mode 100644 docs/fritzbox-hosting.md diff --git a/.env.local.example b/.env.local.example new file mode 100644 index 0000000..1ae21e0 --- /dev/null +++ b/.env.local.example @@ -0,0 +1,2 @@ +PUBLIC_HOST=menus.example.org +BASE_URL=https://menus.example.org diff --git a/.gitignore b/.gitignore index b2a5dae..bdfb0f8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ __pycache__ .devcontainer .vscode .codex +.env.local diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..aef5e0f --- /dev/null +++ b/Caddyfile @@ -0,0 +1,3 @@ +{$PUBLIC_HOST} { + reverse_proxy app:3080 +} diff --git a/compose.local.yml b/compose.local.yml new file mode 100644 index 0000000..a59044f --- /dev/null +++ b/compose.local.yml @@ -0,0 +1,29 @@ +services: + app: + build: . + restart: unless-stopped + environment: + BASE_URL: ${BASE_URL} + LISTEN_PORT: 3080 + expose: + - "3080" + + caddy: + image: caddy:2-alpine + restart: unless-stopped + depends_on: + - app + ports: + - "80:80" + - "443:443" + - "443:443/udp" + environment: + PUBLIC_HOST: ${PUBLIC_HOST} + volumes: + - ./Caddyfile:/etc/caddy/Caddyfile:ro + - caddy_data:/data + - caddy_config:/config + +volumes: + caddy_data: + caddy_config: diff --git a/docs/fritzbox-hosting.md b/docs/fritzbox-hosting.md new file mode 100644 index 0000000..c619312 --- /dev/null +++ b/docs/fritzbox-hosting.md @@ -0,0 +1,67 @@ +FritzBox Self-Hosting +===================== + +This setup runs the parser behind Caddy. Caddy receives public HTTP/HTTPS +traffic, obtains TLS certificates, and proxies requests to the app container. + +Requirements +------------ + +* A machine on your home network with Docker and Docker Compose. +* A DNS name that points to your home connection. +* FritzBox port sharing from the internet to the Docker host: + + * TCP 80 -> Docker host TCP 80 + * TCP 443 -> Docker host TCP 443 + * UDP 443 -> Docker host UDP 443 + +If your internet provider uses CGNAT and you do not have a reachable public IP, +plain FritzBox port forwarding will not work. Use IPv6 with an AAAA record, a +provider option for public IPv4, or a tunnel/VPN. + +Configure +--------- + +Create a local environment file: + +.. code-block:: shell + + cp .env.local.example .env.local + +Edit ``.env.local``: + +.. code-block:: dotenv + + PUBLIC_HOST=menus.example.org + BASE_URL=https://menus.example.org + +``PUBLIC_HOST`` is the domain Caddy serves. ``BASE_URL`` is used by the Flask +app when it generates absolute OpenMensa feed URLs. + +Run +--- + +Start or update the local deployment: + +.. code-block:: shell + + docker compose --env-file .env.local -f compose.local.yml up -d --build + +Check logs: + +.. code-block:: shell + + docker compose --env-file .env.local -f compose.local.yml logs -f + +Check health locally: + +.. code-block:: shell + + curl http://127.0.0.1/health_check + +Stop +---- + +.. code-block:: shell + + docker compose --env-file .env.local -f compose.local.yml down