# LXC Container Deployment Guide

This document provides detailed instructions for deploying the supporting services (Redis, Web3Signer, Vault) as LXC containers on Proxmox.

## Prerequisites

1. **Proxmox Node Access**: SSH access to the Proxmox host (r630-01 recommended)
2. **LXC Templates**: Ubuntu 22.04 LTS template downloaded
3. **Storage**: Sufficient space on local-lvm storage (50GB+ recommended)
4. **Network**: vmbr0 bridge configured with access to 192.168.11.0/24

## Quick Start

### 1. Verify Node Readiness

```bash
cd rpc-translator-138
./verify-node-ready.sh r630-01
```

This script checks:
- ✅ Node is online and accessible
- ✅ Storage is available
- ✅ LXC templates are present
- ✅ Network bridges are configured
- ✅ Sufficient resources (memory/disk)
- ✅ VMIDs 106, 107, 108 are available

### 2. Deploy Supporting Services

```bash
./deploy-supporting-services.sh r630-01
```

This script creates all three containers:
- **VMID 106**: Redis (192.168.11.110)
- **VMID 107**: Web3Signer (192.168.11.111)
- **VMID 108**: Vault (192.168.11.112)

### 3. Start and Configure Containers

After deployment, containers are created but not started. Start them:

```bash
pct start 106  # Redis
pct start 107  # Web3Signer
pct start 108  # Vault
```

Then configure each service (see detailed instructions below).

## Container Specifications

| Service | VMID | IP | Hostname | CPU | RAM | Disk | Template |
|---------|------|----|----------|-----|-----|------|----------|
| Redis | 106 | 192.168.11.110 | redis-rpc-translator | 2 | 512MB | 10GB | Ubuntu 22.04 |
| Web3Signer | 107 | 192.168.11.111 | web3signer-rpc-translator | 2 | 2048MB | 20GB | Ubuntu 22.04 |
| Vault | 108 | 192.168.11.112 | vault-rpc-translator | 2 | 2048MB | 20GB | Ubuntu 22.04 |

## Manual Deployment

If you prefer manual deployment or need to customize the configuration:

### Redis Container (VMID 106)

```bash
# Create container
pct create 106 local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst \
  --hostname redis-rpc-translator \
  --cores 2 \
  --memory 512 \
  --swap 512 \
  --storage local-lvm \
  --rootfs local-lvm:10 \
  --net0 name=eth0,bridge=vmbr0,ip=192.168.11.110/24,gw=192.168.11.1 \
  --onboot 1 \
  --unprivileged 0 \
  --features nesting=1

# Start container
pct start 106

# Enter container
pct enter 106

# Install Redis
apt-get update
apt-get install -y redis-server

# Configure Redis
nano /etc/redis/redis.conf
# Set: bind 192.168.11.110
# Set: requirepass <strong-password>  # Optional but recommended
# Set: protected-mode yes

# Start Redis
systemctl enable redis-server
systemctl restart redis-server

# Verify
redis-cli -h 192.168.11.110 ping
# Should return: PONG
```

### Web3Signer Container (VMID 107)

```bash
# Create container
pct create 107 local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst \
  --hostname web3signer-rpc-translator \
  --cores 2 \
  --memory 2048 \
  --swap 2048 \
  --storage local-lvm \
  --rootfs local-lvm:20 \
  --net0 name=eth0,bridge=vmbr0,ip=192.168.11.111/24,gw=192.168.11.1 \
  --onboot 1 \
  --unprivileged 0 \
  --features nesting=1

# Start container
pct start 107

# Enter container
pct enter 107

# Install dependencies
apt-get update
apt-get install -y openjdk-17-jre-headless wget curl

# Download Web3Signer
cd /opt
wget https://artifacts.consensys.net/web3signer/web3signer-23.10.0/web3signer-23.10.0.tar.gz
tar -xzf web3signer-23.10.0.tar.gz
cd web3signer-23.10.0

# Configure Web3Signer
# See Web3Signer documentation for configuration
# Configure key storage, HTTP server, etc.

# Test
./bin/web3signer --version
```

### Vault Container (VMID 108)

```bash
# Create container
pct create 108 local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst \
  --hostname vault-rpc-translator \
  --cores 2 \
  --memory 2048 \
  --swap 2048 \
  --storage local-lvm \
  --rootfs local-lvm:20 \
  --net0 name=eth0,bridge=vmbr0,ip=192.168.11.112/24,gw=192.168.11.1 \
  --onboot 1 \
  --unprivileged 0 \
  --features nesting=1

# Start container
pct start 108

# Enter container
pct enter 108

# Install Vault
apt-get update
apt-get install -y unzip wget curl
cd /tmp
wget https://releases.hashicorp.com/vault/1.15.0/vault_1.15.0_linux_amd64.zip
unzip vault_1.15.0_linux_amd64.zip
mv vault /usr/local/bin/
chmod +x /usr/local/bin/vault

# Create vault user and directories
useradd -r -s /bin/false vault
mkdir -p /etc/vault.d /var/lib/vault
chown vault:vault /var/lib/vault

# Configure Vault (see Vault documentation for production setup)
# For development/testing:
vault server -dev -dev-listen-address="192.168.11.112:8200"

# Test
vault version
```

## Verifying Deployment

### Check Container Status

```bash
# List containers
pct list | grep -E "106|107|108"

# Check individual containers
pct status 106
pct status 107
pct status 108
```

### Test Connectivity

From a translator VMID (2400-2402) or the Proxmox host:

```bash
# Test Redis
redis-cli -h 192.168.11.110 ping

# Test Web3Signer
curl http://192.168.11.111:9000/upcheck

# Test Vault
curl http://192.168.11.112:8200/v1/sys/health
```

### Check Logs

```bash
# Container logs
pct enter 106
journalctl -u redis-server -n 50

pct enter 107
# Web3Signer logs location depends on configuration

pct enter 108
# Vault logs location depends on configuration
```

## Troubleshooting

### Container Won't Start

```bash
# Check container configuration
pct config 106

# Check logs
journalctl -u pve-container@106

# Check resource availability
pvesh get /nodes/r630-01/status
```

### Network Issues

```bash
# Verify network configuration
pct config 106 | grep net0

# Test connectivity from host
ping 192.168.11.110
ping 192.168.11.111
ping 192.168.11.112

# Check firewall rules (if applicable)
iptables -L -n | grep 192.168.11
```

### Template Not Found

If the script reports "No LXC templates found":

1. Access Proxmox Web UI
2. Go to: Datacenter > Storage > local (or local-lvm)
3. Click "Templates" tab
4. Click "Download Templates"
5. Select "ubuntu-22.04-standard"
6. Wait for download to complete
7. Re-run the deployment script

## Next Steps

After containers are deployed and configured:

1. **Configure Services**: See `DEPLOYMENT.md` for detailed service configuration
2. **Update Translator Configuration**: Update `.env` files on translator VMIDs (2400-2402)
3. **Test Integration**: Verify translator can connect to all supporting services
4. **Deploy Translator**: Follow translator deployment guide

## References

- **Proxmox LXC Documentation**: https://pve.proxmox.com/pve-docs/pve-admin-guide.html#chapter_lxc
- **Redis Documentation**: https://redis.io/docs/
- **Web3Signer Documentation**: https://docs.web3signer.consensys.io/
- **Vault Documentation**: https://developer.hashicorp.com/vault/docs
