-
Notifications
You must be signed in to change notification settings - Fork 0
Scaffolding: Federation sync app creation #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
klpoland
wants to merge
15
commits into
master
Choose a base branch
from
feature-kpoland-federation-sync-scaffolding
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cd5c382
fastapi app init
klpoland 4497e85
app models, doc schemas, webhook endpoints, peer sync/registry/bootst…
klpoland 7525f2c
test setup first pass
klpoland 9909983
create federation transport mesh to mock end-to-end peer app sync
klpoland ec5bc63
remove deprecated vars from tests
klpoland db630b0
integrate pyrefly
klpoland 87472a3
build out health check stub to check redis/opensearch status and conf…
klpoland d0608d2
cursor bot comments
klpoland ce44ac9
production vs local compose, add opensearch network
klpoland 3a7c399
set federation toml as example file for new sites to cp
klpoland 5f40bf1
follow rfc 12: site-prefixed redis channels
klpoland b0bc3f5
remove postgres db queries/dependencies, query opensearch only for as…
klpoland 212961d
add federation shared env to compose
klpoland e939cd7
align with gateway: remove event types, tombstones (all updates handl…
klpoland 155b128
linting
klpoland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Optional full channel override (default: federation:events:{site.name} from federation.toml) | ||
| # FEDERATION_EVENTS_CHANNEL= | ||
| FEDERATION_GATEWAY_API_KEY= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Dev PKI material — generate with scripts/generate-dev-certs.sh | ||
|
|
||
| __pycache__/ | ||
|
|
||
| federation.toml | ||
|
|
||
| .envs/* | ||
| !/.envs/example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| FROM docker.io/python:3.13-slim-trixie | ||
|
|
||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ | ||
|
|
||
| WORKDIR /app | ||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| COPY pyproject.toml ./ | ||
| RUN uv sync --no-dev | ||
|
|
||
| COPY sds_federation ./sds_federation | ||
|
|
||
| EXPOSE 8000 | ||
| CMD ["uv", "run", "uvicorn", "sds_federation.main:app", "--host", "0.0.0.0", "--port", "8000"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Dev PKI material — generate with scripts/generate-dev-certs.sh | ||
| * | ||
| !.gitignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| networks: | ||
| sds-network-local: | ||
| external: true | ||
| name: sds-network-local | ||
| sds-network-local-opensearch: | ||
| driver: bridge | ||
| name: sds-network-local-opensearch | ||
|
|
||
| services: | ||
| sds-federation-local-sync: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| image: sds-federation-local-sync | ||
| container_name: sds-federation-local-sync | ||
| env_file: | ||
| - .envs/local/sync.env | ||
| - ../federation-shared.env | ||
| environment: | ||
| FEDERATION_CONFIG_PATH: /etc/sds/federation.toml | ||
| GATEWAY_INTERNAL_BASE_URL: http://sds-gateway-local-app:8000/api/v1 | ||
| REDIS_URL: redis://sds-gateway-local-redis:6379/0 | ||
| OPENSEARCH_HOST: sds-gateway-local-opensearch | ||
| volumes: | ||
| - ./federation.toml:/etc/sds/federation.toml:ro | ||
| - ./certs:/etc/sds/certs:ro | ||
| ports: | ||
| - "8001:8000" | ||
| healthcheck: | ||
| test: | ||
| [ | ||
| "CMD", | ||
| "uv", | ||
| "run", | ||
| "python", | ||
| "-c", | ||
| "import sys, httpx; r=httpx.get('http://127.0.0.1:8000/health', timeout=4); sys.exit(0 if r.status_code==200 else 1)", | ||
| ] | ||
| interval: 30s | ||
| timeout: 5s | ||
| retries: 3 | ||
| networks: | ||
| - sds-network-local | ||
| - sds-network-local-opensearch | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| networks: | ||
| sds-network-prod: | ||
| external: true | ||
| name: sds-network-prod | ||
| sds-network-prod-opensearch: | ||
| driver: bridge | ||
| name: sds-network-prod-opensearch | ||
|
|
||
| services: | ||
| sds-federation-prod-sync: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| image: sds-federation-prod-sync | ||
| container_name: sds-federation-prod-sync | ||
| env_file: | ||
| - .envs/production/sync.env | ||
| - ../federation-shared.env | ||
| environment: | ||
| FEDERATION_CONFIG_PATH: /etc/sds/federation.toml | ||
| GATEWAY_INTERNAL_BASE_URL: http://sds-gateway-prod-app:8000/api/v1 | ||
| REDIS_URL: redis://sds-gateway-prod-redis:6379/0 | ||
| OPENSEARCH_HOST: sds-gateway-prod-opensearch | ||
| volumes: | ||
| - ./federation.toml:/etc/sds/federation.toml:ro | ||
| - ./certs:/etc/sds/certs:ro | ||
| ports: | ||
| - "8001:8000" | ||
| healthcheck: | ||
| test: | ||
| [ | ||
| "CMD", | ||
| "uv", | ||
| "run", | ||
| "python", | ||
| "-c", | ||
| "import sys, httpx; r=httpx.get('http://127.0.0.1:8000/health', timeout=4); sys.exit(0 if r.status_code==200 else 1)", | ||
| ] | ||
| interval: 30s | ||
| timeout: 5s | ||
| retries: 3 | ||
| networks: | ||
| - sds-network-prod | ||
| - sds-network-prod-opensearch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [site] | ||
| name = "your-site" | ||
| fqdn = "your-site.domain" | ||
| display_name = "Your Site" | ||
|
|
||
| [[peers]] | ||
| # Notre Dame SDS site is the original site deployment | ||
| # and is included as a peer by default. | ||
| name = "crc" | ||
| fqdn = "sds.crc.nd.edu" | ||
| display_name = "Notre Dame CRC" | ||
| gateway_api_base = "https://sds.crc.nd.edu/api/v1" | ||
| sync_service_url = "https://sds.crc.nd.edu/sync/" | ||
| ca_cert_path = "/etc/sds/certs/crc-ca.pem" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| set shell := ["bash", "-eu", "-o", "pipefail", "-c"] | ||
|
|
||
| # TIP: Production on this machine? Add hostname to ../gateway/scripts/prod-hostnames.env | ||
| # or set SDS_ENV=production|local | ||
|
|
||
| env_selection_script := "./scripts/env-selection.sh" | ||
|
|
||
| # variables | run `just env` to see current values | ||
|
|
||
| compose_file := shell(env_selection_script + ' $1', "compose_file") | ||
| env := shell(env_selection_script + ' $1', "env") | ||
| env_file := shell(env_selection_script + ' $1', "env_file") | ||
| sync_container := shell(env_selection_script + ' $1', "sync_container") | ||
| docker_compose := "COMPOSE_FILE=" + compose_file + " docker compose --env-file " + env_file | ||
|
|
||
| alias run := up | ||
|
|
||
| default: | ||
| @just --list | ||
|
|
||
| # prints currently selected environment (override with SDS_ENV=local|production) | ||
| [group('utilities')] | ||
| env: | ||
| #!/usr/bin/env bash | ||
| echo -e "\nSelected env:\n" | ||
| echo -e "\tEnvironment: \e[34m '{{ env }}'\e[0m" | ||
| echo -e "\tEnvironment file: \e[34m '{{ env_file }}'\e[0m" | ||
| echo -e "\tCompose file: \e[34m '{{ compose_file }}'\e[0m" | ||
| echo -e "\tSync container: \e[34m '{{ sync_container }}'\e[0m" | ||
| echo -e "\tDocker compose command: \e[34m '{{ docker_compose }}'\e[0m" | ||
|
|
||
| if ! [ -f "{{ compose_file }}" ]; then | ||
| echo -e "\n\e[31mError:\e[0m Compose file '{{ compose_file }}' does not exist." | ||
| exit 1 | ||
| fi | ||
| if ! [ -f "{{ env_file }}" ]; then | ||
| echo -e "\n\e[33mWarning:\e[0m Env file '{{ env_file }}' does not exist." | ||
| echo -e "Copy from .envs/example/sync.env if needed." | ||
| fi | ||
|
|
||
| # install runtime + dev deps (pytest) | ||
| [group('setup')] | ||
| sync: | ||
| uv sync --extra dev | ||
|
|
||
| [group('qa')] | ||
| test-regression +args='': | ||
| uv run pytest -m regression {{ args }} | ||
|
|
||
| [group('qa')] | ||
| test-integration +args='': | ||
| uv run pytest -m integration {{ args }} | ||
|
|
||
| [group('qa')] | ||
| test +args='': | ||
| uv run pytest {{ args }} | ||
|
|
||
| [group('qa')] | ||
| test-q: | ||
| uv run pytest -q | ||
|
|
||
| # Run federation pre-commit hooks from repo root (requires gateway dev deps / pre-commit install) | ||
| [group('qa')] | ||
| pre-commit +args='': | ||
| cd .. && uv run --directory gateway --extra local pre-commit run ruff-check-federation --all-files {{ args }} | ||
| cd .. && uv run --directory gateway --extra local pre-commit run ruff-format-federation --all-files {{ args }} | ||
| cd .. && uv run --directory gateway --extra local pre-commit run pyrefly-federation --all-files {{ args }} | ||
|
|
||
| # dev PKI for mTLS experiments (see docs/mtls-certificates.md) | ||
| [group('setup')] | ||
| gen-certs +args='': | ||
| ./scripts/generate-dev-certs.sh all {{ args }} | ||
|
|
||
| [group('setup')] | ||
| gen-certs-ca: | ||
| ./scripts/generate-dev-certs.sh ca | ||
|
|
||
| # publish simulated federation:events to Redis | ||
| [group('dev')] | ||
| simulate-redis +args='': | ||
| REDIS_URL="${REDIS_URL:-redis://localhost:6379/0}" uv run python scripts/simulate_redis_event.py {{ args }} | ||
|
|
||
| [group('docker')] | ||
| build +args='': | ||
| {{ docker_compose }} build {{ args }} | ||
|
|
||
| [group('docker')] | ||
| up +args='': | ||
| {{ docker_compose }} up -d --remove-orphans {{ args }} | ||
|
|
||
| [group('docker')] | ||
| down +args='': | ||
| {{ docker_compose }} down {{ args }} | ||
|
|
||
| [group('docker')] | ||
| logs +args='': | ||
| {{ docker_compose }} logs --tail 1000 -f {{ args }} | ||
|
|
||
| [group('docker')] | ||
| dc +args='': | ||
| {{ docker_compose }} {{ args }} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong OpenSearch Docker network
High Severity
The
sds-federation-local-syncservice cannot resolveOPENSEARCH_HOST(sds-gateway-local-opensearch) because it's attached tosds-network-local-opensearchwhile the gateway's OpenSearch service is onsds-gateway-*-opensearch-net. This network isolation prevents communication, causing indexing, Redis fan-out, and OpenSearch health checks to fail.Reviewed by Cursor Bugbot for commit 155b128. Configure here.