A blockchain snapshot discovery and management system with S3 storage integration.
- Docker and Docker Compose installed
- S3-compatible storage credentials
- API keys for authentication
- Clone the repository
git clone <repository-url>
cd chainsnaps- Configure environment
# Copy the example environment file
cp .env.docker.example .env
# Edit .env with your S3 credentials- Start the services
# Build and start all services
docker-compose up -d
# Or use Make commands
make up- Initialize the system
# Check if registration is open
curl http://localhost:8000/api/v1/auth/status
# Register the first (and only) user - becomes admin automatically
curl -X POST http://localhost:8000/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "your_secure_password"}'
# After this, no other users can register
# Use these credentials to create and manage API keysThe API will be available at http://localhost:8000
Using Make:
make build # Build Docker images
make up # Start all services
make down # Stop all services
make restart # Restart all services
make logs # View logs from all services
make api-logs # View API logs only
make shell # Open shell in API container
make db-shell # Open PostgreSQL shell
make migrate # Run database migrations manually
make clean # Remove all containers and volumes
make scan # Trigger manual snapshot scanUsing Docker Compose directly:
docker-compose up -d # Start services
docker-compose down # Stop services
docker-compose logs -f api # View API logs
docker-compose exec api /bin/bash # API shell
docker-compose exec api alembic upgrade head # Run migrationsFor local development with hot reloading:
- Copy the override file:
cp docker-compose.override.yaml.example docker-compose.override.yaml- Start services (will mount local code):
docker-compose up-
API Service (FastAPI)
- REST API for snapshot management
- Automatic S3 scanning for snapshots
- API key authentication
- Background scanning service
-
PostgreSQL Database
- Stores snapshot metadata
- Tracks scan history
- Persistent volume for data
-
Automatic Discovery: On startup, the scanner searches S3 for snapshot directories containing
manifest-body.jsonandmanifest-header.jsonfiles -
Database Storage: Snapshot metadata is extracted and stored in PostgreSQL for fast querying
-
External Updates: Other processes can update snapshot metadata (block heights, blob data) via the API
-
Periodic Scanning: Background service rescans S3 periodically (default: every 6 hours)
# Register the admin user (only the first user can register)
curl -X POST http://localhost:8000/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "SecurePassword123"}'# Create an API key for the web app
curl -X POST http://localhost:8000/api/v1/auth/keys \
-u admin:SecurePassword123 \
-H "Content-Type: application/json" \
-d '{
"name": "Web App",
"description": "Frontend application key",
"scopes": ["snapshots:read"]
}'
# Create an API key for the metadata updater (with write permissions)
curl -X POST http://localhost:8000/api/v1/auth/keys \
-u admin:SecurePassword123 \
-H "Content-Type: application/json" \
-d '{
"name": "Metadata Updater",
"description": "External service for updating snapshot metadata",
"scopes": ["snapshots:read", "snapshots:write"]
}'
# Create an admin API key (can manage other keys)
curl -X POST http://localhost:8000/api/v1/auth/keys \
-u admin:SecurePassword123 \
-H "Content-Type: application/json" \
-d '{
"name": "Admin CLI",
"description": "Administrative access",
"scopes": ["admin", "snapshots:read", "snapshots:write"]
}'# Use an API key to access endpoints
curl http://localhost:8000/api/v1/snapshots \
-H "X-API-Key: csnp_your_api_key_here"When running, interactive API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
GET /health- Health check (no auth required)GET /api/v1/snapshots/- List snapshots with filteringGET /api/v1/snapshots/{id}- Get snapshot by IDPATCH /api/v1/snapshots/{id}- Update snapshot metadataPOST /api/v1/snapshots/scan- Trigger manual scan
All API endpoints (except /health) require an X-API-Key header.
Key environment variables:
S3_ACCESS_KEY_ID- S3 access key (required)S3_SECRET_ACCESS_KEY- S3 secret key (required)S3_BUCKET_NAME- S3 bucket name (required)API_KEYS- Comma-separated API keys (required)SCAN_ON_STARTUP- Auto-scan on startup (default: true)SCAN_INTERVAL_HOURS- Hours between scans (default: 6)
See .env.docker.example for all available options.
Migrations run automatically on container startup. To run manually:
# Using Make
make migrate
# Using Docker Compose
docker-compose exec api alembic upgrade head
# Create a new migration
docker-compose exec api alembic revision --autogenerate -m "Description"Check service health:
# Health endpoint (no auth)
curl http://localhost:8000/health
# With authentication
curl -H "X-API-Key: your_api_key" http://localhost:8000/api/v1/snapshots/View logs:
# All services
docker-compose logs -f
# API only
docker-compose logs -f api
# Database only
docker-compose logs -f postgresFor production:
- Use strong passwords and API keys
- Set
RELOAD=falsein environment - Consider using external PostgreSQL
- Add SSL/TLS termination (nginx/traefik)
- Set appropriate resource limits in docker-compose.yaml
- Use volume backups for PostgreSQL data
- Check PostgreSQL is healthy:
docker-compose ps - Check logs:
docker-compose logs api - Ensure S3 credentials are correct
- Check database connection:
docker-compose logs api - Manually connect:
make db-shell - Reset if needed:
make clean && make up
- Verify S3 bucket name and credentials
- Check scanner logs:
docker-compose logs api | grep scanner - Manually trigger scan:
make scan
[Your License Here]