Update to fit stack
This commit is contained in:
+11
-15
@@ -1,26 +1,22 @@
|
||||
# --- Hostnames (point these at the Docker host, e.g. in your router/Pi-hole DNS) ---
|
||||
FINANCE_HOST=finance.home.lan
|
||||
AUTH_HOST=auth.home.lan
|
||||
# Spendr, ~/docker/spendr/.env (copy from .env.example)
|
||||
SPENDR_HOST=spendr.dv3.app
|
||||
TZ=Europe/Amsterdam
|
||||
|
||||
# --- Secrets: generate with openssl rand -base64 48 | tr -d '\n' ---
|
||||
AUTHENTIK_SECRET_KEY=change-me
|
||||
AUTHENTIK_DB_PASSWORD=change-me
|
||||
FINANCE_DB_PASSWORD=change-me
|
||||
# Password for Spendr's own Postgres database (only used between the two containers).
|
||||
# Generate one with: openssl rand -base64 32 | tr -d '\n/+='
|
||||
SPENDR_DB_PASSWORD=change-me
|
||||
|
||||
# --- Versions ---
|
||||
AUTHENTIK_TAG=2026.8.5
|
||||
TRAEFIK_TAG=v3.6
|
||||
# Optional: pin the DB volume name (e.g. when moving the stack to Komodo)
|
||||
# PG_VOLUME=spendr-db
|
||||
|
||||
# --- Enable Banking (optional automatic sync for ING + Revolut) ---
|
||||
# App ID from https://enablebanking.com/cp/applications ; put the private key at ./secrets/enablebanking.pem
|
||||
# --- Enable Banking (optional automatic ING + Revolut sync) ---
|
||||
# App ID from https://enablebanking.com/cp/applications ; private key goes in $SECRETS_DIR/enablebanking.pem
|
||||
EB_APP_ID=
|
||||
# Host folder with enablebanking.pem (default ./secrets next to compose.yaml)
|
||||
# SECRETS_DIR=/etc/komodo/secrets/spendr
|
||||
EB_SYNC_HOURS=6
|
||||
|
||||
# --- Prices ---
|
||||
# Optional free "Demo" key from CoinGecko for higher rate limits
|
||||
COINGECKO_API_KEY=
|
||||
PRICE_REFRESH_MINUTES=60
|
||||
|
||||
# Only if you enable the Let's Encrypt DNS challenge in traefik/traefik.yml
|
||||
CF_DNS_API_TOKEN=
|
||||
|
||||
+6
-4
@@ -1,6 +1,8 @@
|
||||
.env
|
||||
secrets/*.pem
|
||||
authentik/
|
||||
traefik/certs/*
|
||||
!traefik/certs/.gitkeep
|
||||
.env.*
|
||||
!.env.example
|
||||
secrets/*
|
||||
!secrets/.gitkeep
|
||||
__pycache__/
|
||||
*.db
|
||||
app/static/chart.umd.min.js
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# Finance: a self-hosted dashboard for ING, Revolut, investments, gold and debts
|
||||
# Spendr: a self-hosted dashboard for ING, Revolut, investments, gold and debts
|
||||
|
||||
```
|
||||
browser ──https──▶ Traefik ──forward-auth──▶ authentik (login, MFA)
|
||||
browser ──https──▶ Traefik (existing) ──authentik@docker──▶ Authentik (existing, auth.dv3.app)
|
||||
│
|
||||
└──▶ finance (FastAPI) ──▶ Postgres
|
||||
└──▶ spendr (FastAPI) ──▶ spendr-db (Postgres)
|
||||
│
|
||||
├─ Yahoo Finance (stocks/ETFs, gold spot, FX)
|
||||
├─ CoinGecko (crypto)
|
||||
@@ -23,30 +23,58 @@ browser ──https──▶ Traefik ──forward-auth──▶ authentik (logi
|
||||
| **Joint account** | Give the ING shared account a "your share %" (e.g. 50) and its spending is scaled in the totals. |
|
||||
| **Live numbers** | Every 30 s (and whenever you come back to the tab) the page fetches `/api/live`. Changed totals, prices and P/L count up or down and flash green or red, with no reload. *Refresh prices* runs in place. When new transactions arrive, a "new data · reload" hint appears so charts can be redrawn. |
|
||||
| **Dark mode** | Auto (follows the system), Light or Dark toggle in the sidebar, remembered per browser. |
|
||||
| **Mobile** | Desktop-first layout. On phones the sidebar turns into a scrolling top bar and tables scroll sideways. |
|
||||
| **Mobile** | Desktop-first layout. On phones there's a bottom tab bar and a slide-out menu, and tables scroll sideways. |
|
||||
|
||||
## Setup
|
||||
## Setup (DV3 server)
|
||||
|
||||
This stack uses the Traefik and Authentik you already run. It only adds two containers: `spendr` and `spendr-db`.
|
||||
|
||||
1. **DNS**: point `finance.home.lan` and `auth.home.lan` (or your own names) at the Docker host, e.g. in Pi-hole, AdGuard or your router.
|
||||
2. **Configure**
|
||||
```bash
|
||||
mkdir -p ~/docker/spendr && cd ~/docker/spendr
|
||||
# copy the contents of this folder here (compose.yaml, .env.example, app/, secrets/)
|
||||
cp .env.example .env
|
||||
# fill in hostnames + three secrets: openssl rand -base64 48 | tr -d '\n'
|
||||
mkdir -p authentik/data authentik/certs authentik/custom-templates secrets
|
||||
docker compose up -d --build
|
||||
nano .env # set SPENDR_DB_PASSWORD: openssl rand -base64 32 | tr -d '\n/+='
|
||||
sudo docker compose up -d --build
|
||||
```
|
||||
3. **authentik first run**: open `https://auth.home.lan/if/flow/initial-setup/` and create the admin user. Turn on TOTP or a passkey for it, because this app holds your bank data.
|
||||
4. **Protect the app in authentik** (Admin → Applications → *Create with provider*):
|
||||
- Provider type: **Proxy Provider** → **Forward auth (single application)**
|
||||
- External host: `https://finance.home.lan`
|
||||
- Then go to **Outposts → authentik Embedded Outpost → edit** and add the application.
|
||||
- Optional: bind a policy or group so only you (and your partner, if you like) can open it.
|
||||
5. Open `https://finance.home.lan`. You should be sent to the authentik login and then back to the app.
|
||||
|
||||
### TLS
|
||||
By default Traefik serves a self-signed certificate, so the browser shows a warning. You have two options:
|
||||
- **mkcert** (LAN only): `mkcert "*.home.lan"`, save the files as `traefik/certs/local.crt` / `local.key`, then uncomment `traefik/dynamic/tls.yml`.
|
||||
- **Let's Encrypt DNS challenge** (if you own a domain): uncomment the resolver in `traefik/traefik.yml` and set `CF_DNS_API_TOKEN` (or use another provider). This works even when the hosts are only reachable on your LAN.
|
||||
- **DNS / TLS**: `spendr.dv3.app` gets its certificate from the existing `letsencrypt` resolver, like your other services.
|
||||
- **Login**: the router uses `authentik@docker`. Your domain-level forward-auth provider (cookie domain `dv3.app`) protects it with no extra setup. Optional: create an Authentik application `spendr` and bind a policy or group if only certain users should get in.
|
||||
- **Why forward auth and not OIDC**: the app has no login of its own, so forward auth is the right fit (see your conventions).
|
||||
- **Sign out**: the sidebar button goes to `https://auth.dv3.app/outpost.goauthentik.io/sign_out` (set via `SIGN_OUT_URL` in `compose.yaml`).
|
||||
- **Komodo / Gitea**: see *Deploy with Gitea + Komodo* below (recommended).
|
||||
|
||||
## Deploy with Gitea + Komodo (GitOps)
|
||||
|
||||
Same flow as YoteInvest: push to Gitea, then Komodo redeploys.
|
||||
|
||||
1. **Gitea**: create an empty repo `Mitchell/Spendr` on git.dv3.app (no README), then from the unzipped folder:
|
||||
```bash
|
||||
cd spendr
|
||||
git init -b main && git add . && git commit -m "Spendr: initial version"
|
||||
git remote add origin https://git.dv3.app/Mitchell/Spendr.git
|
||||
git push -u origin main
|
||||
```
|
||||
`.gitignore` keeps `.env` and the Enable Banking key out of the repo.
|
||||
2. **Secrets folder on the NUC** (only needed for Enable Banking):
|
||||
```bash
|
||||
sudo mkdir -p /etc/komodo/secrets/spendr
|
||||
sudo cp enablebanking.pem /etc/komodo/secrets/spendr/ # later, once you have it
|
||||
```
|
||||
3. **Komodo → Stacks → New stack** `spendr`:
|
||||
- Source: **Git Repo** → provider `git.dv3.app`, repo `Mitchell/Spendr`, branch `main`. The file is `compose.yaml`, so no File Paths needed.
|
||||
- Turn on **Run Build** (the app image is built from `./app`), so a push also rebuilds the image.
|
||||
- **Environment** (secrets live here, not in the repo):
|
||||
```
|
||||
SPENDR_DB_PASSWORD=<openssl rand -base64 32 | tr -d '\n/+='>
|
||||
SECRETS_DIR=/etc/komodo/secrets/spendr
|
||||
PG_VOLUME=spendr-db
|
||||
EB_APP_ID=
|
||||
```
|
||||
- Deploy.
|
||||
4. **Auto-deploy on push**: copy the stack's webhook URL (`/listener/github/...`). In Gitea, open repo → Settings → Webhooks → *Gitea*, choose JSON, set the secret to `KOMODO_WEBHOOK_SECRET`, and paste the URL.
|
||||
5. Open `https://spendr.dv3.app`. Authentik asks you to log in, then you land on the dashboard.
|
||||
|
||||
`PG_VOLUME` pins the database volume name, so renaming or recreating the stack never orphans your data.
|
||||
|
||||
## Getting data in
|
||||
|
||||
@@ -57,19 +85,19 @@ By default Traefik serves a self-signed certificate, so the browser shows a warn
|
||||
First go to **Settings → Accounts** and add the IBANs of all three accounts (Revolut's too). Transfers between them are then recognised, and the shared account gets its share %.
|
||||
|
||||
**Automatic sync (Enable Banking, free for your own accounts):**
|
||||
1. Sign up at enablebanking.com → *Applications* → create one (Production). Set the redirect URL to `https://finance.home.lan/eb/callback`.
|
||||
1. Sign up at enablebanking.com → *Applications* → create one (Production). Set the redirect URL to `https://spendr.dv3.app/eb/callback`.
|
||||
2. Save the downloaded private key as `secrets/enablebanking.pem` and put the app id in `.env` → `EB_APP_ID`.
|
||||
3. In their control panel, use **Link accounts** for ING and Revolut. Free "restricted mode" only returns accounts you linked there.
|
||||
4. `docker compose up -d`, then go to Settings → *Connect* (ING / NL, then Revolut; Revolut may be listed under LT).
|
||||
4. `sudo docker compose up -d`, then go to Settings → *Connect* (ING / NL, then Revolut; Revolut may be listed under LT).
|
||||
5. The app syncs every `EB_SYNC_HOURS`. Bank consent (PSD2) expires after 90–180 days, so you'll need to click *Connect* again now and then. The expiry date is shown in Settings.
|
||||
|
||||
CSV and API imports share the same dedupe key (account + date + amount + n-th of that day), so you can mix them.
|
||||
|
||||
## Operations
|
||||
|
||||
- **Backup**: `docker compose exec finance-db pg_dump -U finance finance | gzip > finance-$(date +%F).sql.gz`. Back up `authentik-db` the same way.
|
||||
- **Logs**: `docker compose logs -f finance`
|
||||
- **Not exposed**: the app has no published port. It is only reachable through Traefik and authentik. Keep it that way.
|
||||
- **Backup**: `sudo docker compose exec spendr-db pg_dump -U spendr spendr | gzip > spendr-$(date +%F).sql.gz`. Never run `docker compose down -v`, because it deletes the database volume.
|
||||
- **Logs**: `sudo docker compose logs -f spendr`
|
||||
- **Not exposed**: the app has no published port. It is only reachable through Traefik and Authentik. Keep it that way.
|
||||
- Prices refresh every `PRICE_REFRESH_MINUTES`. Yahoo's endpoint is unofficial. If a ticker fails, the holding shows "price error" and you can set a manual price.
|
||||
- The schema is created on start (`create_all`). Add Alembic if you start changing models.
|
||||
|
||||
|
||||
+3
-2
@@ -70,7 +70,7 @@ async def lifespan(app: FastAPI):
|
||||
sched.shutdown(wait=False)
|
||||
|
||||
|
||||
app = FastAPI(title="Finance", lifespan=lifespan, docs_url=None, redoc_url=None)
|
||||
app = FastAPI(title="Spendr", lifespan=lifespan, docs_url=None, redoc_url=None)
|
||||
app.mount("/static", StaticFiles(directory=os.path.join(BASE_DIR, "static")), name="static")
|
||||
templates = Jinja2Templates(directory=os.path.join(BASE_DIR, "templates"))
|
||||
|
||||
@@ -100,7 +100,8 @@ def icon(name: str, cls: str = "") -> Markup:
|
||||
|
||||
|
||||
templates.env.filters.update(eur=eur, num=num, pct=pct)
|
||||
templates.env.globals.update(icon=icon)
|
||||
templates.env.globals.update(icon=icon, sign_out_url=os.getenv(
|
||||
"SIGN_OUT_URL", "https://auth.dv3.app/outpost.goauthentik.io/sign_out"))
|
||||
templates.env.globals.update(today=date.today, rec_state=rec_mod.state, monthly_eq=rec_mod.monthly_equivalent)
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<meta name="robots" content="noindex">
|
||||
<title>{% block title %}Finance{% endblock %} · Finance</title>
|
||||
<title>{% block title %}Finance{% endblock %} · Spendr</title>
|
||||
<script>try{var t=localStorage.getItem("theme");if(t==="dark"||t==="light")document.documentElement.dataset.theme=t;}catch(e){}</script>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
<script src="/static/chart.umd.min.js" defer></script>
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
<div class="layout">
|
||||
<nav class="side" aria-label="Main">
|
||||
<div class="brand"><span class="logo">{{ icon('wallet') }}</span> Finance</div>
|
||||
<div class="brand"><span class="logo">{{ icon('wallet') }}</span> Spendr</div>
|
||||
|
||||
<div class="nav-section">Overview</div>
|
||||
{{ navlink('/', 'layout-dashboard', 'Dashboard', path == '/') }}
|
||||
@@ -44,7 +44,7 @@
|
||||
<div class="user-chip">
|
||||
<span class="avatar">{{ (user or 'Me')[:1]|upper }}</span>
|
||||
<span class="who">{{ user or 'Signed in' }}</span>
|
||||
<a href="/outpost.goauthentik.io/sign_out" title="Sign out">{{ icon('log-out', 'sm') }}</a>
|
||||
<a href="{{ sign_out_url }}" title="Sign out">{{ icon('log-out', 'sm') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -53,7 +53,7 @@
|
||||
<div style="min-width:0">
|
||||
<header class="topbar">
|
||||
<button class="icon-btn" data-nav-toggle aria-label="Menu">{{ icon('menu') }}</button>
|
||||
<div class="brand"><span class="logo">{{ icon('wallet', 'sm') }}</span> Finance</div>
|
||||
<div class="brand"><span class="logo">{{ icon('wallet', 'sm') }}</span> Spendr</div>
|
||||
</header>
|
||||
<main>
|
||||
{% if msg %}<div class="flash">{{ icon('circle-alert') }}<span>{{ msg }}</span></div>{% endif %}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# Spendr: personal finance dashboard. ~/docker/spendr/compose.yaml
|
||||
# Uses the existing Traefik (external network "proxy") and Authentik forward auth at auth.dv3.app.
|
||||
|
||||
services:
|
||||
spendr:
|
||||
build: ./app
|
||||
container_name: spendr
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
DATABASE_URL: postgresql+psycopg://spendr:${SPENDR_DB_PASSWORD:?set SPENDR_DB_PASSWORD in .env}@spendr-db:5432/spendr
|
||||
TZ: ${TZ:-Europe/Amsterdam}
|
||||
PUBLIC_URL: https://${SPENDR_HOST:-spendr.dv3.app}
|
||||
SIGN_OUT_URL: https://auth.dv3.app/outpost.goauthentik.io/sign_out
|
||||
# Enable Banking (optional automatic ING/Revolut sync, see README)
|
||||
EB_APP_ID: ${EB_APP_ID:-}
|
||||
EB_KEY_PATH: /run/secrets/enablebanking.pem
|
||||
EB_SYNC_HOURS: ${EB_SYNC_HOURS:-6}
|
||||
# Prices
|
||||
COINGECKO_API_KEY: ${COINGECKO_API_KEY:-}
|
||||
PRICE_REFRESH_MINUTES: ${PRICE_REFRESH_MINUTES:-60}
|
||||
volumes:
|
||||
# Folder (not a single file) holding enablebanking.pem. With Komodo, point this at a host folder
|
||||
# outside the cloned repo, e.g. SECRETS_DIR=/etc/komodo/secrets/spendr
|
||||
- ${SECRETS_DIR:-./secrets}:/run/secrets:ro
|
||||
depends_on:
|
||||
spendr-db:
|
||||
condition: service_healthy
|
||||
networks: [proxy, internal]
|
||||
labels:
|
||||
traefik.enable: "true"
|
||||
traefik.docker.network: proxy
|
||||
traefik.http.routers.spendr.rule: Host(`${SPENDR_HOST:-spendr.dv3.app}`)
|
||||
traefik.http.routers.spendr.entrypoints: websecure
|
||||
traefik.http.routers.spendr.tls.certresolver: letsencrypt
|
||||
traefik.http.routers.spendr.middlewares: secure-headers@docker,authentik@docker
|
||||
traefik.http.services.spendr.loadbalancer.server.port: "8000"
|
||||
|
||||
spendr-db:
|
||||
image: postgres:16-alpine
|
||||
container_name: spendr-db
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_USER: spendr
|
||||
POSTGRES_DB: spendr
|
||||
POSTGRES_PASSWORD: ${SPENDR_DB_PASSWORD}
|
||||
volumes:
|
||||
- spendr-db:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -d spendr -U spendr"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
networks: [internal]
|
||||
|
||||
networks:
|
||||
proxy:
|
||||
external: true
|
||||
internal:
|
||||
|
||||
volumes:
|
||||
spendr-db:
|
||||
name: ${PG_VOLUME:-spendr-db}
|
||||
@@ -1,22 +0,0 @@
|
||||
http:
|
||||
middlewares:
|
||||
# Forward every request to authentik's embedded outpost; unauthenticated users get redirected to login.
|
||||
authentik:
|
||||
forwardAuth:
|
||||
address: http://authentik-server:9000/outpost.goauthentik.io/auth/traefik
|
||||
trustForwardHeader: true
|
||||
authResponseHeaders:
|
||||
- X-authentik-username
|
||||
- X-authentik-groups
|
||||
- X-authentik-email
|
||||
- X-authentik-name
|
||||
- X-authentik-uid
|
||||
|
||||
secure-headers:
|
||||
headers:
|
||||
frameDeny: true
|
||||
contentTypeNosniff: true
|
||||
referrerPolicy: same-origin
|
||||
stsSeconds: 31536000
|
||||
customResponseHeaders:
|
||||
X-Robots-Tag: "noindex, nofollow"
|
||||
@@ -1,10 +0,0 @@
|
||||
# Optional: use your own certificate (e.g. made with mkcert for *.home.lan).
|
||||
# Put the files in ./traefik/certs and uncomment. Without this (and without Let's Encrypt)
|
||||
# Traefik serves its built-in self-signed certificate.
|
||||
#
|
||||
# tls:
|
||||
# stores:
|
||||
# default:
|
||||
# defaultCertificate:
|
||||
# certFile: /certs/local.crt
|
||||
# keyFile: /certs/local.key
|
||||
@@ -1,43 +0,0 @@
|
||||
# Traefik static configuration
|
||||
api:
|
||||
dashboard: false
|
||||
|
||||
log:
|
||||
level: INFO
|
||||
|
||||
entryPoints:
|
||||
web:
|
||||
address: ":80"
|
||||
http:
|
||||
redirections:
|
||||
entryPoint:
|
||||
to: websecure
|
||||
scheme: https
|
||||
websecure:
|
||||
address: ":443"
|
||||
http:
|
||||
tls: {}
|
||||
# Uncomment to get real certificates via Let's Encrypt DNS challenge
|
||||
# (works for LAN-only hosts as long as you own the domain):
|
||||
# tls:
|
||||
# certResolver: letsencrypt
|
||||
# domains:
|
||||
# - main: "example.com"
|
||||
# sans: ["*.example.com"]
|
||||
|
||||
providers:
|
||||
docker:
|
||||
exposedByDefault: false
|
||||
network: finance_proxy
|
||||
file:
|
||||
directory: /etc/traefik/dynamic
|
||||
watch: true
|
||||
|
||||
# certificatesResolvers:
|
||||
# letsencrypt:
|
||||
# acme:
|
||||
# email: you@example.com
|
||||
# storage: /acme/acme.json
|
||||
# dnsChallenge:
|
||||
# provider: cloudflare # set CF_DNS_API_TOKEN in .env (or use another provider)
|
||||
# resolvers: ["1.1.1.1:53"]
|
||||
Reference in New Issue
Block a user