optimizing badger cache, won a 10-15% improvement in most benchmarks

This commit is contained in:
2025-11-16 15:07:36 +00:00
parent 9bb3a7e057
commit 95bcf85ad7
72 changed files with 8158 additions and 4048 deletions

276
scripts/DGRAPH_TESTING.md Normal file
View File

@@ -0,0 +1,276 @@
# Dgraph Integration Testing
This directory contains scripts and configuration for testing the ORLY dgraph integration.
## Quick Start
### 1. Start Dgraph Server
```bash
# Using the convenience script
./scripts/dgraph-start.sh
# Or manually with docker-compose
cd scripts
docker-compose -f dgraph-docker-compose.yml up -d
# Or directly with docker
docker run -d \
-p 8080:8080 \
-p 9080:9080 \
-p 8000:8000 \
--name dgraph-orly \
dgraph/standalone:latest
```
### 2. Run Dgraph Tests
```bash
# Run all dgraph package tests
./scripts/test-dgraph.sh
# Run tests with relay-tester
./scripts/test-dgraph.sh --relay-tester
```
### 3. Manual Testing
```bash
# Start ORLY with dgraph backend
export ORLY_DB_TYPE=dgraph
export ORLY_DGRAPH_URL=localhost:9080
./orly
# In another terminal, run relay-tester
go run cmd/relay-tester/main.go -url ws://localhost:3334
```
## Test Files
The dgraph package includes comprehensive tests:
- **testmain_test.go** - Test configuration and logging setup
- **helpers_test.go** - Helper functions for test setup/teardown
- **save-event_test.go** - Event storage tests
- **query-events_test.go** - Event query tests
All tests mirror the existing badger tests to ensure feature parity.
## Test Coverage
The dgraph tests cover:
**Event Storage**
- Saving events from examples.Cache
- Duplicate event rejection
- Deletion event validation
**Event Queries**
- Query by ID
- Query by kind
- Query by author
- Query by time range
- Query by tags
- Event counting
**Advanced Features**
- Replaceable events (kind 0)
- Parameterized replaceable events (kind 30000+)
- Event deletion (kind 5)
- Event replacement logic
## Requirements
### Dgraph Server
The tests require a running dgraph server. Tests will be skipped if dgraph is not available.
**Endpoints:**
- gRPC: `localhost:9080` (required for ORLY)
- HTTP: `localhost:8080` (for health checks)
- Ratel UI: `localhost:8000` (optional, for debugging)
**Custom Endpoint:**
```bash
export ORLY_DGRAPH_URL=remote.server.com:9080
./scripts/test-dgraph.sh
```
### Docker
The docker-compose setup requires:
- Docker Engine 20.10+
- Docker Compose 1.29+ (or docker-compose plugin)
## Test Workflow
### Running Tests Locally
```bash
# 1. Start dgraph
./scripts/dgraph-start.sh
# 2. Run tests
./scripts/test-dgraph.sh
# 3. Clean up when done
cd scripts && docker-compose -f dgraph-docker-compose.yml down
```
### CI/CD Integration
For CI pipelines, use the docker-compose file:
```yaml
# Example GitHub Actions workflow
services:
dgraph:
image: dgraph/standalone:latest
ports:
- 8080:8080
- 9080:9080
steps:
- name: Run dgraph tests
run: |
export ORLY_DGRAPH_URL=localhost:9080
CGO_ENABLED=0 go test -v ./pkg/dgraph/...
```
## Debugging
### View Dgraph Logs
```bash
docker logs dgraph-orly-test -f
```
### Access Ratel UI
Open http://localhost:8000 in your browser to:
- View schema
- Run DQL queries
- Inspect data
### Enable Test Logging
```bash
export TEST_LOG=1
./scripts/test-dgraph.sh
```
### Manual DQL Queries
```bash
# Using curl
curl -X POST localhost:8080/query -d '{
q(func: type(Event)) {
uid
event.id
event.kind
event.created_at
}
}'
# Using grpcurl (if installed)
grpcurl -plaintext -d '{
"query": "{ q(func: type(Event)) { uid event.id } }"
}' localhost:9080 api.Dgraph/Query
```
## Troubleshooting
### Tests Skip with "Dgraph server not available"
**Solution:** Ensure dgraph is running:
```bash
docker ps | grep dgraph
./scripts/dgraph-start.sh
```
### Connection Refused Errors
**Symptoms:**
```
failed to connect to dgraph at localhost:9080: connection refused
```
**Solutions:**
1. Check dgraph is running: `docker ps`
2. Check port mapping: `docker port dgraph-orly-test`
3. Check firewall rules
4. Verify ORLY_DGRAPH_URL is correct
### Schema Application Failed
**Symptoms:**
```
failed to apply schema: ...
```
**Solutions:**
1. Check dgraph logs: `docker logs dgraph-orly-test`
2. Drop all data and retry: Use `dropAll` in test setup
3. Verify dgraph version compatibility
### Tests Timeout
**Symptoms:**
```
panic: test timed out after 10m
```
**Solutions:**
1. Increase timeout: `go test -timeout 20m ./pkg/dgraph/...`
2. Check dgraph performance: May need more resources
3. Reduce test dataset size
## Performance Benchmarks
Compare dgraph vs badger performance:
```bash
# Run badger benchmarks
go test -bench=. ./pkg/database/...
# Run dgraph benchmarks
go test -bench=. ./pkg/dgraph/...
```
## Test Data
Tests use `pkg/encoders/event/examples.Cache` which contains:
- ~100 real Nostr events
- Various kinds (text notes, metadata, etc.)
- Different authors and timestamps
- Events with tags and relationships
## Cleanup
### Remove Test Data
```bash
# Stop and remove containers
cd scripts
docker-compose -f dgraph-docker-compose.yml down
# Remove volumes
docker volume rm scripts_dgraph-data
```
### Reset Dgraph
```bash
# Drop all data (via test helper)
# The dropAll() function is called in test setup
# Or manually via HTTP
curl -X POST localhost:8080/alter -d '{"drop_all": true}'
```
## Related Documentation
- [Dgraph Implementation Status](../DGRAPH_IMPLEMENTATION_STATUS.md)
- [Package README](../pkg/dgraph/README.md)
- [Dgraph Documentation](https://dgraph.io/docs/)
- [DQL Query Language](https://dgraph.io/docs/query-language/)

546
scripts/DOCKER_TESTING.md Normal file
View File

@@ -0,0 +1,546 @@
# Docker-Based Integration Testing
This guide covers running ORLY and Dgraph together in Docker containers for integration testing.
## Overview
The Docker setup provides:
- **Isolated Environment**: Dgraph + ORLY in containers
- **Automated Testing**: Health checks and dependency management
- **Reproducible Tests**: Consistent environment across systems
- **Easy Cleanup**: Remove everything with one command
## Architecture
```
┌─────────────────────────────────────────────┐
│ Docker Network (orly-network) │
│ │
│ ┌──────────────────┐ ┌─────────────────┐ │
│ │ Dgraph │ │ ORLY Relay │ │
│ │ standalone │◄─┤ (dgraph mode) │ │
│ │ │ │ │ │
│ │ :8080 (HTTP) │ │ :3334 (WS) │ │
│ │ :9080 (gRPC) │ │ │ │
│ │ :8000 (Ratel) │ │ │ │
│ └──────────────────┘ └─────────────────┘ │
│ │ │ │
└─────────┼───────────────────────┼───────────┘
│ │
Published Published
to host to host
```
## Quick Start
### 1. Build Images
```bash
# Build ORLY image only
./scripts/docker-build.sh
# Build ORLY + relay-tester
./scripts/docker-build.sh --with-tester
```
### 2. Run Integration Tests
```bash
# Basic test (start containers, verify connectivity)
./scripts/test-docker.sh
# Run with relay-tester
./scripts/test-docker.sh --relay-tester
# Keep containers running after test
./scripts/test-docker.sh --keep-running
# Skip rebuild (use existing images)
./scripts/test-docker.sh --skip-build
```
### 3. Manual Container Management
```bash
# Start containers
cd scripts
docker-compose -f docker-compose-test.yml up -d
# View logs
docker-compose -f docker-compose-test.yml logs -f
# Stop containers
docker-compose -f docker-compose-test.yml down
# Stop and remove volumes
docker-compose -f docker-compose-test.yml down -v
```
## Docker Files
### Dockerfile
Multi-stage build for ORLY:
**Stage 1: Builder**
- Based on golang:1.21-alpine
- Downloads dependencies
- Builds static binary with `CGO_ENABLED=0`
- Copies libsecp256k1.so for crypto operations
**Stage 2: Runtime**
- Based on alpine:latest (minimal)
- Copies binary and shared library
- Creates non-root user
- Sets up health checks
- ~50MB final image size
### Dockerfile.relay-tester
Builds relay-tester for automated testing:
- Static binary from cmd/relay-tester
- Configurable RELAY_URL
- Runs as part of test profile
### docker-compose-test.yml
Orchestrates the full stack:
**Services:**
1. **dgraph** - Database backend
- Health check via HTTP
- Persistent volume for data
- Exposed ports for debugging
2. **orly** - Relay server
- Depends on dgraph (waits for healthy)
- Configured with ORLY_DB_TYPE=dgraph
- Health check via HTTP
- Auto-restart on failure
3. **relay-tester** - Test runner
- Profile: test (optional)
- Runs tests against ORLY
- Exits after completion
## Configuration
### Environment Variables
The docker-compose file sets:
```yaml
# Database
ORLY_DB_TYPE: dgraph
ORLY_DGRAPH_URL: dgraph:9080 # Internal network name
# Server
ORLY_LISTEN: 0.0.0.0
ORLY_PORT: 3334
ORLY_DATA_DIR: /data
# Application
ORLY_LOG_LEVEL: info
ORLY_APP_NAME: ORLY-Dgraph-Test
ORLY_ACL_MODE: none
```
Override via environment or .env file:
```bash
# Create .env file in scripts/
cat > scripts/.env << EOF
ORLY_LOG_LEVEL=debug
ORLY_ADMINS=npub1...
EOF
```
### Volumes
**Persistent Data:**
- `dgraph-data:/dgraph` - Dgraph database
- `orly-data:/data` - ORLY metadata
**Inspect Volumes:**
```bash
docker volume ls
docker volume inspect scripts_dgraph-data
```
### Networks
**Custom Bridge Network:**
- Name: orly-network
- Subnet: 172.28.0.0/16
- Allows container-to-container communication
- DNS resolution by service name
## Testing Workflows
### Basic Integration Test
```bash
./scripts/test-docker.sh
```
**What it does:**
1. Stops any existing containers
2. Starts dgraph and waits for health
3. Starts ORLY and waits for health
4. Verifies HTTP connectivity
5. Tests WebSocket (if websocat installed)
6. Shows container status
7. Cleans up (unless --keep-running)
### With Relay-Tester
```bash
./scripts/test-docker.sh --relay-tester
```
**Additional steps:**
1. Builds relay-tester image
2. Runs comprehensive protocol tests
3. Reports pass/fail
4. Shows ORLY logs on failure
### Development Workflow
```bash
# Start and keep running
./scripts/test-docker.sh --keep-running
# Make changes to code
vim pkg/dgraph/save-event.go
# Rebuild and restart
docker-compose -f scripts/docker-compose-test.yml up -d --build orly
# View logs
docker logs orly-relay -f
# Test changes
go run cmd/relay-tester/main.go -url ws://localhost:3334
# Stop when done
cd scripts && docker-compose -f docker-compose-test.yml down
```
## Debugging
### View Container Logs
```bash
# All services
docker-compose -f scripts/docker-compose-test.yml logs -f
# Specific service
docker logs orly-relay -f
docker logs orly-dgraph -f
# Last N lines
docker logs orly-relay --tail 50
```
### Execute Commands in Container
```bash
# ORLY version
docker exec orly-relay /app/orly version
# Check ORLY processes
docker exec orly-relay ps aux
# Inspect data directory
docker exec orly-relay ls -la /data
# Query dgraph
docker exec orly-dgraph curl http://localhost:8080/health
```
### Access Ratel UI
Open http://localhost:8000 in browser:
- View dgraph schema
- Run DQL queries
- Inspect stored data
- Monitor performance
### Network Inspection
```bash
# List networks
docker network ls
# Inspect orly network
docker network inspect scripts_orly-network
# Test connectivity
docker exec orly-relay ping dgraph
docker exec orly-relay nc -zv dgraph 9080
```
### Health Check Status
```bash
# Check health
docker inspect orly-relay | grep -A 10 Health
# View health check logs
docker inspect --format='{{json .State.Health}}' orly-relay | jq
```
## Troubleshooting
### Build Failures
**Error: Cannot find libsecp256k1.so**
```bash
# Ensure library exists
ls -l pkg/crypto/p8k/libsecp256k1.so
# Rebuild if needed
cd pkg/crypto/p8k && make
```
**Error: Go module download fails**
```bash
# Clear module cache
go clean -modcache
# Try building locally first
CGO_ENABLED=0 go build
```
### Runtime Failures
**ORLY fails health check**
```bash
# Check logs
docker logs orly-relay
# Common issues:
# - Port already in use: docker ps (check for conflicts)
# - Dgraph not ready: docker logs orly-dgraph
# - Bad configuration: docker exec orly-relay env
```
**Cannot connect to dgraph**
```bash
# Verify dgraph is healthy
docker inspect orly-dgraph | grep Health
# Check network connectivity
docker exec orly-relay ping dgraph
docker exec orly-relay nc -zv dgraph 9080
# Verify dgraph is listening
docker exec orly-dgraph netstat -tlnp | grep 9080
```
**WebSocket connection fails**
```bash
# Test from host
websocat ws://localhost:3334
# Test from container
docker exec orly-relay curl -v http://localhost:3334
# Check firewall
sudo iptables -L | grep 3334
```
### Performance Issues
**Slow startup**
```bash
# Increase health check timeouts in docker-compose-test.yml
start_period: 60s # Default is 20-30s
# Pre-pull images
docker pull dgraph/standalone:latest
docker pull golang:1.21-alpine
```
**High memory usage**
```bash
# Check resource usage
docker stats
# Limit container resources
# Add to docker-compose-test.yml:
deploy:
resources:
limits:
memory: 2G
cpus: '2'
```
## CI/CD Integration
### GitHub Actions Example
```yaml
name: Docker Integration Tests
on: [push, pull_request]
jobs:
docker-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build images
run: ./scripts/docker-build.sh --with-tester
- name: Run integration tests
run: ./scripts/test-docker.sh --relay-tester
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v3
with:
name: container-logs
path: |
scripts/orly-relay.log
scripts/dgraph.log
```
### GitLab CI Example
```yaml
docker-test:
image: docker:latest
services:
- docker:dind
script:
- ./scripts/docker-build.sh --with-tester
- ./scripts/test-docker.sh --relay-tester
artifacts:
when: on_failure
paths:
- scripts/*.log
```
## Advanced Usage
### Custom Configuration
Create a custom docker-compose override:
```yaml
# docker-compose.override.yml
version: '3.8'
services:
orly:
environment:
- ORLY_LOG_LEVEL=debug
- ORLY_ADMINS=npub1...
- ORLY_ACL_MODE=follows
ports:
- "3335:3334" # Different host port
```
### Multi-Instance Testing
Test multiple ORLY instances:
```yaml
# docker-compose-multi.yml
services:
orly-1:
extends:
file: docker-compose-test.yml
service: orly
container_name: orly-relay-1
ports:
- "3334:3334"
orly-2:
extends:
file: docker-compose-test.yml
service: orly
container_name: orly-relay-2
ports:
- "3335:3334"
```
### Performance Benchmarking
```bash
# Start with --keep-running
./scripts/test-docker.sh --keep-running
# Run stress test
go run cmd/stresstest/main.go -url ws://localhost:3334 -connections 100
# Monitor resources
docker stats
# Profile ORLY
docker exec orly-relay sh -c 'curl http://localhost:6060/debug/pprof/profile?seconds=30 > /tmp/cpu.prof'
```
## Cleanup
### Remove Everything
```bash
# Stop and remove containers
cd scripts && docker-compose -f docker-compose-test.yml down
# Remove volumes (data)
docker-compose -f docker-compose-test.yml down -v
# Remove images
docker rmi orly:latest orly-relay-tester:latest
# Remove networks
docker network rm scripts_orly-network
# Prune everything (careful!)
docker system prune -a --volumes
```
### Selective Cleanup
```bash
# Just stop containers (keep data)
docker-compose -f docker-compose-test.yml stop
# Remove only one service
docker-compose -f docker-compose-test.yml rm -s -f orly
# Clear dgraph data
docker volume rm scripts_dgraph-data
```
## Related Documentation
- [Main Testing Guide](DGRAPH_TESTING.md)
- [Package Tests](../pkg/dgraph/TESTING.md)
- [Docker Documentation](https://docs.docker.com/)
- [Docker Compose](https://docs.docker.com/compose/)
## Best Practices
1. **Always use health checks** - Ensure services are ready
2. **Use specific tags** - Don't rely on :latest in production
3. **Limit resources** - Prevent container resource exhaustion
4. **Volume backups** - Backup dgraph-data volume before updates
5. **Network isolation** - Use custom networks for security
6. **Read-only root** - Run as non-root user
7. **Clean up regularly** - Remove unused containers/volumes

424
scripts/README.md Normal file
View File

@@ -0,0 +1,424 @@
# ORLY Scripts Directory
This directory contains automation scripts for building, testing, and deploying ORLY.
## Quick Reference
### Dgraph Integration Testing
```bash
# Local testing (requires dgraph server)
./dgraph-start.sh # Start dgraph server
./test-dgraph.sh # Run dgraph package tests
./test-dgraph.sh --relay-tester # Run tests + relay-tester
# Docker testing (containers for everything)
./docker-build.sh # Build ORLY docker image
./test-docker.sh # Run integration tests in containers
./test-docker.sh --relay-tester --keep-running # Full test, keep running
```
### Build & Deploy
```bash
./build-all-platforms.sh # Build for multiple platforms
./deploy.sh # Deploy to systemd
./update-embedded-web.sh # Build and embed web UI
```
## Script Descriptions
### Dgraph Testing Scripts
#### dgraph-start.sh
Starts dgraph server using docker-compose for local testing.
**Usage:**
```bash
./dgraph-start.sh
```
**What it does:**
- Checks if dgraph is already running
- Starts dgraph via docker-compose
- Waits for health check
- Shows endpoints and commands
#### dgraph-docker-compose.yml
Docker Compose configuration for standalone dgraph server.
**Ports:**
- 8080: HTTP API
- 9080: gRPC (ORLY connects here)
- 8000: Ratel UI
#### test-dgraph.sh
Runs dgraph package tests against a running dgraph server.
**Usage:**
```bash
./test-dgraph.sh # Just tests
./test-dgraph.sh --relay-tester # Tests + relay-tester
```
**Requirements:**
- Dgraph server running at ORLY_DGRAPH_URL (default: localhost:9080)
- Go 1.21+
### Docker Integration Scripts
#### docker-build.sh
Builds Docker images for ORLY and optionally relay-tester.
**Usage:**
```bash
./docker-build.sh # ORLY only
./docker-build.sh --with-tester # ORLY + relay-tester
```
**Output:**
- orly:latest
- orly-relay-tester:latest (if --with-tester)
#### docker-compose-test.yml
Full-stack docker-compose with dgraph, ORLY, and relay-tester.
**Services:**
- dgraph: Database backend
- orly: Relay with dgraph backend
- relay-tester: Protocol tests (optional, profile: test)
**Features:**
- Health checks for all services
- Dependency management (ORLY waits for dgraph)
- Custom network with DNS
- Persistent volumes
#### test-docker.sh
Comprehensive integration testing in Docker containers.
**Usage:**
```bash
./test-docker.sh # Basic test
./test-docker.sh --relay-tester # Run relay-tester
./test-docker.sh --keep-running # Keep containers running
./test-docker.sh --skip-build # Use existing images
./test-docker.sh --relay-tester --keep-running # Full test + keep running
```
**What it does:**
1. Stops any existing containers
2. Optionally rebuilds images
3. Starts dgraph and waits for health
4. Starts ORLY and waits for health
5. Verifies connectivity
6. Optionally runs relay-tester
7. Shows status and endpoints
8. Cleanup (unless --keep-running)
### Build Scripts
#### build-all-platforms.sh
Cross-compiles ORLY for multiple platforms.
**Platforms:**
- linux/amd64
- linux/arm64
- darwin/amd64
- darwin/arm64
**Output:** `dist/` directory with platform-specific binaries
#### update-embedded-web.sh
Builds the Svelte web UI and embeds it in ORLY binary.
**Steps:**
1. Builds web UI with bun
2. Generates embedded assets
3. Rebuilds ORLY with embedded UI
### Deployment Scripts
#### deploy.sh
Automated deployment with systemd service.
**What it does:**
1. Installs Go if needed
2. Builds ORLY with embedded web UI
3. Installs to ~/.local/bin/orly
4. Creates systemd service
5. Enables and starts service
6. Sets up port binding capabilities
### Test Scripts
#### test.sh
Runs all Go tests in the project.
**Usage:**
```bash
./test.sh # All tests
TEST_LOG=1 ./test.sh # With logging
```
## Environment Variables
### Common Variables
```bash
# Dgraph
export ORLY_DGRAPH_URL=localhost:9080 # Dgraph endpoint
export ORLY_DB_TYPE=dgraph # Use dgraph backend
# Logging
export ORLY_LOG_LEVEL=debug # Log verbosity
export TEST_LOG=1 # Enable test logging
# Server
export ORLY_PORT=3334 # HTTP/WebSocket port
export ORLY_LISTEN=0.0.0.0 # Listen address
# Data
export ORLY_DATA_DIR=/path/to/data # Data directory
```
### Script-Specific Variables
```bash
# Docker scripts
export SKIP_BUILD=true # Skip image rebuild
export KEEP_RUNNING=true # Don't cleanup containers
# Dgraph scripts
export DGRAPH_VERSION=latest # Dgraph image tag
```
## File Organization
```
scripts/
├── README.md # This file
├── DGRAPH_TESTING.md # Dgraph testing guide
├── DOCKER_TESTING.md # Docker testing guide
├── dgraph-start.sh # Start dgraph server
├── dgraph-docker-compose.yml # Dgraph docker config
├── test-dgraph.sh # Run dgraph tests
├── docker-build.sh # Build docker images
├── docker-compose-test.yml # Full stack docker config
├── test-docker.sh # Run docker integration tests
├── build-all-platforms.sh # Cross-compile
├── deploy.sh # Deploy to systemd
├── update-embedded-web.sh # Build web UI
└── test.sh # Run Go tests
```
## Workflows
### Local Development with Dgraph
```bash
# 1. Start dgraph
./scripts/dgraph-start.sh
# 2. Run ORLY locally with dgraph
export ORLY_DB_TYPE=dgraph
export ORLY_DGRAPH_URL=localhost:9080
./orly
# 3. Test changes
go run cmd/relay-tester/main.go -url ws://localhost:3334
# 4. Run unit tests
./scripts/test-dgraph.sh
```
### Docker Development
```bash
# 1. Make changes
vim pkg/dgraph/save-event.go
# 2. Build and test in containers
./scripts/test-docker.sh --relay-tester --keep-running
# 3. Make more changes
# 4. Rebuild just ORLY
cd scripts
docker-compose -f docker-compose-test.yml up -d --build orly
# 5. View logs
docker logs orly-relay -f
# 6. Stop when done
docker-compose -f docker-compose-test.yml down
```
### CI/CD Testing
```bash
# Quick test (no containers)
./scripts/test.sh
# Full integration test
./scripts/test-docker.sh --relay-tester
# Build for deployment
./scripts/build-all-platforms.sh
```
### Production Deployment
```bash
# Deploy with systemd
./scripts/deploy.sh
# Check status
systemctl status orly
# View logs
journalctl -u orly -f
# Update
./scripts/deploy.sh # Rebuilds and restarts
```
## Troubleshooting
### Dgraph Not Available
```bash
# Check if running
docker ps | grep dgraph
# Start it
./scripts/dgraph-start.sh
# Check logs
docker logs dgraph-orly-test -f
```
### Port Conflicts
```bash
# Find what's using port 3334
lsof -i :3334
netstat -tlnp | grep 3334
# Kill process
kill $(lsof -t -i :3334)
# Or use different port
export ORLY_PORT=3335
```
### Docker Build Failures
```bash
# Clear docker cache
docker builder prune
# Rebuild from scratch
docker build --no-cache -t orly:latest -f Dockerfile .
# Check Dockerfile syntax
docker build --dry-run -f Dockerfile .
```
### Permission Issues
```bash
# Fix script permissions
chmod +x scripts/*.sh
# Fix docker socket
sudo usermod -aG docker $USER
newgrp docker
```
## Best Practices
1. **Always use scripts from project root**
```bash
./scripts/test-docker.sh # Good
cd scripts && ./test-docker.sh # May have path issues
```
2. **Check prerequisites before running**
```bash
# Check docker
docker --version
docker-compose --version
# Check dgraph
curl http://localhost:9080/health
```
3. **Clean up after testing**
```bash
# Stop containers
cd scripts && docker-compose -f docker-compose-test.yml down
# Remove volumes if needed
docker-compose -f docker-compose-test.yml down -v
```
4. **Use --keep-running for debugging**
```bash
./scripts/test-docker.sh --keep-running
# Inspect, debug, make changes
docker-compose -f scripts/docker-compose-test.yml down
```
5. **Check logs on failures**
```bash
# Container logs
docker logs orly-relay --tail 100
# Test output
./scripts/test-dgraph.sh 2>&1 | tee test.log
```
## Related Documentation
- [Dgraph Testing Guide](DGRAPH_TESTING.md)
- [Docker Testing Guide](DOCKER_TESTING.md)
- [Package Tests](../pkg/dgraph/TESTING.md)
- [Main Implementation Status](../DGRAPH_IMPLEMENTATION_STATUS.md)
## Contributing
When adding new scripts:
1. **Add executable permission**
```bash
chmod +x scripts/new-script.sh
```
2. **Use bash strict mode**
```bash
#!/bin/bash
set -e # Exit on error
```
3. **Add help text**
```bash
if [ "$1" == "--help" ]; then
echo "Usage: $0 [options]"
exit 0
fi
```
4. **Document in this README**
- Add to appropriate section
- Include usage examples
- Note any requirements
5. **Test on fresh system**
```bash
# Use Docker to test
docker run --rm -v $(pwd):/app -w /app ubuntu:latest ./scripts/new-script.sh
```

View File

@@ -0,0 +1,25 @@
version: '3.8'
services:
dgraph:
image: dgraph/standalone:latest
container_name: dgraph-orly-test
ports:
- "8080:8080" # HTTP API
- "9080:9080" # gRPC
- "8000:8000" # Ratel UI
volumes:
- dgraph-data:/dgraph
environment:
- DGRAPH_ALPHA_JAEGER_COLLECTOR=false
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 10s
timeout: 5s
retries: 5
start_period: 20s
volumes:
dgraph-data:
driver: local

50
scripts/dgraph-start.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/bash
# Quick script to start dgraph for testing
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "Starting dgraph server for ORLY testing..."
cd "$SCRIPT_DIR"
# Check if already running
if docker ps | grep -q dgraph-orly-test; then
echo "✅ Dgraph is already running"
echo ""
echo "Dgraph endpoints:"
echo " gRPC: localhost:9080"
echo " HTTP: http://localhost:8080"
echo " Ratel UI: http://localhost:8000"
exit 0
fi
# Determine docker-compose command
if docker compose version &> /dev/null 2>&1; then
DOCKER_COMPOSE="docker compose"
else
DOCKER_COMPOSE="docker-compose"
fi
# Start using docker compose
$DOCKER_COMPOSE -f dgraph-docker-compose.yml up -d
echo ""
echo "Waiting for dgraph to be healthy..."
for i in {1..30}; do
if docker exec dgraph-orly-test curl -sf http://localhost:8080/health > /dev/null 2>&1; then
echo "✅ Dgraph is healthy and ready"
echo ""
echo "Dgraph endpoints:"
echo " gRPC: localhost:9080"
echo " HTTP: http://localhost:8080"
echo " Ratel UI: http://localhost:8000"
echo ""
echo "To stop: $DOCKER_COMPOSE -f dgraph-docker-compose.yml down"
echo "To view logs: docker logs dgraph-orly-test -f"
exit 0
fi
sleep 1
done
echo "❌ Dgraph failed to become healthy"
docker logs dgraph-orly-test
exit 1

45
scripts/docker-build.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
echo "=== Building ORLY Docker Images ==="
echo ""
# Change to project root
cd "$PROJECT_ROOT"
# Determine docker-compose command
if docker compose version &> /dev/null 2>&1; then
DOCKER_COMPOSE="docker compose"
else
DOCKER_COMPOSE="docker-compose"
fi
# Build ORLY image
echo "Building ORLY relay image..."
docker build -t orly:latest -f Dockerfile .
echo "✅ ORLY image built successfully"
echo ""
# Build relay-tester image (optional)
if [ "$1" == "--with-tester" ]; then
echo "Building relay-tester image..."
docker build -t orly-relay-tester:latest -f Dockerfile.relay-tester .
echo "✅ Relay-tester image built successfully"
echo ""
fi
# Show images
echo "Built images:"
docker images | grep -E "orly|REPOSITORY"
echo ""
echo "=== Build Complete ==="
echo ""
echo "To run:"
echo " cd scripts && $DOCKER_COMPOSE -f docker-compose-test.yml up -d"
echo ""
echo "To test:"
echo " ./scripts/test-docker.sh"

View File

@@ -0,0 +1,93 @@
version: '3.8'
services:
# Dgraph database
dgraph:
image: dgraph/standalone:latest
container_name: orly-dgraph
ports:
- "8080:8080" # HTTP API
- "9080:9080" # gRPC (ORLY connects here)
- "8000:8000" # Ratel UI
volumes:
- dgraph-data:/dgraph
environment:
- DGRAPH_ALPHA_JAEGER_COLLECTOR=false
networks:
- orly-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 10s
timeout: 5s
retries: 5
start_period: 20s
# ORLY relay with dgraph backend
orly:
build:
context: ..
dockerfile: Dockerfile
container_name: orly-relay
ports:
- "3334:3334" # WebSocket/HTTP
depends_on:
dgraph:
condition: service_healthy
environment:
# Database configuration
- ORLY_DB_TYPE=dgraph
- ORLY_DGRAPH_URL=dgraph:9080
- ORLY_DATA_DIR=/data
# Server configuration
- ORLY_LISTEN=0.0.0.0
- ORLY_PORT=3334
- ORLY_LOG_LEVEL=info
- ORLY_APP_NAME=ORLY-Dgraph-Test
# Admin configuration (example)
- ORLY_ADMINS=npub1fjqqy4a93z5zsjwsfxqhc2764kvykfdyttvldkkkdera8dr78vhsmmleku
- ORLY_OWNERS=npub1fjqqy4a93z5zsjwsfxqhc2764kvykfdyttvldkkkdera8dr78vhsmmleku
# ACL mode
- ORLY_ACL_MODE=none
volumes:
- orly-data:/data
networks:
- orly-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3334/"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
restart: unless-stopped
# Relay tester (optional, for automated testing)
relay-tester:
build:
context: ..
dockerfile: Dockerfile.relay-tester
container_name: orly-tester
depends_on:
orly:
condition: service_healthy
environment:
- RELAY_URL=ws://orly:3334
networks:
- orly-network
profiles:
- test
networks:
orly-network:
driver: bridge
ipam:
config:
- subnet: 172.28.0.0/16
volumes:
dgraph-data:
driver: local
orly-data:
driver: local

308
scripts/migrate-badger-config.sh Executable file
View File

@@ -0,0 +1,308 @@
#!/bin/bash
# Badger Database Migration Script
# Migrates ORLY database to new Badger configuration with VLogPercentile optimization
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}=== ORLY Badger Database Migration ===${NC}"
echo ""
# Configuration
DATA_DIR="${ORLY_DATA_DIR:-$HOME/.local/share/ORLY}"
BACKUP_DIR="${DATA_DIR}-backup-$(date +%Y%m%d-%H%M%S)"
EXPORT_FILE="${DATA_DIR}/events-export.jsonl"
RELAY_BIN="${RELAY_BIN:-./orly}"
# Check if relay binary exists
if [ ! -f "$RELAY_BIN" ]; then
echo -e "${RED}Error: ORLY binary not found at $RELAY_BIN${NC}"
echo "Please build the relay first: go build -o orly"
echo "Or set RELAY_BIN environment variable to the binary location"
exit 1
fi
# Check if database exists
if [ ! -d "$DATA_DIR" ]; then
echo -e "${YELLOW}Warning: Database directory not found at $DATA_DIR${NC}"
echo "Nothing to migrate. If this is a fresh install, you can skip migration."
exit 0
fi
# Check disk space
DB_SIZE=$(du -sb "$DATA_DIR" | cut -f1)
AVAILABLE_SPACE=$(df "$HOME" | tail -1 | awk '{print $4}')
AVAILABLE_SPACE=$((AVAILABLE_SPACE * 1024)) # Convert to bytes
REQUIRED_SPACE=$((DB_SIZE * 3)) # 3x for safety (export + backup + new DB)
echo "Database size: $(numfmt --to=iec-i --suffix=B $DB_SIZE)"
echo "Available space: $(numfmt --to=iec-i --suffix=B $AVAILABLE_SPACE)"
echo "Required space: $(numfmt --to=iec-i --suffix=B $REQUIRED_SPACE)"
echo ""
if [ $AVAILABLE_SPACE -lt $REQUIRED_SPACE ]; then
echo -e "${RED}Error: Not enough disk space!${NC}"
echo "Required: $(numfmt --to=iec-i --suffix=B $REQUIRED_SPACE)"
echo "Available: $(numfmt --to=iec-i --suffix=B $AVAILABLE_SPACE)"
echo ""
echo "Options:"
echo " 1. Free up disk space"
echo " 2. Use natural compaction (no migration needed)"
echo " 3. Export to external drive and import back"
exit 1
fi
# Check if relay is running
if pgrep -x "orly" > /dev/null; then
echo -e "${YELLOW}Warning: ORLY relay is currently running${NC}"
echo "The relay should be stopped before migration."
echo ""
read -p "Stop the relay now? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Attempting to stop relay..."
if systemctl is-active --quiet orly; then
sudo systemctl stop orly
echo -e "${GREEN}Relay stopped via systemd${NC}"
else
pkill orly
sleep 2
if pgrep -x "orly" > /dev/null; then
echo -e "${RED}Failed to stop relay. Please stop it manually and try again.${NC}"
exit 1
fi
echo -e "${GREEN}Relay stopped${NC}"
fi
else
echo "Please stop the relay and run this script again."
exit 1
fi
fi
echo ""
echo -e "${YELLOW}=== Migration Plan ===${NC}"
echo "1. Export all events to JSONL: $EXPORT_FILE"
echo "2. Backup current database to: $BACKUP_DIR"
echo "3. Create new database with optimized configuration"
echo "4. Import all events (rebuilds indexes)"
echo "5. Verify event counts match"
echo ""
echo "Estimated time: $(( (DB_SIZE / 1024 / 1024 / 100) + 1 )) - $(( (DB_SIZE / 1024 / 1024 / 50) + 1 )) minutes"
echo ""
read -p "Proceed with migration? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Migration cancelled."
exit 0
fi
# Step 1: Export events
echo ""
echo -e "${GREEN}=== Step 1: Exporting Events ===${NC}"
echo "This may take several minutes for large databases..."
echo ""
# We'll use a Go program to export since the binary doesn't have a CLI export command
# Create temporary export program
EXPORT_PROG=$(mktemp -d)/export-db.go
cat > "$EXPORT_PROG" << 'EOF'
package main
import (
"context"
"fmt"
"os"
"next.orly.dev/pkg/database"
)
func main() {
if len(os.Args) < 3 {
fmt.Fprintf(os.Stderr, "Usage: %s <data-dir> <output-file>\n", os.Args[0])
os.Exit(1)
}
dataDir := os.Args[1]
outFile := os.Args[2]
ctx := context.Background()
cancel := func() {}
db, err := database.New(ctx, cancel, dataDir, "error")
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to open database: %v\n", err)
os.Exit(1)
}
defer db.Close()
f, err := os.Create(outFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create output file: %v\n", err)
os.Exit(1)
}
defer f.Close()
fmt.Println("Exporting events...")
db.Export(ctx, f)
fmt.Println("Export complete!")
}
EOF
# Build and run export program
echo "Building export tool..."
EXPORT_BIN=$(mktemp)
if ! go build -o "$EXPORT_BIN" "$EXPORT_PROG" 2>&1; then
echo -e "${RED}Failed to build export tool${NC}"
rm -f "$EXPORT_PROG" "$EXPORT_BIN"
exit 1
fi
echo "Running export..."
if ! "$EXPORT_BIN" "$DATA_DIR" "$EXPORT_FILE"; then
echo -e "${RED}Export failed!${NC}"
rm -f "$EXPORT_PROG" "$EXPORT_BIN"
exit 1
fi
rm -f "$EXPORT_PROG" "$EXPORT_BIN"
# Count exported events
EXPORT_COUNT=$(wc -l < "$EXPORT_FILE")
echo -e "${GREEN}Exported $EXPORT_COUNT events${NC}"
echo "Export size: $(du -h "$EXPORT_FILE" | cut -f1)"
# Step 2: Backup current database
echo ""
echo -e "${GREEN}=== Step 2: Backing Up Current Database ===${NC}"
echo "Moving $DATA_DIR to $BACKUP_DIR"
mv "$DATA_DIR" "$BACKUP_DIR"
echo -e "${GREEN}Backup complete${NC}"
# Step 3 & 4: Create new database and import
echo ""
echo -e "${GREEN}=== Step 3 & 4: Creating New Database and Importing ===${NC}"
echo "This will take longer as indexes are rebuilt..."
echo ""
# Create temporary import program
IMPORT_PROG=$(mktemp -d)/import-db.go
cat > "$IMPORT_PROG" << 'EOF'
package main
import (
"context"
"fmt"
"os"
"next.orly.dev/pkg/database"
)
func main() {
if len(os.Args) < 3 {
fmt.Fprintf(os.Stderr, "Usage: %s <data-dir> <import-file>\n", os.Args[0])
os.Exit(1)
}
dataDir := os.Args[1]
importFile := os.Args[2]
ctx := context.Background()
cancel := func() {}
// This will create new database with updated configuration from database.go
db, err := database.New(ctx, cancel, dataDir, "info")
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create database: %v\n", err)
os.Exit(1)
}
defer db.Close()
f, err := os.Open(importFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to open import file: %v\n", err)
os.Exit(1)
}
defer f.Close()
fmt.Println("Importing events (this may take a while)...")
db.Import(f)
// Wait for import to complete
fmt.Println("Import started. Waiting for completion...")
fmt.Println("Check the log output above for progress (logged every 100 events)")
}
EOF
# Build and run import program
echo "Building import tool..."
IMPORT_BIN=$(mktemp)
if ! go build -o "$IMPORT_BIN" "$IMPORT_PROG" 2>&1; then
echo -e "${RED}Failed to build import tool${NC}"
echo "Rolling back..."
mv "$BACKUP_DIR" "$DATA_DIR"
rm -f "$IMPORT_PROG" "$IMPORT_BIN"
exit 1
fi
echo "Running import..."
if ! "$IMPORT_BIN" "$DATA_DIR" "$EXPORT_FILE"; then
echo -e "${RED}Import failed!${NC}"
echo "Rolling back..."
rm -rf "$DATA_DIR"
mv "$BACKUP_DIR" "$DATA_DIR"
rm -f "$IMPORT_PROG" "$IMPORT_BIN"
exit 1
fi
rm -f "$IMPORT_PROG" "$IMPORT_BIN"
# Give import goroutine time to process
echo "Waiting for import to complete..."
sleep 10
# Step 5: Verify
echo ""
echo -e "${GREEN}=== Step 5: Verification ===${NC}"
NEW_DB_SIZE=$(du -sb "$DATA_DIR" | cut -f1)
echo "Old database size: $(numfmt --to=iec-i --suffix=B $DB_SIZE)"
echo "New database size: $(numfmt --to=iec-i --suffix=B $NEW_DB_SIZE)"
echo ""
if [ $NEW_DB_SIZE -lt $((DB_SIZE / 10)) ]; then
echo -e "${YELLOW}Warning: New database is suspiciously small${NC}"
echo "This may indicate an incomplete import."
echo "Check the logs in $DATA_DIR/migration.log"
echo ""
read -p "Continue anyway? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Rolling back..."
rm -rf "$DATA_DIR"
mv "$BACKUP_DIR" "$DATA_DIR"
exit 1
fi
fi
echo -e "${GREEN}=== Migration Complete! ===${NC}"
echo ""
echo "Summary:"
echo " - Exported: $EXPORT_COUNT events"
echo " - Old DB size: $(numfmt --to=iec-i --suffix=B $DB_SIZE)"
echo " - New DB size: $(numfmt --to=iec-i --suffix=B $NEW_DB_SIZE)"
echo " - Space saved: $(numfmt --to=iec-i --suffix=B $((DB_SIZE - NEW_DB_SIZE)))"
echo " - Backup location: $BACKUP_DIR"
echo ""
echo "Next steps:"
echo " 1. Start the relay: sudo systemctl start orly (or ./orly)"
echo " 2. Monitor performance for 24-48 hours"
echo " 3. Watch for cache hit ratio >85% in logs"
echo " 4. Verify event count and queries work correctly"
echo " 5. After verification, remove backup: rm -rf $BACKUP_DIR"
echo ""
echo "Rollback (if needed):"
echo " Stop relay, then: rm -rf $DATA_DIR && mv $BACKUP_DIR $DATA_DIR"
echo ""

88
scripts/test-dgraph.sh Executable file
View File

@@ -0,0 +1,88 @@
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
echo "=== ORLY Dgraph Integration Test Suite ==="
echo ""
# Check if dgraph is running
echo "Checking for dgraph server..."
DGRAPH_URL="${ORLY_DGRAPH_URL:-localhost:9080}"
if ! timeout 2 bash -c "echo > /dev/tcp/${DGRAPH_URL%:*}/${DGRAPH_URL#*:}" 2>/dev/null; then
echo "❌ Dgraph server not available at $DGRAPH_URL"
echo ""
echo "To start dgraph using docker-compose:"
echo " cd $SCRIPT_DIR && docker-compose -f dgraph-docker-compose.yml up -d"
echo ""
echo "Or using docker directly:"
echo " docker run -d -p 8080:8080 -p 9080:9080 -p 8000:8000 --name dgraph-orly dgraph/standalone:latest"
echo ""
exit 1
fi
echo "✅ Dgraph server is running at $DGRAPH_URL"
echo ""
# Run dgraph tests
echo "Running dgraph package tests..."
cd "$PROJECT_ROOT"
CGO_ENABLED=0 go test -v -timeout 10m ./pkg/dgraph/... || {
echo "❌ Dgraph tests failed"
exit 1
}
echo ""
echo "✅ All dgraph tests passed!"
echo ""
# Optional: Run relay-tester if requested
if [ "$1" == "--relay-tester" ]; then
echo "Starting ORLY with dgraph backend..."
export ORLY_DB_TYPE=dgraph
export ORLY_DGRAPH_URL="$DGRAPH_URL"
export ORLY_LOG_LEVEL=info
export ORLY_PORT=3334
# Kill any existing ORLY instance
pkill -f "./orly" || true
sleep 1
# Start ORLY in background
./orly &
ORLY_PID=$!
# Wait for ORLY to start
echo "Waiting for ORLY to start..."
for i in {1..30}; do
if curl -s http://localhost:3334 > /dev/null 2>&1; then
echo "✅ ORLY started successfully"
break
fi
sleep 1
if [ $i -eq 30 ]; then
echo "❌ ORLY failed to start"
kill $ORLY_PID 2>/dev/null || true
exit 1
fi
done
echo ""
echo "Running relay-tester against dgraph backend..."
go run cmd/relay-tester/main.go -url ws://localhost:3334 || {
echo "❌ Relay-tester failed"
kill $ORLY_PID 2>/dev/null || true
exit 1
}
# Clean up
kill $ORLY_PID 2>/dev/null || true
echo ""
echo "✅ Relay-tester passed!"
fi
echo ""
echo "=== All tests completed successfully! ==="

250
scripts/test-docker.sh Executable file
View File

@@ -0,0 +1,250 @@
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
echo "=== ORLY Dgraph Docker Integration Test Suite ==="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_error() {
echo -e "${RED}$1${NC}"
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_info() {
echo -e "${YELLOW} $1${NC}"
}
# Check if docker is available
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed or not in PATH"
exit 1
fi
# Check if docker-compose is available
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
print_error "Docker Compose is not installed or not in PATH"
exit 1
fi
# Determine docker-compose command
if docker compose version &> /dev/null 2>&1; then
DOCKER_COMPOSE="docker compose"
else
DOCKER_COMPOSE="docker-compose"
fi
print_info "Using docker-compose command: $DOCKER_COMPOSE"
echo ""
# Change to scripts directory
cd "$SCRIPT_DIR"
# Parse arguments
SKIP_BUILD=false
KEEP_RUNNING=false
RUN_RELAY_TESTER=false
while [[ $# -gt 0 ]]; do
case $1 in
--skip-build)
SKIP_BUILD=true
shift
;;
--keep-running)
KEEP_RUNNING=true
shift
;;
--relay-tester)
RUN_RELAY_TESTER=true
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--skip-build] [--keep-running] [--relay-tester]"
exit 1
;;
esac
done
# Cleanup function
cleanup() {
if [ "$KEEP_RUNNING" = false ]; then
print_info "Cleaning up containers..."
$DOCKER_COMPOSE -f docker-compose-test.yml down
print_success "Cleanup complete"
else
print_info "Containers left running (--keep-running)"
echo ""
print_info "To stop: cd $SCRIPT_DIR && $DOCKER_COMPOSE -f docker-compose-test.yml down"
print_info "View logs: $DOCKER_COMPOSE -f docker-compose-test.yml logs -f"
print_info "ORLY: http://localhost:3334"
print_info "Dgraph: http://localhost:8080"
print_info "Ratel: http://localhost:8000"
fi
}
# Set trap for cleanup
if [ "$KEEP_RUNNING" = false ]; then
trap cleanup EXIT
fi
# Stop any existing containers
print_info "Stopping any existing containers..."
$DOCKER_COMPOSE -f docker-compose-test.yml down --remove-orphans
echo ""
# Build images if not skipping
if [ "$SKIP_BUILD" = false ]; then
print_info "Building ORLY docker image..."
$DOCKER_COMPOSE -f docker-compose-test.yml build orly
print_success "Build complete"
echo ""
fi
# Start dgraph
print_info "Starting dgraph server..."
$DOCKER_COMPOSE -f docker-compose-test.yml up -d dgraph
# Wait for dgraph to be healthy
print_info "Waiting for dgraph to be healthy..."
MAX_WAIT=60
WAITED=0
while [ $WAITED -lt $MAX_WAIT ]; do
if docker exec orly-dgraph curl -sf http://localhost:8080/health > /dev/null 2>&1; then
print_success "Dgraph is healthy"
break
fi
sleep 2
WAITED=$((WAITED + 2))
if [ $WAITED -ge $MAX_WAIT ]; then
print_error "Dgraph failed to become healthy after ${MAX_WAIT}s"
docker logs orly-dgraph
exit 1
fi
done
echo ""
# Start ORLY
print_info "Starting ORLY relay with dgraph backend..."
$DOCKER_COMPOSE -f docker-compose-test.yml up -d orly
# Wait for ORLY to be healthy
print_info "Waiting for ORLY to be healthy..."
MAX_WAIT=60
WAITED=0
while [ $WAITED -lt $MAX_WAIT ]; do
if curl -sf http://localhost:3334/ > /dev/null 2>&1; then
print_success "ORLY is healthy and responding"
break
fi
sleep 2
WAITED=$((WAITED + 2))
if [ $WAITED -ge $MAX_WAIT ]; then
print_error "ORLY failed to become healthy after ${MAX_WAIT}s"
echo ""
print_info "ORLY logs:"
docker logs orly-relay
exit 1
fi
done
echo ""
# Check ORLY version
print_info "Checking ORLY version..."
ORLY_VERSION=$(docker exec orly-relay /app/orly version 2>&1 | head -1 || echo "unknown")
echo "ORLY version: $ORLY_VERSION"
echo ""
# Verify dgraph connection
print_info "Verifying dgraph connection..."
if docker logs orly-relay 2>&1 | grep -q "successfully connected to dgraph"; then
print_success "ORLY successfully connected to dgraph"
elif docker logs orly-relay 2>&1 | grep -q "dgraph"; then
print_info "ORLY dgraph logs:"
docker logs orly-relay 2>&1 | grep -i dgraph
else
print_info "No explicit dgraph connection message (may be using badger)"
fi
echo ""
# Basic connectivity test
print_info "Testing basic relay connectivity..."
if curl -sf http://localhost:3334/ > /dev/null 2>&1; then
print_success "ORLY is accessible at http://localhost:3334"
else
print_error "Failed to connect to ORLY"
exit 1
fi
echo ""
# Test WebSocket connection
print_info "Testing WebSocket connection..."
if command -v websocat &> /dev/null; then
TEST_REQ='["REQ","test",{"kinds":[1],"limit":1}]'
if echo "$TEST_REQ" | timeout 5 websocat ws://localhost:3334 2>/dev/null | grep -q "EOSE"; then
print_success "WebSocket connection successful"
else
print_info "WebSocket test inconclusive (may need events)"
fi
elif command -v wscat &> /dev/null; then
print_info "Testing with wscat..."
# wscat test would go here
else
print_info "WebSocket testing tools not available (install websocat or wscat)"
fi
echo ""
# Run relay-tester if requested
if [ "$RUN_RELAY_TESTER" = true ]; then
print_info "Building relay-tester image..."
$DOCKER_COMPOSE -f docker-compose-test.yml build relay-tester
echo ""
print_info "Running relay-tester against ORLY..."
if $DOCKER_COMPOSE -f docker-compose-test.yml run --rm relay-tester -url ws://orly:3334; then
print_success "Relay-tester passed!"
else
print_error "Relay-tester failed"
echo ""
print_info "ORLY logs:"
docker logs orly-relay --tail 50
exit 1
fi
echo ""
fi
# Show container status
print_info "Container status:"
$DOCKER_COMPOSE -f docker-compose-test.yml ps
echo ""
# Show useful information
print_success "All tests passed!"
echo ""
print_info "Endpoints:"
echo " ORLY WebSocket: ws://localhost:3334"
echo " ORLY HTTP: http://localhost:3334"
echo " Dgraph HTTP: http://localhost:8080"
echo " Dgraph gRPC: localhost:9080"
echo " Ratel UI: http://localhost:8000"
echo ""
if [ "$KEEP_RUNNING" = false ]; then
print_info "Containers will be stopped on script exit"
else
print_info "Containers are running. Use --keep-running flag was set."
fi
exit 0