# Temporary VM Deployment - Complete Summary

## Overview

This deployment method provides a quick way to deploy all Besu nodes in a single VM using Docker containers, with an easy migration path to individual LXC containers later.

## Architecture

```
┌─────────────────────────────────────┐
│   Proxmox VE Host (ml110)           │
│   IP: 192.168.11.10                 │
│                                     │
│   ┌─────────────────────────────┐  │
│   │  Temporary VM (VMID 9000)   │  │
│   │  IP: 192.168.11.90          │  │
│   │  Resources: 32GB RAM, 8 CPU │  │
│   │                               │  │
│   │  ┌─────────────────────────┐ │  │
│   │  │  Docker Network         │ │  │
│   │  │  172.20.0.0/16         │ │  │
│   │  │                         │ │  │
│   │  │  Validators (5):        │ │  │
│   │  │  • besu-validator-1    │ │  │
│   │  │  • besu-validator-2    │ │  │
│   │  │  • besu-validator-3    │ │  │
│   │  │  • besu-validator-4    │ │  │
│   │  │  • besu-validator-5    │ │  │
│   │  │                         │ │  │
│   │  │  Sentries (4):          │ │  │
│   │  │  • besu-sentry-1        │ │  │
│   │  │  • besu-sentry-2        │ │  │
│   │  │  • besu-sentry-3        │ │  │
│   │  │  • besu-sentry-4        │ │  │
│   │  │                         │ │  │
│   │  │  RPC Nodes (3):         │ │  │
│   │  │  • besu-rpc-1           │ │  │
│   │  │  • besu-rpc-2           │ │  │
│   │  │  • besu-rpc-3           │ │  │
│   │  └─────────────────────────┘ │  │
│   └─────────────────────────────┘  │
└─────────────────────────────────────┘
```

## Files Created

### Deployment Scripts
1. **`scripts/deployment/deploy-besu-temp-vm.sh`**
   - Creates the temporary VM in Proxmox
   - Configures network and cloud-init
   - Downloads Ubuntu cloud image if needed

2. **`scripts/deployment/setup-docker-besu.sh`**
   - Installs Docker and Docker Compose
   - Creates directory structure
   - Copies configuration files and keys

3. **`scripts/deployment/copy-configs-to-vm.sh`**
   - Copies config templates to VM
   - Copies genesis and permissions files
   - Sets up node-specific configurations

4. **`scripts/deployment/deploy-besu-temp-vm-complete.sh`**
   - Orchestrates the complete deployment
   - Runs all steps in sequence
   - Validates the deployment

### Configuration Files
5. **`templates/docker-compose-besu-temp.yml`**
   - Docker Compose configuration
   - Defines all 12 containers
   - Network and volume configuration

6. **`templates/besu-configs/config-validator.toml`**
   - Validator node configuration template

7. **`templates/besu-configs/config-sentry.toml`**
   - Sentry node configuration template

8. **`templates/besu-configs/config-rpc.toml`**
   - RPC node configuration template

### Migration Scripts
9. **`scripts/migration/migrate-vm-to-lxc.sh`**
   - Exports data from Docker containers
   - Imports data to LXC containers
   - Preserves all blockchain data

### Validation Scripts
10. **`scripts/validation/validate-besu-temp-vm.sh`**
    - Comprehensive validation
    - Checks container health
    - Tests RPC and metrics endpoints

11. **`scripts/validation/health-check-besu-vm.sh`**
    - Quick health check
    - Returns exit code for automation

### Remote Deployment
12. **`scripts/deploy-besu-temp-vm-on-ml110.sh`**
    - Deploys from local machine to ml110
    - Handles SSH authentication
    - Provides progress feedback

### Documentation
13. **`docs/TEMP_VM_DEPLOYMENT.md`**
    - Complete deployment guide
    - Detailed instructions
    - Troubleshooting section

14. **`docs/TEMP_VM_QUICK_START.md`**
    - Quick reference guide
    - Essential commands

15. **`docs/DEPLOYMENT_OPTIONS.md`**
    - Comparison of deployment methods
    - When to use each method

16. **`README_TEMP_VM.md`**
    - Quick reference at project root

## Usage

### Complete Automated Deployment

```bash
# On Proxmox host
cd /opt/smom-dbis-138-proxmox
sudo ./scripts/deployment/deploy-besu-temp-vm-complete.sh /opt/smom-dbis-138
```

### Remote Deployment (from local machine)

```bash
cd /home/intlc/projects/proxmox
./scripts/deploy-besu-temp-vm-on-ml110.sh
```

### Integration with deploy-all.sh

```bash
# Use temporary VM instead of LXC
sudo DEPLOY_BESU=true DEPLOY_BESU_TEMP_VM=true ./deploy-all.sh
```

## Container Details

### Validators
- **Containers**: `besu-validator-1` through `besu-validator-5`
- **P2P Ports**: 30303-30307 (host ports)
- **Metrics Ports**: 9545-9549
- **Memory**: 4GB each
- **Image**: `hyperledger/besu:23.10.0`

### Sentries
- **Containers**: `besu-sentry-1` through `besu-sentry-4`
- **P2P Ports**: 30308-30311
- **Metrics Ports**: 9550-9553
- **Memory**: 2GB each
- **Image**: `hyperledger/besu:23.10.0`

### RPC Nodes
- **Containers**: `besu-rpc-1` through `besu-rpc-3`
- **HTTP RPC**: 8545, 8547, 8549
- **WS RPC**: 8546, 8548, 8550
- **P2P Ports**: 30312-30314
- **Metrics Ports**: 9554-9556
- **Memory**: 8GB each
- **Image**: `hyperledger/besu:23.10.0`

## Network Configuration

- **VM IP**: 192.168.11.90
- **Docker Network**: 172.20.0.0/16
- **Gateway**: 192.168.11.1
- **DNS**: 8.8.8.8, 8.8.4.4

## Data Locations

### On VM
- **Base Directory**: `/opt/besu`
- **Validator Data**: `/opt/besu/validators/validator-{N}/data`
- **Sentry Data**: `/opt/besu/sentries/sentry-{N}/data`
- **RPC Data**: `/opt/besu/rpc/rpc-{N}/data`
- **Shared Config**: `/opt/besu/shared/genesis/` and `/opt/besu/shared/permissions/`

## Migration Path

1. **Deploy Temporary VM** (15-30 minutes)
   ```bash
   sudo ./scripts/deployment/deploy-besu-temp-vm-complete.sh /opt/smom-dbis-138
   ```

2. **Test and Validate** (ongoing)
   ```bash
   ./scripts/validation/validate-besu-temp-vm.sh
   ```

3. **Deploy LXC Containers** (30-45 minutes)
   ```bash
   sudo ./scripts/deployment/deploy-besu-nodes.sh
   ```

4. **Migrate Data** (10-20 minutes)
   ```bash
   sudo ./scripts/migration/migrate-vm-to-lxc.sh /opt/smom-dbis-138
   ```

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

6. **Shut Down Temporary VM**
   ```bash
   qm stop 9000
   # Or delete: qm destroy 9000 --purge
   ```

## Benefits

✅ **Fast Deployment**: Get network running in 15-30 minutes  
✅ **Easy Testing**: Single VM for quick validation  
✅ **Simple Management**: All nodes in one place  
✅ **Migration Ready**: Easy path to production LXC deployment  
✅ **Resource Efficient**: Lower initial resource requirements  

## Next Steps

1. Review the deployment guide: `docs/TEMP_VM_DEPLOYMENT.md`
2. Deploy the temporary VM
3. Validate the deployment
4. Test the network
5. Plan migration to LXC when ready

## Support

For issues or questions:
- Check logs: `docker compose logs` (on VM)
- Run validation: `./scripts/validation/validate-besu-temp-vm.sh`
- Review documentation: `docs/TEMP_VM_DEPLOYMENT.md`
- Check troubleshooting section in deployment guide

