This commit is contained in:
Para Dox
2025-04-27 17:06:15 +07:00
parent 938bf33053
commit a1fc35b87f

View File

@@ -110,32 +110,18 @@ services:
- traefik.http.routers.ethereum-mainnet-reth-minimal-trace-node.middlewares=ethereum-mainnet-reth-minimal-trace-node-stripprefix, ipallowlist - traefik.http.routers.ethereum-mainnet-reth-minimal-trace-node.middlewares=ethereum-mainnet-reth-minimal-trace-node-stripprefix, ipallowlist
ethereum-mainnet-minimal-pruner: ethereum-mainnet-minimal-pruner:
build: image: debian:latest
context: . command:
dockerfile: | - |
FROM alpine:latest
# Install necessary packages
RUN apk add --no-cache bash coreutils sed findutils
# Create the prune script inline
RUN <<EOF > /prune.sh
#!/bin/bash
set -euo pipefail
# Settings # Settings
source_dir="/data" # Data directory (mount) source_dir="/data/static_files"
backup_dir="/backup" # Backup directory (mount) backup_dir="/data/static_files/delete_me"
target_free_percent=10 # Percentage of space to free
# Make sure backup dir exists
mkdir -p "$$backup_dir" mkdir -p "$$backup_dir"
# Step 1: List base filenames (without .conf/.off) and sort by starting block number # Step 1: List base filenames (without .conf/.off) and sort by starting block number
base_files=$$(find "$$source_dir" -maxdepth 1 -type f \ base_files=$$(find "$$source_dir" -maxdepth 1 -type f \
| sed -E "s/\.(conf|off)$$" \ | sed -E "s/\.(conf|off)$$" \
| sort -u \ | sort -u \
| awk -F_ '{print $$NF-0, $$0}' | sort -n | cut -d" " -f2-) | awk -F_ '{print $$NF-0, $$0}' | sort -n | cut -d" " -f2-)
# Step 2: Calculate total size
total_size_bytes=$$(du -cb "$$source_dir"/* | tail -1 | awk '{print $$1}')
target_free_bytes=$$(( total_size_bytes * target_free_percent / 100 ))
echo "Total size: $$total_size_bytes bytes"
echo "Target to free: $$target_free_bytes bytes"
# Convert base_files to an array for easier manipulation # Convert base_files to an array for easier manipulation
base_files_array=($$base_files) base_files_array=($$base_files)
# Step 3: Group files by prefix and block range, keeping only the last two block ranges # Step 3: Group files by prefix and block range, keeping only the last two block ranges
@@ -165,16 +151,11 @@ services:
done done
done done
done done
# Step 5: Calculate the space freed
freed_bytes=$$(du -cb "$$backup_dir"/* | tail -1 | awk '{print $$1}') freed_bytes=$$(du -cb "$$backup_dir"/* | tail -1 | awk '{print $$1}')
echo "Moved files to backup. Total freed: $$freed_bytes bytes." echo "Moved files to backup. Total freed: $$freed_bytes bytes."
echo "Done." echo "Done."
EOF - -c
RUN chmod +x /prune.sh - bash
environment:
- BACKUP_DIR=/data/static_files/delete_me
- DATA_DIR=/data/static_files
entrypoint: [/prune.sh] # Run the prune script manually
restart: no restart: no
volumes: volumes:
- /root/.local/share/reth:/data - /root/.local/share/reth:/data