From 00c99e58e9440f580d984123fd547b42848d09d5 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 4 Sep 2025 17:09:35 +0200 Subject: [PATCH] Cleaned up bridgy fed --- roles/web-app-bridgy-fed/README.md | 2 +- roles/web-app-bridgy-fed/config/main.yml | 19 ++++------ roles/web-app-bridgy-fed/files/Dockerfile | 6 +-- roles/web-app-bridgy-fed/schema/main.yml | 0 roles/web-app-bridgy-fed/tasks/01_core.yml | 16 +------- .../templates/Administration.md.j2 | 20 ---------- .../templates/docker-compose.yml.j2 | 29 ++------------ roles/web-app-bridgy-fed/templates/env.j2 | 15 +++----- roles/web-app-bridgy-fed/vars/main.yml | 38 +++++++++---------- 9 files changed, 39 insertions(+), 106 deletions(-) create mode 100644 roles/web-app-bridgy-fed/schema/main.yml delete mode 100644 roles/web-app-bridgy-fed/templates/Administration.md.j2 diff --git a/roles/web-app-bridgy-fed/README.md b/roles/web-app-bridgy-fed/README.md index e1f72fca..c59d737d 100644 --- a/roles/web-app-bridgy-fed/README.md +++ b/roles/web-app-bridgy-fed/README.md @@ -9,7 +9,7 @@ This role builds and runs Bridgy Fed as a Docker container and (optionally) star Upstream docs & dev notes: - User & developer docs: https://fed.brid.gy and https://bridgy-fed.readthedocs.io/ - Source: https://github.com/snarfed/bridgy-fed -- Local run (reference): `flask run -p 8080` with APPVIEW_HOST/PLC_HOST/BGS_HOST/PDS_HOST set, and Datastore emulator envs +- Local run (reference): `flask run -p 8080` with BRIDGY_APPVIEW_HOST/BRIDGY_PLC_HOST/BRIDGY_BGS_HOST/BRIDGY_PDS_HOST set, and Datastore emulator envs ## Features - Dockerized Flask app (gunicorn) diff --git a/roles/web-app-bridgy-fed/config/main.yml b/roles/web-app-bridgy-fed/config/main.yml index 2f3c4c8b..3a3a81d2 100644 --- a/roles/web-app-bridgy-fed/config/main.yml +++ b/roles/web-app-bridgy-fed/config/main.yml @@ -17,18 +17,13 @@ server: docker: services: database: - enabled: false - emulator: - enabled: true - image: 'gcr.io/google.com/cloudsdktool/google-cloud-cli:latest' + enabled: false application: - image: "python" - version: "3.12-bookworm" - name: "web-app-bridgy-fed" - + image: "python" + version: "3.12-bookworm" + name: "web-app-bridgy-fed" + repository: "https://github.com/snarfed/bridgy-fed.git" + branch: "main" rbac: roles: {} - -source: - repo: "https://github.com/snarfed/bridgy-fed.git" - ref: "main" + diff --git a/roles/web-app-bridgy-fed/files/Dockerfile b/roles/web-app-bridgy-fed/files/Dockerfile index 8fa25b0c..48cebb10 100644 --- a/roles/web-app-bridgy-fed/files/Dockerfile +++ b/roles/web-app-bridgy-fed/files/Dockerfile @@ -3,7 +3,7 @@ ARG PY_BASE="python:3.12-bookworm" FROM ${PY_BASE} AS build ARG BRIDGY_REPO_URL -ARG BRIDGY_REPO_REF +ARG BRIDGY_REPO_BRANCH # System deps: git, build tools, curl for healthchecks, and gunicorn RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -11,7 +11,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ rm -rf /var/lib/apt/lists/* WORKDIR /app -RUN git clone --depth=1 --branch "${BRIDGY_REPO_REF}" "${BRIDGY_REPO_URL}" ./ +RUN git clone --depth=1 --branch "${BRIDGY_REPO_BRANCH}" "${BRIDGY_REPO_URL}" ./ # Python deps RUN pip install --upgrade pip && \ @@ -35,7 +35,7 @@ PY FROM ${PY_BASE} ARG CONTAINER_PORT -ENV PORT=${CONTAINER_PORT:-8080} +ENV PORT=${CONTAINER_PORT} WORKDIR /app COPY --from=build /app /app diff --git a/roles/web-app-bridgy-fed/schema/main.yml b/roles/web-app-bridgy-fed/schema/main.yml new file mode 100644 index 00000000..e69de29b diff --git a/roles/web-app-bridgy-fed/tasks/01_core.yml b/roles/web-app-bridgy-fed/tasks/01_core.yml index f8f77031..15ab77ca 100644 --- a/roles/web-app-bridgy-fed/tasks/01_core.yml +++ b/roles/web-app-bridgy-fed/tasks/01_core.yml @@ -2,20 +2,8 @@ include_role: name: sys-stk-full-stateless -- name: "Include front proxy for {{ container_hostname }}:{{ ports.localhost.http[application_id] }}" +- name: "Include front proxy for {{ container_hostname}}:{{ ports.localhost.http[application_id] }}" include_role: name: sys-stk-front-proxy - vars: - domain: "{{ container_hostname }}" - http_port: "{{ ports.localhost.http[application_id] }}" -- name: "Provide Dockerfile" - copy: - src: "Dockerfile" - dest: "{{ docker_compose.directories.instance }}/Dockerfile" - notify: - - docker compose build - -- name: "Run once marker" - set_fact: - run_once_web_app_bridgy_fed: true +- include_tasks: utils/run_once.yml \ No newline at end of file diff --git a/roles/web-app-bridgy-fed/templates/Administration.md.j2 b/roles/web-app-bridgy-fed/templates/Administration.md.j2 deleted file mode 100644 index 201dd164..00000000 --- a/roles/web-app-bridgy-fed/templates/Administration.md.j2 +++ /dev/null @@ -1,20 +0,0 @@ -# Administration - -## Local dev shell (inside container) -```bash -docker compose exec application bash -``` - -## Logs -```bash -docker compose logs -f application -docker compose logs -f emulator # if enabled -``` - -## Notes -- Upstream dev run example: - ```bash - export APPVIEW_HOST=api.bsky.app PLC_HOST=plc.directory BGS_HOST=bsky.network PDS_HOST=atproto.brid.gy - flask --debug run -p 8080 - ``` - (We run via gunicorn in this role.) diff --git a/roles/web-app-bridgy-fed/templates/docker-compose.yml.j2 b/roles/web-app-bridgy-fed/templates/docker-compose.yml.j2 index 540f4993..27f4e699 100644 --- a/roles/web-app-bridgy-fed/templates/docker-compose.yml.j2 +++ b/roles/web-app-bridgy-fed/templates/docker-compose.yml.j2 @@ -6,38 +6,15 @@ dockerfile: Dockerfile args: BRIDGY_REPO_URL: "{{ BRIDGY_REPO_URL }}" - BRIDGY_REPO_REF: "{{ BRIDGY_REPO_REF }}" + BRIDGY_REPO_BRANCH: "{{ BRIDGY_REPO_BRANCH }}" CONTAINER_PORT: "{{ container_port | string }}" - image: "{{ BRIDGY_IMAGE }}" + image: "{{ BRIDGY_IMAGE }}:{{ BRIDGY_VERSION }}" container_name: "{{ BRIDGY_CONTAINER }}" hostname: "{{ container_hostname }}" - env_file: - - "{{ docker_compose.files.env }}" ports: - - "127.0.0.1:{{ ports.localhost.http[application_id] }}:{{ container_port }}" + - "127.0.0.1:{{ http_port }}:{{ container_port }}" {% include 'roles/docker-container/templates/healthcheck/tcp.yml.j2' %} {% include 'roles/docker-container/templates/base.yml.j2' %} - depends_on: -{% if EMULATOR_ENABLED | bool %} - - emulator -{% endif %} {% include 'roles/docker-container/templates/networks.yml.j2' %} -{% if EMULATOR_ENABLED | bool %} - emulator: - image: "{{ EMULATOR_IMAGE }}" - container_name: "{{ BRIDGY_CONTAINER }}_emulator" - command: > - gcloud emulators firestore start - --host-port=0.0.0.0:{{ EMULATOR_PORT }} - --database-mode=datastore-mode - --quiet - ports: - - "127.0.0.1:{{ EMULATOR_PORT }}:{{ EMULATOR_PORT }}" - environment: - - CLOUDSDK_CORE_DISABLE_PROMPTS=1 - restart: unless-stopped -{% include 'roles/docker-container/templates/networks.yml.j2' %} -{% endif %} - {% include 'roles/docker-compose/templates/networks.yml.j2' %} diff --git a/roles/web-app-bridgy-fed/templates/env.j2 b/roles/web-app-bridgy-fed/templates/env.j2 index e86c2409..8f6d6b67 100644 --- a/roles/web-app-bridgy-fed/templates/env.j2 +++ b/roles/web-app-bridgy-fed/templates/env.j2 @@ -1,18 +1,13 @@ # Flask / Gunicorn basics -FLASK_ENV="{{ ENVIRONMENT | default('production') }}" +FLASK_ENV="{{ ENVIRONMENT }}" PORT="{{ container_port }}" BRIDGY_ADMIN_EMAIL="{{ BRIDGY_ADMIN_EMAIL }}" # Bridgy Fed upstream knobs (see README @ GitHub) -APPVIEW_HOST="{{ APPVIEW_HOST }}" -PLC_HOST="{{ PLC_HOST }}" -BGS_HOST="{{ BGS_HOST }}" -PDS_HOST="{{ PDS_HOST }}" - -# Datastore emulator (Datastore-mode Firestore). If sidecar enabled, point here. -GOOGLE_CLOUD_PROJECT="{{ EMULATOR_PROJECT_ID }}" -DATASTORE_EMULATOR_HOST="{{ EMULATOR_ENABLED | ternary(EMULATOR_HOST_INTERNAL, '') }}" -# DATASTORE_DATASET not needed when GOOGLE_CLOUD_PROJECT is set +BRIDGY_APPVIEW_HOST="{{ BRIDGY_APPVIEW_HOST }}" +BRIDGY_PLC_HOST="{{ BRIDGY_PLC_HOST }}" +BRIDGY_BGS_HOST="{{ BRIDGY_BGS_HOST }}" +BRIDGY_PDS_HOST="{{ BRIDGY_PDS_HOST }}" # Optional: # GUNICORN_CMD_ARGS="--log-level info" diff --git a/roles/web-app-bridgy-fed/vars/main.yml b/roles/web-app-bridgy-fed/vars/main.yml index 88b6f46b..0db6db45 100644 --- a/roles/web-app-bridgy-fed/vars/main.yml +++ b/roles/web-app-bridgy-fed/vars/main.yml @@ -1,27 +1,25 @@ # General -application_id: "web-app-bridgy-fed" +application_id: "web-app-bridgy-fed" + +# Container +container_port: 8080 +domain: "{{ container_hostname }}" +http_port: "{{ ports.localhost.http[application_id] }}" +container_hostname: "{{ domains | get_domain(application_id) }}" # App container -BRIDGY_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.application.name') }}" -BRIDGY_IMAGE: "{{ applications | get_app_conf(application_id, 'docker.services.application.image') }}" -#BRIDGY_VERSION: "{{ applications | get_app_conf(application_id, 'docker.services.application.version')}}" -container_port: 8080 -container_hostname: "{{ domains | get_domain(application_id) }}" -BRIDGY_ADMIN_EMAIL: "{{ users.administrator.email }}" +BRIDGY_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.application.name') }}" +BRIDGY_IMAGE: "{{ applications | get_app_conf(application_id, 'docker.services.application.image') }}" +BRIDGY_VERSION: "{{ applications | get_app_conf(application_id, 'docker.services.application.version')}}" + +BRIDGY_ADMIN_EMAIL: "{{ users.administrator.email }}" # Source -BRIDGY_REPO_URL: "{{ applications | get_app_conf(application_id, 'source.repo') }}" -BRIDGY_REPO_REF: "{{ applications | get_app_conf(application_id, 'source.ref') }}" - -# Emulator sidecar (Datastore-mode Firestore) -EMULATOR_ENABLED: "{{ applications | get_app_conf(application_id, 'docker.services.emulator.enabled') }}" -EMULATOR_IMAGE: "{{ applications | get_app_conf(application_id, 'docker.services.emulator.image') }}" -EMULATOR_PORT: 8089 -EMULATOR_HOST_INTERNAL: "emulator:8089" -EMULATOR_PROJECT_ID: "bridgy-federated-local" +BRIDGY_REPO_URL: "{{ applications | get_app_conf(application_id, 'docker.services.application.repository') }}" +BRIDGY_REPO_BRANCH: "{{ applications | get_app_conf(application_id, 'docker.services.application.branch') }}" # Runtime env defaults for Bridgy Fed (see upstream README) -APPVIEW_HOST: "api.bsky.app" -PLC_HOST: "plc.directory" -BGS_HOST: "bsky.network" -PDS_HOST: "atproto.brid.gy" +BRIDGY_APPVIEW_HOST: "api.bsky.app" +BRIDGY_PLC_HOST: "plc.directory" +BRIDGY_BGS_HOST: "bsky.network" +BRIDGY_PDS_HOST: "atproto.brid.gy"