maple-proxy 0.1.6

Lightweight OpenAI-compatible proxy server for Maple/OpenSecret TEE infrastructure
Documentation
# Justfile for Maple Proxy
# Development commands for the OpenAI-compatible proxy server

# Load environment variables from .env file
set dotenv-load

# Set the container runtime (docker or podman)
container := env_var_or_default("CONTAINER_RUNTIME", "podman")

# Default command - show available commands
default:
    @just --list

# Set up development environment
setup:
    @echo "๐Ÿ”ง Setting up development environment..."
    @bash setup-hooks.sh
    @cargo check --all-features
    @echo "โœ… Development environment ready"

# Format code with rustfmt
format:
    @echo "๐ŸŽจ Formatting code..."
    @cargo fmt
    @echo "โœ… Code formatted"

# Alias for format
fmt: format

# Run clippy lints
lint:
    @echo "๐Ÿ” Running clippy lints..."
    @cargo clippy --all-targets --all-features -- -D warnings
    @echo "โœ… Lints passed"

# Alias for lint
clippy: lint

# Run all tests
test:
    @echo "๐Ÿงช Running tests..."
    @cargo test --all-features
    @echo "โœ… Tests passed"

# Run all checks (format, lint, test)
check: format lint test
    @echo "โœ… All checks passed"

# Run the development server
run:
    @echo "๐Ÿš€ Starting Maple Proxy server..."
    @echo "๐Ÿ“ Loading configuration from .env"
    @cargo run

# Run with custom backend URL (preserves .env variables)
run-with-backend url:
    @echo "๐Ÿš€ Starting Maple Proxy server..."
    @echo "๐Ÿ”— Backend: {{url}}"
    @echo "๐Ÿ“ Loading other configs from .env"
    @bash -c 'set -a; source .env 2>/dev/null; set +a; MAPLE_BACKEND_URL={{url}} cargo run'

# Run pointing to local backend
run-local:
    @just run-with-backend "http://localhost:3000"

# Run pointing to production backend
run-prod:
    @just run-with-backend "https://enclave.trymaple.ai"

# Build debug binary
build:
    @echo "๐Ÿ”จ Building debug binary..."
    @cargo build
    @echo "โœ… Debug binary built at target/debug/maple-proxy"

# Build release binary
release:
    @echo "๐Ÿ“ฆ Building release binary..."
    @cargo build --release
    @echo "โœ… Release binary built at target/release/maple-proxy"

# Build for all targets (used in CI)
build-all:
    @echo "๐Ÿ“ฆ Building for all targets..."
    @cargo build --all-targets --all-features
    @echo "โœ… All targets built"

# Clean build artifacts
clean:
    @echo "๐Ÿงน Cleaning build artifacts..."
    @cargo clean
    @echo "โœ… Build artifacts cleaned"

# Update dependencies
update:
    @echo "๐Ÿ“ฆ Updating dependencies..."
    @cargo update
    @echo "โœ… Dependencies updated"

# Install to ~/.cargo/bin
install:
    @echo "๐Ÿ“ฅ Installing maple-proxy..."
    @cargo install --path .
    @echo "โœ… Installed to ~/.cargo/bin/maple-proxy"

# Uninstall from ~/.cargo/bin
uninstall:
    @echo "๐Ÿ“ค Uninstalling maple-proxy..."
    @cargo uninstall maple-proxy
    @echo "โœ… Uninstalled"

# Run with verbose logging
debug:
    @echo "๐Ÿ› Starting with debug logging..."
    RUST_LOG=debug MAPLE_DEBUG=true cargo run

# Check for security vulnerabilities
audit:
    @echo "๐Ÿ”’ Running security audit..."
    @cargo audit
    @echo "โœ… Security audit complete"

# Generate documentation
doc:
    @echo "๐Ÿ“š Generating documentation..."
    @cargo doc --no-deps --all-features --open
    @echo "โœ… Documentation generated"

# Show code coverage (requires cargo-tarpaulin)
coverage:
    @echo "๐Ÿ“Š Generating code coverage..."
    @cargo tarpaulin --verbose --all-features --workspace --timeout 120 --out html
    @echo "โœ… Coverage report generated at tarpaulin-report.html"

# Watch for changes and run tests
watch:
    @echo "๐Ÿ‘๏ธ Watching for changes..."
    @cargo watch -x test

# Create a new git commit with conventional commit message
commit message:
    @git add -A
    @git commit -m "{{message}}"
    @echo "โœ… Changes committed"

# Quick test with curl
test-curl:
    @echo "๐Ÿงช Testing with curl..."
    @curl -N http://localhost:8080/v1/chat/completions \
        -H "Content-Type: application/json" \
        -d '{"model": "llama3-3-70b", "messages": [{"role": "user", "content": "Say hello"}], "stream": true}'

# Show environment info
env:
    @echo "๐ŸŒ Environment Info"
    @echo "==================="
    @echo "Rust version: $(rustc --version)"
    @echo "Cargo version: $(cargo --version)"
    @echo "Just version: $(just --version)"
    @echo "Container runtime: {{container}} $({{container}} --version 2>/dev/null | head -1 || echo 'not installed')"
    @echo ""
    @echo "๐Ÿ“‹ Environment Variables:"
    @echo "MAPLE_HOST: ${MAPLE_HOST:-127.0.0.1}"
    @echo "MAPLE_PORT: ${MAPLE_PORT:-8080}"
    @echo "MAPLE_BACKEND_URL: ${MAPLE_BACKEND_URL:-https://enclave.trymaple.ai}"
    @echo "MAPLE_API_KEY: ${MAPLE_API_KEY:-[not set]}"
    @echo "MAPLE_DEBUG: ${MAPLE_DEBUG:-false}"
    @echo "MAPLE_ENABLE_CORS: ${MAPLE_ENABLE_CORS:-false}"

# Build Docker image
docker-build:
    @echo "๐Ÿณ Building Docker image with {{container}}..."
    @{{container}} build -t maple-proxy:latest .
    @echo "โœ… Docker image built: maple-proxy:latest"

# Run Docker container
docker-run:
    @echo "๐Ÿš€ Running Docker container with {{container}}..."
    @{{container}} run --rm -it \
        -p ${MAPLE_PORT:-8080}:8080 \
        -e MAPLE_API_KEY=${MAPLE_API_KEY} \
        -e MAPLE_BACKEND_URL=${MAPLE_BACKEND_URL:-https://enclave.trymaple.ai} \
        -e MAPLE_DEBUG=${MAPLE_DEBUG:-false} \
        -e MAPLE_ENABLE_CORS=${MAPLE_ENABLE_CORS:-true} \
        maple-proxy:latest

# Run Docker container in detached mode
docker-run-detached:
    @echo "๐Ÿš€ Running Docker container in background with {{container}}..."
    @{{container}} run -d \
        --name maple-proxy \
        -p ${MAPLE_PORT:-8080}:8080 \
        -e MAPLE_API_KEY=${MAPLE_API_KEY} \
        -e MAPLE_BACKEND_URL=${MAPLE_BACKEND_URL:-https://enclave.trymaple.ai} \
        -e MAPLE_DEBUG=${MAPLE_DEBUG:-false} \
        -e MAPLE_ENABLE_CORS=${MAPLE_ENABLE_CORS:-true} \
        maple-proxy:latest
    @echo "โœ… Container started. Use 'just docker-stop' to stop it."

# Stop Docker container
docker-stop:
    @echo "๐Ÿ›‘ Stopping Docker container..."
    @{{container}} stop maple-proxy 2>/dev/null || echo "Container not running"
    @{{container}} rm maple-proxy 2>/dev/null || true
    @echo "โœ… Container stopped"

# View Docker logs
docker-logs:
    @{{container}} logs -f maple-proxy 2>/dev/null || echo "Container not running"

# Run with docker-compose
compose-up:
    @echo "๐Ÿš€ Starting services with docker-compose..."
    @{{container}}-compose up -d
    @echo "โœ… Services started. Use 'just compose-down' to stop."

# Stop docker-compose services
compose-down:
    @echo "๐Ÿ›‘ Stopping services..."
    @{{container}}-compose down
    @echo "โœ… Services stopped"

# View docker-compose logs
compose-logs:
    @{{container}}-compose logs -f

# Clean Docker images
docker-clean:
    @echo "๐Ÿงน Cleaning Docker images..."
    @{{container}} rmi maple-proxy:latest 2>/dev/null || true
    @echo "โœ… Docker images cleaned"

# Push to GitHub Container Registry
ghcr-push tag="latest":
    @echo "๐Ÿ“ฆ Pushing to GitHub Container Registry..."
    @{{container}} tag maple-proxy:latest ghcr.io/opensecretcloud/maple-proxy:{{tag}}
    @{{container}} push ghcr.io/opensecretcloud/maple-proxy:{{tag}}
    @echo "โœ… Pushed to ghcr.io/opensecretcloud/maple-proxy:{{tag}}"

# Build and push to GHCR
ghcr-build-push tag="latest":
    @echo "๐Ÿณ Building and pushing to GHCR..."
    @{{container}} build -t ghcr.io/opensecretcloud/maple-proxy:{{tag}} .
    @{{container}} push ghcr.io/opensecretcloud/maple-proxy:{{tag}}
    @echo "โœ… Image available at ghcr.io/opensecretcloud/maple-proxy:{{tag}}"

# Login to GitHub Container Registry (requires PAT token)
ghcr-login:
    @echo "๐Ÿ” Logging in to GitHub Container Registry..."
    @echo "Please ensure you have a GitHub Personal Access Token with 'write:packages' scope"
    @echo "${GITHUB_TOKEN}" | {{container}} login ghcr.io -u ${GITHUB_USER} --password-stdin
    @echo "โœ… Logged in to ghcr.io"

# Pull from GitHub Container Registry
ghcr-pull tag="latest":
    @echo "๐Ÿ“ฅ Pulling from GitHub Container Registry..."
    @{{container}} pull ghcr.io/opensecretcloud/maple-proxy:{{tag}}
    @echo "โœ… Pulled ghcr.io/opensecretcloud/maple-proxy:{{tag}}"