mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-18 19:25:56 +00:00
Phase 12: Coordinator deployment files, join/claim commands and UI, access options for published realms
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
71e1488336
commit
2caa687490
18 files changed
+856
-8
No files matched your search
@@ -0,0 +1,16 @@
|
||||
# Build context: the repository root. docker build -f services/coa-coordinator/Dockerfile -t coa-coordinator:<tag> .
|
||||
FROM rust:1-bookworm AS build
|
||||
WORKDIR /src
|
||||
COPY crates/coa-registry-proto crates/coa-registry-proto
|
||||
COPY crates/coa-control-proto crates/coa-control-proto
|
||||
COPY services/coa-coordinator services/coa-coordinator
|
||||
WORKDIR /src/services/coa-coordinator
|
||||
RUN cargo build --release --locked --bin coa-coordinator
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
RUN useradd --system --uid 10002 --user-group --no-create-home --shell /usr/sbin/nologin coa
|
||||
COPY --from=build /src/services/coa-coordinator/target/release/coa-coordinator /usr/local/bin/coa-coordinator
|
||||
USER 10002:10002
|
||||
EXPOSE 8081
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 CMD ["/usr/local/bin/coa-coordinator", "--healthcheck"]
|
||||
ENTRYPOINT ["/usr/local/bin/coa-coordinator"]
|
||||
@@ -0,0 +1,37 @@
|
||||
# /opt/coa/coordinator/compose.yaml (Phase 12). The Coordinator publishes no host port: Caddy reaches it as coa-coordinator:8081 on coa-ingress. It reads the realms' public
|
||||
# keys from the Registry's database with a role that can read four columns and nothing else. It keeps nothing on disk and writes no database row.
|
||||
name: coa-coordinator
|
||||
services:
|
||||
coordinator:
|
||||
image: coa-coordinator:${COORDINATOR_TAG:-latest}
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
COORD_LISTEN: "0.0.0.0:8081"
|
||||
COORD_TRUST_PROXY: "1"
|
||||
COORD_DB_HOST: coa-postgres
|
||||
COORD_DB_NAME: coa_registry
|
||||
COORD_DB_USER: coa_coordinator
|
||||
COORD_DB_PASSWORD_FILE: /run/secrets/coordinator_db_password
|
||||
RUST_LOG: "info"
|
||||
secrets:
|
||||
- coordinator_db_password
|
||||
read_only: true
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
mem_limit: 256m
|
||||
pids_limit: 128
|
||||
networks:
|
||||
coa-ingress:
|
||||
aliases:
|
||||
- coa-coordinator
|
||||
coa-db: {}
|
||||
secrets:
|
||||
coordinator_db_password:
|
||||
file: /opt/coa/secrets/coordinator_db_password
|
||||
networks:
|
||||
coa-ingress:
|
||||
external: true
|
||||
coa-db:
|
||||
external: true
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
# Build the Coordinator image on the node from the working tree and (re)start it. Usage (from the repository root):
|
||||
# VPS=ubuntu@<VPS_IP> TAG=p12a sh services/coa-coordinator/deploy/deploy.sh
|
||||
# The database role must exist (provision-db.sh) and /opt/coa/coordinator/compose.yaml must be in place (copied here on the first run).
|
||||
set -eu
|
||||
: "${VPS:?set VPS=user@host}" "${TAG:?set TAG=<image tag>}"
|
||||
tar --exclude=target -czf /tmp/coordinator-src.tgz crates/coa-registry-proto crates/coa-control-proto services/coa-coordinator .dockerignore
|
||||
scp -q /tmp/coordinator-src.tgz "$VPS:/tmp/coordinator-src.tgz"
|
||||
scp -q services/coa-coordinator/deploy/coordinator.compose.yaml "$VPS:/tmp/coordinator.compose.yaml"
|
||||
scp -q services/coa-coordinator/deploy/provision-db.sh "$VPS:/tmp/coordinator-provision-db.sh"
|
||||
ssh "$VPS" "set -e
|
||||
sudo mkdir -p /opt/coa/coordinator && sudo cp /tmp/coordinator.compose.yaml /opt/coa/coordinator/compose.yaml
|
||||
sudo sh /tmp/coordinator-provision-db.sh
|
||||
sudo rm -rf /opt/coa/coordinator/src && sudo mkdir -p /opt/coa/coordinator/src && sudo tar -xzf /tmp/coordinator-src.tgz -C /opt/coa/coordinator/src
|
||||
cd /opt/coa/coordinator/src && sudo docker build -q -f services/coa-coordinator/Dockerfile -t coa-coordinator:$TAG . >/dev/null
|
||||
cd /opt/coa/coordinator && echo COORDINATOR_TAG=$TAG | sudo tee .env >/dev/null && sudo docker compose up -d
|
||||
sleep 8 && sudo docker ps --format '{{.Names}} {{.Status}}'"
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
# Create the Coordinator's database role (idempotent). Run on the node as root: sudo sh provision-db.sh
|
||||
# The role may read exactly four columns of one table. The password is read from /opt/coa/secrets/coordinator_db_password (created here when missing) and goes to psql on stdin.
|
||||
set -eu
|
||||
umask 077
|
||||
if [ ! -s /opt/coa/secrets/coordinator_db_password ]; then
|
||||
head -c 32 /dev/urandom | base64 | tr -d '/+=\n' | head -c 40 > /opt/coa/secrets/coordinator_db_password
|
||||
fi
|
||||
chown root:10002 /opt/coa/secrets/coordinator_db_password
|
||||
chmod 0440 /opt/coa/secrets/coordinator_db_password
|
||||
PW=$(cat /opt/coa/secrets/coordinator_db_password)
|
||||
docker exec -i coa-postgres-postgres-1 sh -c 'PGPASSWORD=$(cat /run/secrets/postgres_password) exec psql -U coa -d coa_registry -v ON_ERROR_STOP=1 -q' <<SQL
|
||||
DO \$\$ BEGIN
|
||||
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'coa_coordinator') THEN
|
||||
CREATE ROLE coa_coordinator LOGIN PASSWORD '$PW' NOSUPERUSER NOCREATEDB NOCREATEROLE CONNECTION LIMIT 8;
|
||||
ELSE
|
||||
ALTER ROLE coa_coordinator PASSWORD '$PW';
|
||||
END IF;
|
||||
END \$\$;
|
||||
REVOKE ALL ON DATABASE coa_registry FROM coa_coordinator;
|
||||
GRANT CONNECT ON DATABASE coa_registry TO coa_coordinator;
|
||||
REVOKE ALL ON ALL TABLES IN SCHEMA public FROM coa_coordinator;
|
||||
GRANT USAGE ON SCHEMA public TO coa_coordinator;
|
||||
GRANT SELECT (realm_id, public_key, published, advert_version) ON realms TO coa_coordinator;
|
||||
SQL
|
||||
echo "coordinator role is in place"
|
||||
@@ -21,5 +21,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
# Phase 12: the control plane. WebSocket connections are proxied as they are; the Coordinator rate-limits by the address Caddy saw.
|
||||
handle /coord/* {
|
||||
reverse_proxy coa-coordinator:8081 {
|
||||
header_up X-Forwarded-For {remote_host}
|
||||
transport http {
|
||||
dial_timeout 3s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
respond "not found" 404
|
||||
}
|
||||
Reference in new issue
Block a user