# One-Command Deployment Guide

Complete Proxmox VE LXC deployment for SMOM-DBIS-138 with a single command.

## 🚀 Quick Start

### Step 1: Prepare Configuration

```bash
cd /opt/smom-dbis-138-proxmox
cp config/proxmox.conf.example config/proxmox.conf
cp config/network.conf.example config/network.conf
```

Edit `config/proxmox.conf` with your Proxmox settings:
- `PROXMOX_HOST` - Proxmox host IP/hostname
- `PROXMOX_USER` - Proxmox API user
- `PROXMOX_TOKEN` - API token
- `PROXMOX_NODE` - Node name
- `PROXMOX_STORAGE` - Storage pool name

### Step 2: Run Deployment

**Deploy Everything (Recommended):**
```bash
sudo ./deploy-all.sh
```

**Or deploy specific components:**
```bash
# Deploy only Besu nodes
sudo DEPLOY_BESU=true DEPLOY_HYPERLEDGER=false DEPLOY_SERVICES=false DEPLOY_MONITORING=false DEPLOY_EXPLORER=false ./deploy-all.sh

# Deploy Besu + Hyperledger
sudo DEPLOY_BESU=true DEPLOY_HYPERLEDGER=true DEPLOY_SERVICES=false DEPLOY_MONITORING=false DEPLOY_EXPLORER=false ./deploy-all.sh
```

## 📦 What Gets Deployed

### Phase 1: Blockchain Core (Besu)
- **Validators** (VMID 1000-1004): 5 nodes for consensus
- **Sentries** (VMID 1500-1503): 4 nodes for protection
- **RPC Nodes** (VMID 2500-2502): 3 nodes for public access

### Phase 2: Hyperledger Services
- **Firefly** (VMID 6200): Web3 gateway
- **Cacti** (VMID 5200): Blockchain integration platform
- **Fabric** (VMID 6000): Permissioned blockchain
- **Indy** (VMID 6400): Self-sovereign identity

### Phase 3: Services
- **Oracle Publisher** (VMID 3500+): Price feed service
- **CCIP Monitor** (VMID 3500+): Cross-chain monitoring
- **Keeper** (VMID 3500+): Automated upkeep
- **Financial Tokenization** (VMID 3500+): Tokenization service

### Phase 4: Monitoring Stack
- **Monitoring Stack** (VMID 3500+): Prometheus, Grafana, Loki, Alertmanager

### Phase 5: Explorer
- **Blockscout** (VMID 5000): Blockchain explorer

**Total**: ~35-40 containers

## 🔧 Post-Deployment

After deployment completes, configure each service:

### 1. Configure Besu RPC Endpoints

All services need to connect to Besu RPC. Update their configurations:

```bash
# For each service container
pct exec <VMID> -- bash

# Edit service .env file
nano /opt/<service>/.env
# Set RPC_URL_138=http://10.3.1.40:8545
# Set WS_URL_138=ws://10.3.1.40:8546
```

### 2. Copy Service Files

Copy application files from source project to containers:

```bash
# Oracle Publisher (update VMID when deployed)
pct push <VMID> /path/to/smom-dbis-138/services/oracle-publisher/oracle_publisher.py /opt/oracle-publisher/
pct exec <VMID> -- systemctl start oracle-publisher

# CCIP Monitor (update VMID when deployed)
pct push <VMID> /path/to/smom-dbis-138/services/ccip-monitor/ccip_monitor.py /opt/ccip-monitor/
pct exec <VMID> -- systemctl start ccip-monitor

# Keeper (update VMID when deployed)
pct push <VMID> /path/to/smom-dbis-138/scripts/reserve/keeper-service.js /opt/keeper/
pct exec <VMID> -- systemctl start price-feed-keeper

# Financial Tokenization (update VMID when deployed)
pct push <VMID> /path/to/smom-dbis-138/services/financial-tokenization/ /opt/financial-tokenization/
pct exec <VMID> -- systemctl start financial-tokenization
```

### 3. Start Services

```bash
# Start all Besu nodes
for vmid in 1000 1001 1002 1003 1004 1500 1501 1502 1503 2500 2501 2502; do
    pct exec $vmid -- systemctl start besu-validator.service 2>/dev/null || \
    pct exec $vmid -- systemctl start besu-sentry.service 2>/dev/null || \
    pct exec $vmid -- systemctl start besu-rpc.service 2>/dev/null
done

# Start Hyperledger services
pct exec 150 -- systemctl start firefly
pct exec 151 -- systemctl start cacti
pct exec 152 -- systemctl start fabric
pct exec 153 -- systemctl start indy

# Start monitoring
pct exec 130 -- systemctl start monitoring-stack

# Start explorer
pct exec 140 -- systemctl start blockscout
```

### 4. Verify Deployment

```bash
# Check container status
pct list

# Check service status in containers
pct exec <VMID> -- systemctl status <service-name>

# Check logs
pct exec <VMID> -- journalctl -u <service-name> -f
```

## 📊 Access Points

After deployment, services will be available at:

- **Besu RPC**: `http://10.3.1.40:8545`
- **Grafana**: `http://10.3.1.130:3000` (admin/admin)
- **Prometheus**: `http://10.3.1.130:9090`
- **Blockscout**: `http://10.3.1.140:4000`
- **Firefly API**: `http://10.3.1.60:5000`
- **Cacti API**: `http://10.3.1.61:4000`

## 🔍 Troubleshooting

### Container Creation Fails
- Check Proxmox storage space: `df -h`
- Verify storage pool exists: `pvesm status`
- Check VMID availability: `pct list | grep <VMID>`

### Services Won't Start
- Check container logs: `pct exec <VMID> -- journalctl -xe`
- Verify network connectivity: `pct exec <VMID> -- ping 8.8.8.8`
- Check service configuration: `pct exec <VMID> -- systemctl status <service>`

### Network Issues
- Verify VLAN configuration matches network.conf
- Check IP addresses are not conflicting
- Ensure gateway is accessible: `pct exec <VMID> -- ping <GATEWAY>`

## 📚 Additional Resources

- [Full Deployment Guide](docs/DEPLOYMENT.md)
- [Services List](docs/SERVICES_LIST.md)
- [Hyperledger Guide](README_HYPERLEDGER.md)
- [Quick Start](docs/QUICK_START.md)

## 🆘 Support

For issues or questions:
1. Check logs in `/opt/smom-dbis-138-proxmox/logs/`
2. Review container logs: `pct exec <VMID> -- journalctl -xe`
3. Verify configuration files match your environment

