Add the usaco service and its /usaco/ route
The USACO practice log from the usaco repo's site/: one container, git as its store (a clone in ./usaco-data), behind nginx with the prefix kept, like /jobs/. Gitea may now deliver webhooks to it by name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -217,6 +217,19 @@ 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=
|
||||||
|
|
||||||
|
# --- USACO site (/usaco/) ------------------------------------------------------
|
||||||
|
# An image built and published by the usaco repo's CI. Blank runs :latest; set
|
||||||
|
# a commit sha to pin. Changing it needs
|
||||||
|
# `docker compose pull usaco && docker compose up -d usaco`.
|
||||||
|
USACO_IMAGE_TAG=
|
||||||
|
# Gitea access token (repository: read and write on adamf/usaco). The site
|
||||||
|
# clones with it and pushes the admin's edits back.
|
||||||
|
USACO_GIT_TOKEN=
|
||||||
|
# Shared secret of the usaco repo's push webhook in Gitea
|
||||||
|
# (http://usaco:8080/usaco/api/hooks/gitea). Blank turns the hook off and
|
||||||
|
# the site only pulls every 10 minutes. Generate with `openssl rand -hex 32`.
|
||||||
|
USACO_WEBHOOK_SECRET=
|
||||||
|
|
||||||
# --- Activity tracker (/tracker/) --------------------------------------------
|
# --- Activity tracker (/tracker/) --------------------------------------------
|
||||||
# An image built and published by the ccp repo's CI. Blank runs :latest; set a
|
# An image built and published by the ccp repo's CI. Blank runs :latest; set a
|
||||||
# commit sha to pin. Changing it needs
|
# commit sha to pin. Changing it needs
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ certbot/conf
|
|||||||
certbot/www
|
certbot/www
|
||||||
backend/token/
|
backend/token/
|
||||||
jobs-data/
|
jobs-data/
|
||||||
|
usaco-data/
|
||||||
.env
|
.env
|
||||||
.env.bak
|
.env.bak
|
||||||
|
|
||||||
|
|||||||
@@ -110,12 +110,13 @@ 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 and activity
|
// password or the JWT secret: the Python service, the job and activity
|
||||||
// trackers (images from their own repos, each with its own database role). The
|
// trackers (images from their own repos, each with its own database role) and
|
||||||
|
// the USACO site (an image from its own repo, with no database at all). 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", "activity-tracker"}
|
var explicitEnvServices = []string{"python", "jobs", "activity-tracker", "usaco"}
|
||||||
|
|
||||||
// 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:
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
{"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": "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": "USACO_IMAGE_TAG", "group": "Infrastructure", "purpose": "USACO site image tag to run (default latest)", "kind": "text", "editable": false, "lockedReason": "Changing it needs a pull: docker compose pull usaco && docker compose up -d usaco."},
|
||||||
{"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."},
|
||||||
@@ -69,6 +70,8 @@
|
|||||||
{"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_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_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": "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": "USACO_GIT_TOKEN", "group": "USACO site", "purpose": "Gitea token (repository read and write on adamf/usaco) the site clones and pushes edits with", "kind": "secret", "editable": false, "lockedReason": "Made in Gitea (Settings, Applications); rotate it there, then set it here and run docker compose up -d usaco.", "docsUrl": "https://adam-french.co.uk/gitea/user/settings/applications"},
|
||||||
|
{"name": "USACO_WEBHOOK_SECRET", "group": "USACO site", "purpose": "Shared secret of the usaco repo's Gitea push webhook", "kind": "secret", "editable": false, "lockedReason": "Must match the secret on the webhook in Gitea; change both together by hand."},
|
||||||
{"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": "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."},
|
||||||
|
|||||||
@@ -474,6 +474,37 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./jobs-data:/data
|
- ./jobs-data:/data
|
||||||
|
|
||||||
|
# The USACO practice log, served at /usaco/. Built and published by the
|
||||||
|
# usaco repo's CI (adamf/usaco on this Gitea; the server is in its site/
|
||||||
|
# directory), which pulls :latest into this service on every push to main
|
||||||
|
# that touches the site. Pin USACO_IMAGE_TAG to hold a version.
|
||||||
|
#
|
||||||
|
# It has no database: git is its store. It keeps a clone of adamf/usaco in
|
||||||
|
# ./usaco-data, pulled over the Docker network when Gitea's push webhook
|
||||||
|
# fires (USACO_WEBHOOK_SECRET signs it), and commits the admin's edits
|
||||||
|
# (status, link, notes) back with USACO_GIT_TOKEN. ./usaco-data holds only
|
||||||
|
# that clone, so deleting it is safe; the image runs as uid 1000, so the
|
||||||
|
# directory must be owned by it.
|
||||||
|
#
|
||||||
|
# Same explicit `environment:` list as jobs. Like the tracker it has no
|
||||||
|
# login: visitors see solved problems, and AUTH_VALIDATE_URL decides who
|
||||||
|
# is the admin from the visitor's cookies.
|
||||||
|
usaco:
|
||||||
|
image: adam-french.co.uk/adamf/usaco:${USACO_IMAGE_TAG:-latest}
|
||||||
|
container_name: usaco
|
||||||
|
restart: always
|
||||||
|
depends_on:
|
||||||
|
- gitea
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
environment:
|
||||||
|
- GIT_REMOTE_URL=http://${GITEA_HOST}:${GITEA_PORT}/adamf/usaco.git
|
||||||
|
- GIT_TOKEN=${USACO_GIT_TOKEN:-}
|
||||||
|
- WEBHOOK_SECRET=${USACO_WEBHOOK_SECRET:-}
|
||||||
|
- AUTH_VALIDATE_URL=http://${BACKEND_HOST}:${BACKEND_PORT}/auth/validate-admin
|
||||||
|
volumes:
|
||||||
|
- ./usaco-data:/data
|
||||||
|
|
||||||
# The activity tracker (time spent per app, site, walk...), served at
|
# The activity tracker (time spent per app, site, walk...), served at
|
||||||
# /tracker/ with the prefix stripped. Built and published by its own repo
|
# /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
|
# (adamf/ccp on this Gitea), whose CI pulls :latest into this service on
|
||||||
@@ -534,6 +565,10 @@ services:
|
|||||||
- GITEA__server__LFS_JWT_SECRET=${GITEA_LFS_JWT_SECRET}
|
- GITEA__server__LFS_JWT_SECRET=${GITEA_LFS_JWT_SECRET}
|
||||||
- GITEA__security__INTERNAL_TOKEN=${GITEA_INTERNAL_TOKEN}
|
- GITEA__security__INTERNAL_TOKEN=${GITEA_INTERNAL_TOKEN}
|
||||||
- GITEA__oauth2__JWT_SECRET=${GITEA_OAUTH2_JWT_SECRET}
|
- GITEA__oauth2__JWT_SECRET=${GITEA_OAUTH2_JWT_SECRET}
|
||||||
|
# Webhooks are refused to private addresses by default ("external").
|
||||||
|
# The usaco site's push hook targets http://usaco:8080 on the Docker
|
||||||
|
# network, so that one host is allowed by name.
|
||||||
|
- GITEA__webhook__ALLOWED_HOST_LIST=external,usaco
|
||||||
- USER_UID=1000
|
- USER_UID=1000
|
||||||
- USER_GID=1000
|
- USER_GID=1000
|
||||||
restart: always
|
restart: always
|
||||||
|
|||||||
@@ -79,6 +79,8 @@
|
|||||||
set $upstream_jobs http://jobs:8080;
|
set $upstream_jobs http://jobs:8080;
|
||||||
# Likewise the activity tracker's.
|
# Likewise the activity tracker's.
|
||||||
set $upstream_tracker http://activity-tracker:8080;
|
set $upstream_tracker http://activity-tracker:8080;
|
||||||
|
# And the USACO site's.
|
||||||
|
set $upstream_usaco http://usaco:8080;
|
||||||
|
|
||||||
# ---- Backend API -----------------------------------------------------
|
# ---- Backend API -----------------------------------------------------
|
||||||
# Two patterns repeat through every proxied location below:
|
# Two patterns repeat through every proxied location below:
|
||||||
@@ -365,6 +367,28 @@
|
|||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ---- USACO practice log (/usaco/) ----
|
||||||
|
# Its own container (the usaco repo's site/), shaped like /jobs/: SPA
|
||||||
|
# and API under one prefix that is NOT stripped, and no
|
||||||
|
# auth_request, because most of it is public and the app checks the
|
||||||
|
# session itself for the admin's edits. Gitea's push webhook does not
|
||||||
|
# come through here: it calls the container directly on the Docker
|
||||||
|
# network. ^~ so no regex location can claim a /usaco/ path.
|
||||||
|
location = /usaco {
|
||||||
|
return 301 /usaco/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ^~ /usaco/ {
|
||||||
|
limit_req zone=api burst=20 nodelay;
|
||||||
|
# An admin edit commits and pushes to Gitea before answering.
|
||||||
|
proxy_read_timeout 120s;
|
||||||
|
proxy_pass $upstream_usaco;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
# ---- Activity tracker (/tracker/) ----
|
# ---- Activity tracker (/tracker/) ----
|
||||||
# Its own container (the adamf/ccp repo): an ingest API for device
|
# Its own container (the adamf/ccp repo): an ingest API for device
|
||||||
# collectors, which send batches of events with a per-device bearer
|
# collectors, which send batches of events with a per-device bearer
|
||||||
|
|||||||
Reference in New Issue
Block a user