From 65cd6104686f8c89134e2f96c93734782bb433aa Mon Sep 17 00:00:00 2001 From: Matthew Daubney Date: Tue, 6 Oct 2026 23:12:41 +0100 Subject: [PATCH] Isolate concurrent federation interop runs (SCR-4) Let Docker allocate each run's network subnet instead of deriving a /24 from the run number, trust private ranges in GoToSocial, and tag/clean up api and ui images per run so overlapping runs (e.g. main push plus tag) cannot collide. Co-Authored-By: Claude Sonnet 5.5 --- .gitea/workflows/ci.yml | 7 +++---- deploy/interop/docker-compose.interop.yml | 9 ++++----- scripts/interop/compose.sh | 2 +- scripts/interop/run.sh | 9 ++++++++- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 9ea3e33..9055844 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -87,11 +87,10 @@ jobs: - uses: actions/checkout@v4 - name: Scrobbler <-> GoToSocial env: + # Own compose project, network and image tags, so concurrent runs can't collide INTEROP_PROJECT: interop-${{ github.run_id }} - run: | - # A subnet of its own, so concurrent runs can't collide - export INTEROP_SUBNET="172.30.$(( ${{ github.run_number }} % 200 + 20 )).0/24" - scripts/interop/run.sh + SCROBBLER_IMAGE_TAG: interop-${{ github.run_id }} + run: scripts/interop/run.sh # ---- Publishing (main and v* tags only) ------------------------------------- diff --git a/deploy/interop/docker-compose.interop.yml b/deploy/interop/docker-compose.interop.yml index c6bd88d..69220aa 100644 --- a/deploy/interop/docker-compose.interop.yml +++ b/deploy/interop/docker-compose.interop.yml @@ -18,11 +18,10 @@ x-federation: &federation FEDERATION_INSECURE_TESTING: "1" UI_BASE_URL: https://scrobble.test +# Docker picks the network's subnet, so concurrent runs can't collide on one. GoToSocial +# is therefore told to trust any private range rather than one specific /24. networks: fedi: - ipam: - config: - - subnet: ${INTEROP_SUBNET:-172.30.0.0/24} services: db: @@ -63,9 +62,9 @@ services: GTS_PORT: "80" GTS_DB_TYPE: sqlite GTS_DB_ADDRESS: /gotosocial/storage/sqlite.db - GTS_HTTP_CLIENT_ALLOW_IPS: ${INTEROP_SUBNET:-172.30.0.0/24} # let it reach Scrobbler on this network + GTS_HTTP_CLIENT_ALLOW_IPS: ${INTEROP_PRIVATE_RANGES:-10.0.0.0/8,172.16.0.0/12,192.168.0.0/16} # let it reach Scrobbler on this network GTS_HTTP_CLIENT_TLS_INSECURE_SKIP_VERIFY: "true" # Caddy's throwaway certificate - GTS_TRUSTED_PROXIES: ${INTEROP_SUBNET:-172.30.0.0/24} + GTS_TRUSTED_PROXIES: ${INTEROP_PRIVATE_RANGES:-10.0.0.0/8,172.16.0.0/12,192.168.0.0/16} GTS_ACCOUNTS_REGISTRATION_OPEN: "false" GTS_LOG_LEVEL: ${GTS_LOG_LEVEL:-info} sysctls: diff --git a/scripts/interop/compose.sh b/scripts/interop/compose.sh index 7884744..73a7de9 100755 --- a/scripts/interop/compose.sh +++ b/scripts/interop/compose.sh @@ -2,6 +2,6 @@ # docker compose for the federation interop stack (Scrobbler + GoToSocial). set -euo pipefail root="$(cd "$(dirname "$0")/../.." && pwd)" -# INTEROP_PROJECT and INTEROP_SUBNET let concurrent runs (e.g. in CI) stay apart. +# INTEROP_PROJECT (with a distinct SCROBBLER_IMAGE_TAG) lets concurrent runs (e.g. in CI) stay apart. exec docker compose -p "${INTEROP_PROJECT:-scrobbler-interop}" \ -f "$root/docker-compose.yml" -f "$root/deploy/interop/docker-compose.interop.yml" "$@" diff --git a/scripts/interop/run.sh b/scripts/interop/run.sh index e99cffe..3f5fce6 100755 --- a/scripts/interop/run.sh +++ b/scripts/interop/run.sh @@ -6,7 +6,14 @@ here="$(cd "$(dirname "$0")" && pwd)" compose="$here/compose.sh" keep=0; [ "${1:-}" = "--keep" ] && keep=1 -cleanup() { [ "$keep" = 1 ] || "$compose" down -v --remove-orphans >/dev/null 2>&1; } +cleanup() { + [ "$keep" = 1 ] && return 0 + "$compose" down -v --remove-orphans --rmi local >/dev/null 2>&1 + # Per-run api/ui images (tagged with SCROBBLER_IMAGE_TAG) would otherwise pile up + [ -n "${SCROBBLER_IMAGE_TAG:-}" ] && "$compose" config --images 2>/dev/null \ + | grep ":${SCROBBLER_IMAGE_TAG}$" | xargs -r docker rmi >/dev/null 2>&1 + return 0 +} trap cleanup EXIT "$compose" down -v --remove-orphans >/dev/null 2>&1