From 07d25956782b38f95cd801add0ce96b87c293db7 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 6 Aug 2026 19:04:06 +1200 Subject: [PATCH] changes --- README.md | 41 ++++++++++++++++--------- deploy/.env.example | 6 +++- deploy/docker-compose.yml | 64 ++++++++++++++++++++++++++++----------- 3 files changed, 78 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 45b06f6..35f1085 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,15 @@ the full list and a description of each. The two driver toggles: - **`DB_DRIVER`**: `postgres` (default) or `sqlite`. With `sqlite`, `DATABASE_URL` is a file path (e.g. `./data/vlog.db`) instead of a DSN, and the schema is applied idempotently on startup — no golang-migrate, no - external DB needed. Meant for local dev/testing; use Postgres in - production. + external DB needed. Good for local dev/testing, and just as fine for a + real single-server/personal-use deployment (see `deploy/docker-compose.yml`) + — use Postgres only if you actually need a separate DB server. - **`STORAGE_DRIVER`**: `s3` (default) or `local`. With `local`, uploads are written under `LOCAL_STORAGE_PATH` (default `./data/uploads`) instead of - S3 — no AWS credentials needed. Meant for local dev/testing; use S3 in - production. + S3 — no AWS credentials needed. Same story: fine for production too as + long as the volume backing `LOCAL_STORAGE_PATH` is actually durable (i.e. + a real disk/volume, not ephemeral container storage) — use S3 if you want + uploads off-box. Everything else (`OIDC_*`, `PUBLIC_BASE_URL`, `JWT_SIGNING_SECRET`) is required regardless — there's no toggle for OIDC, you'll need a real (or @@ -80,31 +83,41 @@ dev server side by side. ## Deploying +`deploy/docker-compose.yml` is wired for `DB_DRIVER=sqlite` + +`STORAGE_DRIVER=local` out of the box — config as literal env values right +in the file (no separate `.env`), matching the convention used for other +services on the host: one folder per service, `./data` bind-mounted in, +published on a `127.0.0.1` port for the host's own Caddy to reverse-proxy +to. Fill in the `OIDC_*`/`PUBLIC_BASE_URL`/`JWT_SIGNING_SECRET` placeholders +(still required either way — there's no toggle for OIDC), then: + ```sh cd deploy -cp .env.example .env # fill in real values (DB_DRIVER=postgres, STORAGE_DRIVER=s3) docker compose up -d --build ``` -This starts one container: `app` (the Go binary, built via +This starts one container: `vlog` (the Go binary, built via `backend/Dockerfile`, which builds the frontend and embeds it in the same -multi-stage build), published on `PORT` (default `8080`). Postgres, the -OIDC provider, and TLS termination are all assumed to already exist — -nothing else runs in this compose file. +multi-stage build), published on `127.0.0.1:4012` (pick any free port — +that's what your Caddy config points at). The OIDC provider and TLS +termination are assumed to already exist — nothing else runs in this +compose file. Point your existing Caddy config at it: ``` garage.example.com { - reverse_proxy localhost:8080 + reverse_proxy localhost:4012 } ``` -(Use the app container's name instead of `localhost` if your Caddy also -runs in Docker on the same network.) +To use Postgres + S3 instead, swap the relevant env values for the ones in +`deploy/.env.example` (a full reference list of every var the app reads). -The schema applies automatically on every `app` startup — there's no -separate migrate step to remember. +The schema applies automatically on every startup — there's no separate +migrate step to remember, and for SQLite specifically, adding a new column +to an existing local DB file is also handled automatically (no need to +delete and recreate it as the schema evolves). ## Verification checklist diff --git a/deploy/.env.example b/deploy/.env.example index ce2054d..285f151 100644 --- a/deploy/.env.example +++ b/deploy/.env.example @@ -1,4 +1,8 @@ -# Copy to deploy/.env and fill in — docker compose loads this automatically. +# Reference list of every env var the app reads — see docker-compose.yml for +# how they're actually wired in (literal values right in that file, matching +# this host's convention for other services, not a separate .env). Copy +# values from here into the `environment:` block there, or into a `.env` +# yourself if you'd rather use `${VAR}` substitution in the compose file. # --- Database --- # "postgres" (production, default) or "sqlite" (local dev/testing, no diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index b95f1ca..10ee673 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -1,26 +1,54 @@ +# Matches the house style used for other services on this host (gittea, +# etc.): one folder per service, config as literal env values right in this +# file (no separate .env), bind-mounted ./data, published on a 127.0.0.1 +# port for the host's own Caddy to reverse_proxy to. +# +# This example is wired for DB_DRIVER=sqlite + STORAGE_DRIVER=local — no +# Postgres or S3 needed, everything lives under ./data. Fine for production +# on a single-server/personal-use deployment like this one; swap to +# postgres/s3 by changing the env values below (see deploy/.env.example for +# the full var list either way). services: - app: + vlog: build: context: .. dockerfile: backend/Dockerfile + container_name: vlog restart: unless-stopped + + # Only needed if your OIDC provider runs on the host itself (or another + # compose stack not on this network) rather than a public domain — same + # reason gittea reaches Postgres via host.docker.internal. Safe to leave + # in even if unused. + extra_hosts: + - "host.docker.internal:host-gateway" + + # Pick any free host port — this is what your Caddy config points at. ports: - - "${PORT:-8080}:8080" - environment: - DB_DRIVER: ${DB_DRIVER:-postgres} - DATABASE_URL: ${DATABASE_URL} - PORT: "8080" - OIDC_ISSUER_URL: ${OIDC_ISSUER_URL} - OIDC_CLIENT_ID: ${OIDC_CLIENT_ID} - OIDC_CLIENT_SECRET: ${OIDC_CLIENT_SECRET} - OIDC_REDIRECT_URL: ${OIDC_REDIRECT_URL} - PUBLIC_BASE_URL: ${PUBLIC_BASE_URL} - JWT_SIGNING_SECRET: ${JWT_SIGNING_SECRET} - STORAGE_DRIVER: ${STORAGE_DRIVER:-s3} - LOCAL_STORAGE_PATH: ${LOCAL_STORAGE_PATH:-./data/uploads} - AWS_REGION: ${AWS_REGION} - AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} - AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY} - S3_BUCKET_NAME: ${S3_BUCKET_NAME} + - "127.0.0.1:4012:8080" + volumes: - ./data:/data + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + + environment: + - DB_DRIVER=sqlite + - DATABASE_URL=/data/vlog.db + - PORT=8080 + - STORAGE_DRIVER=local + - LOCAL_STORAGE_PATH=/data/uploads + + # Point at your existing OIDC provider (Authentik/Keycloak/Zitadel/etc). + # Register OIDC_REDIRECT_URL with it as this app's callback URL. + - OIDC_ISSUER_URL=https://auth.example.com/realms/your-realm + - OIDC_CLIENT_ID=vlog + - OIDC_CLIENT_SECRET=changeme + - OIDC_REDIRECT_URL=https://garage.example.com/api/auth/callback + + # Whatever your Caddy config serves this app as — controls whether + # session cookies are marked Secure (only over https://). + - PUBLIC_BASE_URL=https://garage.example.com + + # openssl rand -base64 32 + - JWT_SIGNING_SECRET=changeme