# Fase 1: EasyPanel Migration (Week 1-2)

Target: Migrar 108 containers Docker para VM Proxmox

## 1.1 Criar VM Docker Host

```bash
qm create 200 \
  --name easypanel-docker \
  --memory 32768 \
  --cores 8 \
  --net0 virtio,bridge=vmbr0 \
  --scsi0 rpool/vm-disks:200 \
  --ostype l26 \
  --boot order=scsi0

# Install Ubuntu 24.04 LTS
# Via Cloud-Init ou ISO manual
```

## 1.2 Instalar Docker + EasyPanel

```bash
ssh root@10.10.10.200

# Docker
curl -fsSL https://get.docker.com | sh

# EasyPanel
curl -sSL https://get.easypanel.io | sh
```

## 1.3 Backup Containers Actuais

```bash
# Em easy.descomplicar.pt
tar -czf /tmp/easypanel-volumes.tar.gz /var/lib/easypanel/projects

# Transfer para PBS ou storage temporario
scp /tmp/easypanel-volumes.tar.gz root@cluster.descomplicar.pt:/mnt/migration/
```

## 1.4 Migrar Containers (Batch 5-10)

Batch 1 (nao-criticos para teste):

```bash
# Containers teste: dev environments, staging
# IDs: 1-5

# Por cada container:
1. Exportar env vars do EasyPanel
2. Exportar docker-compose.yml
3. Copiar volumes
4. Recriar em novo EasyPanel
5. Testar health endpoint
6. DNS cutover se OK
```

Workflow Batch:

```bash
for container_id in 1 2 3 4 5; do
  # Export config
  curl -s http://easy.descomplicar.pt:3000/api/trpc/services.get \
    -d "serviceId=$container_id" > config_$container_id.json

  # Copiar volumes
  rsync -avz /var/lib/easypanel/projects/$container_id/ \
    root@10.10.10.200:/var/lib/easypanel/projects/$container_id/

  # Recriar service (via EasyPanel API ou UI)

  # Test
  curl -I http://10.10.10.200:PORT/health

  # DNS cutover (se health OK)
done
```

## 1.5 Validation (24-48h por batch)

```
Monitoring:
- Uptime checks (UptimeRobot ou similar)
- Error rates (logs)
- Performance (response time <500ms)
- Cliente feedback

Rollback triggers:
- >2 containers falham consecutivamente
- Cliente reporta down
- Health checks fail >10min
```

## 1.6 DNS Cutover

```bash
# Baixar TTL para 300s (5min) 24h ANTES
# Ex: Cloudflare ou dns.descomplicar.pt

# Cutover:
A record: old-ip -> NAT port forward para 10.10.10.200:PORT

# Monitorizar por 1h
# Reverter se problemas
```

## 1.7 Rollback Procedure

```bash
# Reverter DNS (TTL 300s = 5min propagacao)
# Reactivar container antigo
# Investigar causa falha
# Re-tentar apos fix
```

Batch 2-N: Repetir ate 108 containers migrados.
