Add optional compose for rust-synapse-compress-state

This commit is contained in:
notplants
2026-04-29 13:14:49 -04:00
parent 8a7978b388
commit 3fab725957
3 changed files with 73 additions and 0 deletions

View File

@ -199,6 +199,14 @@ RETENTION_MAX_LIFETIME=4w
#WEB_CLIENT_LOCATION=https://element-web.example.com
## State compression (reduces database bloat from federation)
## Runs synapse_auto_compressor daily, built from source on first start
#COMPOSE_FILE="$COMPOSE_FILE:compose.compress-state.yml"
#COMPRESS_STATE_ENTRYPOINT_VERSION=v1
#STATE_COMPRESS_CHUNK_SIZE=500
#STATE_COMPRESS_CHUNKS=100
#STATE_COMPRESS_INTERVAL=86400
## Admin interface at /admin
#COMPOSE_FILE="$COMPOSE_FILE:compose.admin.yml"
#ADMIN_INTERFACE_ENABLED=1

View File

@ -0,0 +1,31 @@
version: "3.8"
services:
compress-state:
image: rust:1-alpine
entrypoint: /compress_state_entrypoint.sh
environment:
- STATE_COMPRESS_CHUNK_SIZE=${STATE_COMPRESS_CHUNK_SIZE:-500}
- STATE_COMPRESS_CHUNKS=${STATE_COMPRESS_CHUNKS:-100}
- STATE_COMPRESS_INTERVAL=${STATE_COMPRESS_INTERVAL:-86400}
secrets:
- db_password
configs:
- source: compress_entrypoint
target: /compress_state_entrypoint.sh
mode: 0555
volumes:
- compress_state_build:/build
networks:
- internal
deploy:
restart_policy:
condition: on-failure
volumes:
compress_state_build:
configs:
compress_entrypoint:
name: ${STACK_NAME}_compress_ep_${COMPRESS_STATE_ENTRYPOINT_VERSION}
file: compress_state_entrypoint.sh

View File

@ -0,0 +1,34 @@
#!/bin/sh
set -e
BINARY="/build/synapse_auto_compressor"
REPO_DIR="/build/rust-synapse-compress-state"
DB_PASS=$(cat /run/secrets/db_password)
CONN="postgresql://synapse:${DB_PASS}@db:5432/synapse"
CHUNK_SIZE="${STATE_COMPRESS_CHUNK_SIZE:-500}"
CHUNKS="${STATE_COMPRESS_CHUNKS:-100}"
INTERVAL="${STATE_COMPRESS_INTERVAL:-86400}"
# Build from source if binary doesn't exist
if [ ! -f "$BINARY" ]; then
echo "[compress-state] Binary not found, building from source..."
apk add --no-cache git openssl-dev openssl-libs-static perl make musl-dev jemalloc-dev
rm -rf "$REPO_DIR"
git clone https://github.com/matrix-org/rust-synapse-compress-state "$REPO_DIR"
cd "$REPO_DIR"
cargo build --release -p synapse_auto_compressor
cp target/release/synapse_auto_compressor "$BINARY"
echo "[compress-state] Build complete"
# Clean up source to save space
rm -rf "$REPO_DIR"
else
echo "[compress-state] Using cached binary"
fi
# Run compressor in a loop
while true; do
echo "[compress-state] Running at $(date)"
"$BINARY" -p "$CONN" -c "$CHUNK_SIZE" -n "$CHUNKS" || echo "[compress-state] Error: $?"
echo "[compress-state] Done. Sleeping ${INTERVAL}s"
sleep "$INTERVAL"
done