fix/docker-log-rotation-disk-management (#93)

Co-authored-by: openhands <openhands@all-hands.dev>
Reviewed-on: https://codeberg.org/johba/harb/pulls/93
This commit is contained in:
johba 2025-11-09 12:57:49 +01:00
parent 5d71753086
commit 19bac420d0
4 changed files with 78 additions and 1 deletions

View file

@ -49,6 +49,8 @@
```
- **Container Orchestration**: `docker-compose.yml` has NO `depends_on` declarations. All service ordering is handled in `scripts/dev.sh` via phased startup with explicit health checks.
- **Startup Phases**: (1) Create all containers, (2) Start anvil+postgres and wait for healthy, (3) Start bootstrap and wait for completion, (4) Start ponder and wait for healthy, (5) Start webapp/landing/txn-bot, (6) Start caddy.
- **Logging Configuration**: All services have log rotation configured (max 10MB per file, 3 files max = 30MB per container) to prevent disk bloat. Logs are automatically rotated by Docker.
- **Disk Management**: `./scripts/dev.sh stop` automatically prunes unused Docker resources. For aggressive cleanup, run `./scripts/cleanup-disk.sh`.
## Guardrails & Tips
- `token0isWeth` flips amount semantics; confirm ordering before seeding or interpreting liquidity.

View file

@ -4,6 +4,13 @@ networks:
harb-network:
driver: bridge
# Global logging configuration to prevent disk bloat
x-logging: &default-logging
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
services:
anvil:
image: ghcr.io/foundry-rs/foundry:latest
@ -17,6 +24,7 @@ services:
restart: unless-stopped
networks:
- harb-network
logging: *default-logging
healthcheck:
test: ["CMD", "cast", "block-number", "--rpc-url", "http://127.0.0.1:8545"]
interval: 2s
@ -37,6 +45,7 @@ services:
restart: unless-stopped
networks:
- harb-network
logging: *default-logging
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ponder"]
interval: 5s
@ -56,6 +65,7 @@ services:
networks:
- harb-network
restart: "no"
logging: *default-logging
healthcheck:
test: ["CMD", "test", "-f", "/workspace/tmp/containers/contracts.env"]
interval: 5s
@ -84,6 +94,7 @@ services:
restart: unless-stopped
networks:
- harb-network
logging: *default-logging
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:42069/"]
interval: 5s
@ -112,6 +123,7 @@ services:
restart: unless-stopped
networks:
- harb-network
logging: *default-logging
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:5173/"]
interval: 5s
@ -137,6 +149,7 @@ services:
restart: unless-stopped
networks:
- harb-network
logging: *default-logging
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:5174/"]
interval: 5s
@ -161,6 +174,7 @@ services:
restart: unless-stopped
networks:
- harb-network
logging: *default-logging
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:43069/status"]
interval: 5s
@ -176,6 +190,7 @@ services:
restart: unless-stopped
networks:
- harb-network
logging: *default-logging
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:80"]
interval: 2s

55
scripts/cleanup-disk.sh Executable file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -euo pipefail
# Disk cleanup utility for Harb stack
# Use this to aggressively free up disk space
cd "$(dirname "$0")/.."
echo "=== Harb Stack Disk Cleanup ==="
echo ""
# Detect container runtime
if command -v docker &> /dev/null; then
RUNTIME_CMD="docker"
elif command -v podman &> /dev/null; then
RUNTIME_CMD="podman"
else
echo "Error: docker/podman not found"
exit 1
fi
echo "Current disk usage:"
df -h / | tail -1
echo ""
# Stop the stack first
if [[ -f "./scripts/dev.sh" ]]; then
echo "Stopping stack..."
./scripts/dev.sh stop || true
fi
echo ""
echo "Pruning Docker resources..."
echo " - Stopped containers"
echo " - Unused volumes"
echo " - Dangling images"
echo " - Build cache"
echo ""
# Aggressive pruning
${RUNTIME_CMD} system prune -af --volumes
echo ""
echo "Cleaning npm caches..."
rm -rf ~/.npm ~/.cache 2>/dev/null || true
echo ""
echo "Cleaning journal logs..."
sudo journalctl --vacuum-size=500M 2>/dev/null || echo " (skipped: needs sudo)"
echo ""
echo "Final disk usage:"
df -h / | tail -1
echo ""
echo "[ok] Cleanup complete"

View file

@ -162,7 +162,12 @@ start_stack() {
stop_stack() {
cleanup_existing
${COMPOSE_CMD} down
echo "[ok] Stack stopped"
# Prune Docker resources to prevent disk bloat
echo " Pruning Docker resources..."
${RUNTIME_CMD} system prune -f --volumes 2>&1 | grep -E "Total reclaimed|deleted" || true
echo "[ok] Stack stopped and cleaned"
}
check_health() {