Serve fediverse paths on the UI's domain (phase 1, step 6)
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 1m6s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 1m6s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
- The UI container forwards /.well-known/{webfinger,nodeinfo,host-meta},
/nodeinfo/, /users/, /inbox and /actor to API_INTERNAL_URL (compose:
http://api:8000), passing Host and X-Forwarded-*; unset means no
forwarding
- The API's name is resolved per request via the container's resolver,
so the UI starts before the API and survives API restarts
- Compose passes the FEDERATION_* settings to api and worker;
.env.example documents them, including FEDERATION_KEY_SECRET
- gunicorn: disable the 26.x control socket (the container user has no
home directory)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
c0b9e85519
commit
8d12922f6a
5 files changed
+58
-1
No files matched your search
@@ -24,6 +24,9 @@ GRAFANA_PORT=3000
|
||||
GRAFANA_ADMIN_PASSWORD=admin
|
||||
|
||||
# ActivityPub federation (in development; off by default). See src/scrobbler/federation/README.md.
|
||||
# Use the web UI's host and origin: handles become @user@<FEDERATION_DOMAIN>.
|
||||
FEDERATION_ENABLED=0
|
||||
FEDERATION_DOMAIN=
|
||||
FEDERATION_BASE_URL=
|
||||
# 32+ characters; encrypts actors' private keys. Keep it safe and never change it.
|
||||
FEDERATION_KEY_SECRET=
|
||||
@@ -1,4 +1,10 @@
|
||||
# Rendered by the nginx image's envsubst step (API_BASE_URL comes from the environment).
|
||||
|
||||
# Behind a TLS proxy, keep its scheme; otherwise use ours.
|
||||
map $http_x_forwarded_proto $scrobbler_forwarded_proto {
|
||||
default $http_x_forwarded_proto;
|
||||
"" $scheme;
|
||||
}
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
@@ -17,6 +23,9 @@ server {
|
||||
add_header Referrer-Policy same-origin always;
|
||||
}
|
||||
|
||||
# Fediverse paths forwarded to the API (written at start-up; empty if API_INTERNAL_URL is unset).
|
||||
include /etc/nginx/scrobbler/federation.conf;
|
||||
|
||||
location /fonts/ {
|
||||
add_header Cache-Control "public, max-age=2592000, immutable";
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@ services:
|
||||
WEB_CONCURRENCY: ${WEB_CONCURRENCY:-2}
|
||||
FORWARDED_ALLOW_IPS: "*"
|
||||
LASTFM_API_KEY: ${LASTFM_API_KEY:-}
|
||||
FEDERATION_ENABLED: ${FEDERATION_ENABLED:-0}
|
||||
FEDERATION_DOMAIN: ${FEDERATION_DOMAIN:-}
|
||||
FEDERATION_BASE_URL: ${FEDERATION_BASE_URL:-}
|
||||
FEDERATION_KEY_SECRET: ${FEDERATION_KEY_SECRET:-}
|
||||
ports:
|
||||
- "${API_PORT:-5050}:8000"
|
||||
expose:
|
||||
@@ -53,6 +57,10 @@ services:
|
||||
DATABASE_URL: postgresql+psycopg://scrobbler:${POSTGRES_PASSWORD:-scrobbler}@db:5432/scrobbler
|
||||
SECRET_KEY: ${SECRET_KEY:-change-me}
|
||||
LASTFM_API_KEY: ${LASTFM_API_KEY:-}
|
||||
FEDERATION_ENABLED: ${FEDERATION_ENABLED:-0}
|
||||
FEDERATION_DOMAIN: ${FEDERATION_DOMAIN:-}
|
||||
FEDERATION_BASE_URL: ${FEDERATION_BASE_URL:-}
|
||||
FEDERATION_KEY_SECRET: ${FEDERATION_KEY_SECRET:-}
|
||||
RUN_MIGRATIONS: "0" # the api service applies them
|
||||
expose:
|
||||
- "9101" # metrics: internal network only
|
||||
@@ -69,6 +77,8 @@ services:
|
||||
dockerfile: docker/ui.Dockerfile
|
||||
environment:
|
||||
API_BASE_URL: ${API_BASE_URL:-http://localhost:5050}
|
||||
# Forward the fediverse paths (/.well-known/webfinger, /users/, /inbox, ...) to the API.
|
||||
API_INTERNAL_URL: ${API_INTERNAL_URL:-http://api:8000}
|
||||
ports:
|
||||
- "${UI_PORT:-8080}:80"
|
||||
|
||||
|
||||
+34
-1
@@ -1,5 +1,6 @@
|
||||
#!/bin/sh
|
||||
# Point the UI at the API: rewrite config.js from $API_BASE_URL at container start.
|
||||
# Container start-up: point the UI at the API, and (when API_INTERNAL_URL is set)
|
||||
# forward the fediverse paths on this domain to the API.
|
||||
set -e
|
||||
case "$API_BASE_URL" in
|
||||
http://*|https://*) ;;
|
||||
@@ -11,3 +12,35 @@ window.SCROBBLER_CONFIG = {
|
||||
apiBaseUrl: "$url",
|
||||
};
|
||||
JS
|
||||
|
||||
mkdir -p /etc/nginx/scrobbler
|
||||
if [ -z "$API_INTERNAL_URL" ]; then
|
||||
: > /etc/nginx/scrobbler/federation.conf
|
||||
exit 0
|
||||
fi
|
||||
case "$API_INTERNAL_URL" in
|
||||
http://*|https://*) ;;
|
||||
*) echo "API_INTERNAL_URL must look like http://api:8000" >&2; exit 1 ;;
|
||||
esac
|
||||
upstream=$(printf '%s' "$API_INTERNAL_URL" | sed 's#/*$##')
|
||||
case "$upstream" in
|
||||
*://*/*) echo "API_INTERNAL_URL must not have a path" >&2; exit 1 ;;
|
||||
esac
|
||||
# Resolve the API's name per request (not once at start-up), so the UI starts even if
|
||||
# the API isn't up yet and keeps working when the API container is replaced.
|
||||
nameserver=$(awk '/^nameserver/ { print $2; exit }' /etc/resolv.conf)
|
||||
case "$nameserver" in *:*) nameserver="[$nameserver]" ;; esac
|
||||
cat > /etc/nginx/scrobbler/federation.conf <<NGINX
|
||||
# Fediverse (ActivityPub) paths live on the UI's domain; the API answers them.
|
||||
location ~ ^/(\.well-known/(webfinger|nodeinfo|host-meta)\$|nodeinfo/|users/|inbox\$|actor(/|\$)) {
|
||||
resolver ${nameserver:-127.0.0.11} valid=30s ipv6=off;
|
||||
set \$scrobbler_api $upstream;
|
||||
proxy_pass \$scrobbler_api;
|
||||
proxy_set_header Host \$host;
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto \$scrobbler_forwarded_proto;
|
||||
proxy_set_header X-Forwarded-Host \$host;
|
||||
client_max_body_size 1m;
|
||||
}
|
||||
NGINX
|
||||
echo "forwarding fediverse paths to $upstream"
|
||||
@@ -12,6 +12,8 @@ bind = os.environ.get("BIND", "0.0.0.0:8000")
|
||||
workers = int(os.environ.get("WEB_CONCURRENCY", "2"))
|
||||
accesslog = "-"
|
||||
forwarded_allow_ips = os.environ.get("FORWARDED_ALLOW_IPS", "127.0.0.1")
|
||||
# gunicorn 26's control socket lives in $HOME, which the container user doesn't have.
|
||||
control_socket_disable = True
|
||||
|
||||
|
||||
def on_starting(server):
|
||||
|
||||
Reference in new issue
Block a user