Add optional compose for rust-synapse-compress-state
This commit is contained in:
@ -199,6 +199,14 @@ RETENTION_MAX_LIFETIME=4w
|
|||||||
#WEB_CLIENT_LOCATION=https://element-web.example.com
|
#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
|
## Admin interface at /admin
|
||||||
#COMPOSE_FILE="$COMPOSE_FILE:compose.admin.yml"
|
#COMPOSE_FILE="$COMPOSE_FILE:compose.admin.yml"
|
||||||
#ADMIN_INTERFACE_ENABLED=1
|
#ADMIN_INTERFACE_ENABLED=1
|
||||||
|
|||||||
31
compose.compress-state.yml
Normal file
31
compose.compress-state.yml
Normal 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
|
||||||
34
compress_state_entrypoint.sh
Normal file
34
compress_state_entrypoint.sh
Normal 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
|
||||||
Reference in New Issue
Block a user