Run the activity tracker as its own published image at /tracker/
Test and deploy / test (push) Successful in 2m0s
Test and deploy / deploy (push) Successful in 1m29s

Same shape as jobs: adam-french.co.uk/adamf/activity-tracker, published by
the adamf/ccp repo's CI, with an explicit environment list and its own
database role. nginx strips the /tracker prefix. The env test now covers
the new service's allow-list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-14 20:39:05 +01:00
co-authored by Claude Opus 5.5
parent e788e16898
commit d28524e8c0
6 changed files with 74 additions and 8 deletions
+17 -5
View File
@@ -37,11 +37,12 @@
# ============================================================================= # =============================================================================
# --- Postgres ---------------------------------------------------------------- # --- Postgres ----------------------------------------------------------------
# One instance, three databases: POSTGRES_DB for the Go backend, # One instance, four databases: POSTGRES_DB for the Go backend,
# POSTGRES_GITEA_DB for Gitea, POSTGRES_JOBS_DB for the job tracker (with its # POSTGRES_GITEA_DB for Gitea, POSTGRES_JOBS_DB for the job tracker and
# own role). Only POSTGRES_DB is auto-created on first init; the other two must # POSTGRES_TRACKER_DB for the activity tracker (each of the last two with its
# be created by hand on a fresh volume (the job tracker's README has the # own role). Only POSTGRES_DB is auto-created on first init; the others must
# commands). # be created by hand on a fresh volume (the job-tracker and ccp READMEs have
# the commands).
# POSTGRES_HOST doubles as the db container's name. # POSTGRES_HOST doubles as the db container's name.
POSTGRES_USER= POSTGRES_USER=
POSTGRES_PASSWORD= POSTGRES_PASSWORD=
@@ -51,6 +52,9 @@ POSTGRES_HOST=db
POSTGRES_JOBS_DB=jobs POSTGRES_JOBS_DB=jobs
POSTGRES_JOBS_USER=jobs POSTGRES_JOBS_USER=jobs
POSTGRES_JOBS_PASSWORD= POSTGRES_JOBS_PASSWORD=
POSTGRES_TRACKER_DB=tracker
POSTGRES_TRACKER_USER=tracker
POSTGRES_TRACKER_PASSWORD=
# --- Gitea ------------------------------------------------------------------- # --- Gitea -------------------------------------------------------------------
# GITEA_HOST is the container name AND the nginx upstream host. # GITEA_HOST is the container name AND the nginx upstream host.
@@ -213,5 +217,13 @@ PYTHON_PORT=8000
# `docker compose pull jobs && docker compose up -d jobs`. # `docker compose pull jobs && docker compose up -d jobs`.
JOBS_IMAGE_TAG= JOBS_IMAGE_TAG=
# --- Activity tracker (/tracker/) --------------------------------------------
# An image built and published by the ccp repo's CI. Blank runs :latest; set a
# commit sha to pin. Changing it needs
# `docker compose pull activity-tracker && docker compose up -d activity-tracker`.
ACTIVITY_TRACKER_IMAGE_TAG=
# IANA timezone that decides where a "day" starts in daily summaries. Blank is UTC.
TRACKER_TZ=Europe/London
# TfL Unified API key (500 req/min); used by the Python hotel finder # TfL Unified API key (500 req/min); used by the Python hotel finder
TFL_APP_KEY= TFL_APP_KEY=
+1
View File
@@ -57,6 +57,7 @@ backend icecast2 gitea sb sb-pub python | |
| silverbullet-git | n/a | n/a | none (timer loop) | no | | silverbullet-git | n/a | n/a | none (timer loop) | no |
| python (FastAPI) | `${PYTHON_HOST}` | `${PYTHON_PORT}` | `/py/`, docs at `/py/docs` | no | | python (FastAPI) | `${PYTHON_HOST}` | `${PYTHON_PORT}` | `/py/`, docs at `/py/docs` | no |
| jobs (job tracker, published image) | `jobs` | 8080 | `/jobs/` (admin-gated by the app itself) | no | | jobs (job tracker, published image) | `jobs` | 8080 | `/jobs/` (admin-gated by the app itself) | no |
| activity-tracker (published image, adamf/ccp) | `activity-tracker` | 8080 | `/tracker/`, prefix stripped (per-device bearer keys) | no |
| icecast2 + liquidsoap | `${ICECAST_HOST}` | `${ICECAST_PORT}` | `/radio/` | **harbor port only** | | icecast2 + liquidsoap | `${ICECAST_HOST}` | `${ICECAST_PORT}` | `/radio/` | **harbor port only** |
| gitea | `${GITEA_HOST}` | 3000, 2222 | `/gitea/` | **3000, 2222** | | gitea | `${GITEA_HOST}` | 3000, 2222 | `/gitea/` | **3000, 2222** |
| vue | `vue` | 5173 (dev only) | `/` (dev only) | no | | vue | `vue` | 5173 (dev only) | `/` (dev only) | no |
+3 -3
View File
@@ -110,12 +110,12 @@ func composeServiceEnv(t *testing.T, service string) []string {
// explicitEnvServices are the containers given an explicit `environment:` // explicitEnvServices are the containers given an explicit `environment:`
// list instead of the whole .env, so that they never hold the database // list instead of the whole .env, so that they never hold the database
// password or the JWT secret: the Python service, and the job tracker (an // password or the JWT secret: the Python service, and the job and activity
// image from its own repo, which gets its own database role besides). The // trackers (images from their own repos, each with its own database role). The
// cost is a third place a new variable for one of them has to be added — the // cost is a third place a new variable for one of them has to be added — the
// registry, .env.example and that list — and forgetting the third is silent: // registry, .env.example and that list — and forgetting the third is silent:
// the variable is simply empty inside the container. // the variable is simply empty inside the container.
var explicitEnvServices = []string{"python", "jobs"} var explicitEnvServices = []string{"python", "jobs", "activity-tracker"}
// So the registry's claim "this service reads this" and the compose list must // So the registry's claim "this service reads this" and the compose list must
// agree, in both directions: // agree, in both directions:
+5
View File
@@ -45,6 +45,7 @@
{"name": "BACKEND_ENDPOINT", "group": "Infrastructure", "purpose": "URL prefix nginx mounts the API at", "kind": "text", "editable": false, "lockedReason": "The Vue app assumes /api."}, {"name": "BACKEND_ENDPOINT", "group": "Infrastructure", "purpose": "URL prefix nginx mounts the API at", "kind": "text", "editable": false, "lockedReason": "The Vue app assumes /api."},
{"name": "PYTHON_HOST", "group": "Infrastructure", "purpose": "Python container name and nginx upstream", "kind": "text", "editable": false, "lockedReason": "Renames a container and repoints nginx."}, {"name": "PYTHON_HOST", "group": "Infrastructure", "purpose": "Python container name and nginx upstream", "kind": "text", "editable": false, "lockedReason": "Renames a container and repoints nginx."},
{"name": "PYTHON_PORT", "group": "Infrastructure", "purpose": "Python listen port", "kind": "text", "editable": false, "lockedReason": "Renames a container or repoints nginx."}, {"name": "PYTHON_PORT", "group": "Infrastructure", "purpose": "Python listen port", "kind": "text", "editable": false, "lockedReason": "Renames a container or repoints nginx."},
{"name": "ACTIVITY_TRACKER_IMAGE_TAG", "group": "Infrastructure", "purpose": "Activity tracker image tag to run (default latest)", "kind": "text", "editable": false, "lockedReason": "Changing it needs a pull: docker compose pull activity-tracker && docker compose up -d activity-tracker."},
{"name": "JOBS_IMAGE_TAG", "group": "Infrastructure", "purpose": "Job tracker image tag to run (default latest)", "kind": "text", "editable": false, "lockedReason": "Changing it needs a pull: docker compose pull jobs && docker compose up -d jobs."}, {"name": "JOBS_IMAGE_TAG", "group": "Infrastructure", "purpose": "Job tracker image tag to run (default latest)", "kind": "text", "editable": false, "lockedReason": "Changing it needs a pull: docker compose pull jobs && docker compose up -d jobs."},
{"name": "ICECAST_HOST", "group": "Infrastructure", "purpose": "Icecast container name and nginx upstream", "kind": "text", "editable": false, "lockedReason": "Renames a container and repoints nginx."}, {"name": "ICECAST_HOST", "group": "Infrastructure", "purpose": "Icecast container name and nginx upstream", "kind": "text", "editable": false, "lockedReason": "Renames a container and repoints nginx."},
{"name": "ICECAST_PORT", "group": "Infrastructure", "purpose": "Icecast listen port", "kind": "text", "editable": false, "lockedReason": "Renames a container or repoints nginx."}, {"name": "ICECAST_PORT", "group": "Infrastructure", "purpose": "Icecast listen port", "kind": "text", "editable": false, "lockedReason": "Renames a container or repoints nginx."},
@@ -65,6 +66,10 @@
{"name": "POSTGRES_JOBS_DB", "group": "Database", "purpose": "Job tracker database name", "kind": "text", "editable": false, "lockedReason": "Created by hand on first install; see the job-tracker README."}, {"name": "POSTGRES_JOBS_DB", "group": "Database", "purpose": "Job tracker database name", "kind": "text", "editable": false, "lockedReason": "Created by hand on first install; see the job-tracker README."},
{"name": "POSTGRES_JOBS_USER", "group": "Database", "purpose": "Job tracker database role", "kind": "text", "editable": false, "lockedReason": "Created by hand on first install; changing it here locks the tracker out."}, {"name": "POSTGRES_JOBS_USER", "group": "Database", "purpose": "Job tracker database role", "kind": "text", "editable": false, "lockedReason": "Created by hand on first install; changing it here locks the tracker out."},
{"name": "POSTGRES_JOBS_PASSWORD", "group": "Database", "purpose": "Job tracker database password", "kind": "secret", "editable": false, "lockedReason": "Set on the role by hand; changing it here locks the tracker out."}, {"name": "POSTGRES_JOBS_PASSWORD", "group": "Database", "purpose": "Job tracker database password", "kind": "secret", "editable": false, "lockedReason": "Set on the role by hand; changing it here locks the tracker out."},
{"name": "POSTGRES_TRACKER_DB", "group": "Database", "purpose": "Activity tracker database name", "kind": "text", "editable": false, "lockedReason": "Created by hand on first install; see the ccp README."},
{"name": "POSTGRES_TRACKER_USER", "group": "Database", "purpose": "Activity tracker database role", "kind": "text", "editable": false, "lockedReason": "Created by hand on first install; changing it here locks the activity tracker out."},
{"name": "POSTGRES_TRACKER_PASSWORD", "group": "Database", "purpose": "Activity tracker database password", "kind": "secret", "editable": false, "lockedReason": "Set on the role by hand; changing it here locks the activity tracker out."},
{"name": "TRACKER_TZ", "group": "Activity tracker", "purpose": "Timezone where the activity tracker's day starts, e.g. Europe/London (blank is UTC)", "kind": "text", "editable": true, "services": ["activity-tracker"]},
{"name": "GITEA_HOST", "group": "Gitea", "purpose": "Gitea container name and nginx upstream", "kind": "text", "editable": false, "lockedReason": "Renames a container and repoints nginx."}, {"name": "GITEA_HOST", "group": "Gitea", "purpose": "Gitea container name and nginx upstream", "kind": "text", "editable": false, "lockedReason": "Renames a container and repoints nginx."},
{"name": "GITEA_PORT", "group": "Gitea", "purpose": "Gitea HTTP port", "kind": "text", "editable": false, "lockedReason": "Renames a container or repoints nginx."}, {"name": "GITEA_PORT", "group": "Gitea", "purpose": "Gitea HTTP port", "kind": "text", "editable": false, "lockedReason": "Renames a container or repoints nginx."},
+24
View File
@@ -115,6 +115,7 @@ services:
- silverbullet-public - silverbullet-public
- python - python
- jobs - jobs
- activity-tracker
networks: networks:
- app-network - app-network
ports: ports:
@@ -473,6 +474,29 @@ services:
volumes: volumes:
- ./jobs-data:/data - ./jobs-data:/data
# The activity tracker (time spent per app, site, walk...), served at
# /tracker/ with the prefix stripped. Built and published by its own repo
# (adamf/ccp on this Gitea), whose CI pulls :latest into this service on
# every push to main; pin ACTIVITY_TRACKER_IMAGE_TAG to hold a version.
#
# Same shape as jobs: an explicit `environment:` list and a database role of
# its own, created by hand once (the ccp README has the command). It applies
# its own migrations on start. Collectors authenticate with per-device
# bearer keys made by `docker exec activity-tracker tracker apikey create`;
# nothing here touches the site's login. No state outside Postgres.
activity-tracker:
image: adam-french.co.uk/adamf/activity-tracker:${ACTIVITY_TRACKER_IMAGE_TAG:-latest}
container_name: activity-tracker
restart: always
depends_on:
db:
condition: service_healthy
networks:
- app-network
environment:
- DATABASE_URL=postgres://${POSTGRES_TRACKER_USER:-tracker}:${POSTGRES_TRACKER_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_TRACKER_DB:-tracker}?sslmode=disable
- TRACKER_TZ=${TRACKER_TZ:-}
# Self-hosted git, served at /gitea/ and on port 3000 directly. Also the CI # Self-hosted git, served at /gitea/ and on port 3000 directly. Also the CI
# server: .gitea/workflows/deploy.yaml redeploys this whole stack on push to # server: .gitea/workflows/deploy.yaml redeploys this whole stack on push to
# main, executed by the act_runner that lives outside docker (gitea-runner/). # main, executed by the act_runner that lives outside docker (gitea-runner/).
+24
View File
@@ -77,6 +77,8 @@
# The job tracker's container name is fixed in docker-compose.yml, so # The job tracker's container name is fixed in docker-compose.yml, so
# it needs no variable (and no ENVSUBST_VARS entry). # it needs no variable (and no ENVSUBST_VARS entry).
set $upstream_jobs http://jobs:8080; set $upstream_jobs http://jobs:8080;
# Likewise the activity tracker's.
set $upstream_tracker http://activity-tracker:8080;
# ---- Backend API ----------------------------------------------------- # ---- Backend API -----------------------------------------------------
# Two patterns repeat through every proxied location below: # Two patterns repeat through every proxied location below:
@@ -363,6 +365,28 @@
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
# ---- Activity tracker (/tracker/) ----
# Its own container (the adamf/ccp repo): an ingest API for device
# collectors, which send batches of events with a per-device bearer
# key. The app does its own auth, so no auth_request. Unlike /jobs/
# the prefix IS stripped: the server serves /api/v1/... and /readyz
# from /. Collectors must use the www host: the apex 301 would turn
# their POSTs into GETs. Health Auto Export bodies can be several MB;
# the server-wide 50M client_max_body_size covers them.
location = /tracker {
return 301 /tracker/;
}
location ^~ /tracker/ {
limit_req zone=api burst=20 nodelay;
rewrite ^/tracker/(.*)$ /$1 break;
proxy_pass $upstream_tracker;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Where the tracker used to be. The SPA routes were client-side, so # Where the tracker used to be. The SPA routes were client-side, so
# these only catch bookmarks and typed URLs. The userscript's old # these only catch bookmarks and typed URLs. The userscript's old
# @updateURL lands on the third, which is how installed copies find # @updateURL lands on the third, which is how installed copies find