# Quick Start Deployment Guide

This guide provides the fastest path to deploy the DeFi Oracle Meta Mainnet (ChainID 138).

## Prerequisites Checklist

Before starting, ensure you have:

- [x] ✅ Azure CLI installed and authenticated
- [x] ✅ `.env` file configured with Azure and Cloudflare credentials
- [x] ✅ Validator and oracle keys generated
- [x] ✅ Genesis file created
- [x] ✅ Resource providers registered
- [ ] ⚠️ Terraform installed (run: `./scripts/setup/install-terraform.sh`)
- [ ] ⚠️ kubectl installed
- [ ] ⚠️ Helm 3.x installed

## Quick Deployment Steps

### Step 1: Install Missing Tools

```bash
# Install Terraform (if not installed)
./scripts/setup/install-terraform.sh

# Verify all tools
./scripts/deployment/prepare-all-phases.sh
```

### Step 2: Initialize Terraform

```bash
cd terraform
terraform init
```

### Step 3: Review Configuration

```bash
# Review terraform.tfvars
cat terraform.tfvars

# Verify naming convention
grep -E "az-p-we" terraform/locals.tf
```

### Step 4: Plan Deployment

```bash
terraform plan -out=tfplan
```

**Review the plan carefully:**
- Check resource names follow convention: `az-p-we-{resource}-{instance}`
- Verify region is `westeurope`
- Review estimated costs
- Check resource counts and sizes

### Step 5: Apply Infrastructure

```bash
terraform apply tfplan
```

**This will create:**
- Resource groups
- Virtual network and subnets
- Network security groups
- Key Vault
- Log Analytics workspace
- AKS cluster and node pools
- Application Gateway
- Storage accounts

**⏱️ Estimated time: 20-30 minutes**

### Step 6: Configure kubectl

```bash
# Get AKS credentials
az aks get-credentials \
  --resource-group az-p-we-rg-comp-001 \
  --name az-p-we-aks-main

# Verify connection
kubectl get nodes
```

### Step 7: Deploy Kubernetes Resources

```bash
# Create namespaces
kubectl apply -f k8s/base/namespace.yaml

# Deploy validators
helm install besu-validators ./helm/besu-network \
  -f helm/besu-network/values-validators.yaml \
  -n besu-network

# Deploy sentries
helm install besu-sentries ./helm/besu-network \
  -f helm/besu-network/values-sentries.yaml \
  -n besu-network

# Deploy RPC nodes
helm install besu-rpc ./helm/besu-network \
  -f helm/besu-network/values-rpc.yaml \
  -n besu-network
```

### Step 8: Configure DNS

```bash
# Get Application Gateway IP
AGW_IP=$(./scripts/deployment/get-app-gateway-ip.sh)

# Configure Cloudflare DNS
./scripts/deployment/cloudflare-dns.sh \
  --zone-id $CLOUDFLARE_ZONE_ID \
  --api-token $CLOUDFLARE_API_TOKEN \
  --ip $AGW_IP
```

### Step 9: Deploy Contracts

```bash
# Set RPC URL (after DNS propagates)
export RPC_URL="https://rpc.d-bis.org"
export PRIVATE_KEY="<your-deployment-key>"

# Deploy contracts
./scripts/deployment/deploy-weth.sh
./scripts/deployment/deploy-multicall.sh
```

### Step 10: Verify Deployment

```bash
./scripts/deployment/verify-deployment.sh
```

## Automated Deployment

For a fully automated deployment (after prerequisites):

```bash
# Phase 1: Prerequisites (already done)
./scripts/deployment/deploy-phase1.sh

# Phase 2: Terraform setup
./scripts/deployment/deploy-phase2.sh

# Then manually:
cd terraform
terraform init
terraform plan
terraform apply  # Requires confirmation
```

## Troubleshooting

### Terraform Not Found
```bash
./scripts/setup/install-terraform.sh
```

### Azure Authentication Issues
```bash
az login
az account show
```

### Resource Provider Not Registered
```bash
./scripts/azure/check-azure-prerequisites.sh
```

### Quota Issues
```bash
./scripts/azure/check-quotas.sh westeurope
```

## Resource Naming

All resources follow: `az-p-we-{resource}-{instance}`

Examples:
- AKS: `az-p-we-aks-main`
- Key Vault: `az-p-we-kv-secrets-001`
- VNet: `az-p-we-vnet-main`

See `docs/configuration/AZURE_NAMING_CONVENTION_3CHAR.md` (standard) or `docs/configuration/AZURE_NAMING_CONVENTION_2CHAR.md` (alternative) for details.

## Estimated Costs

Approximate monthly costs (West Europe):
- AKS Cluster: ~$300-500
- VM Nodes (13 nodes): ~$500-800
- Application Gateway: ~$100-200
- Storage: ~$50-100
- Networking: ~$50-100
- **Total: ~$1000-1700/month**

Use Azure Pricing Calculator for accurate estimates.

## Next Steps After Deployment

1. Configure monitoring alerts
2. Set up backup procedures
3. Deploy Blockscout explorer
4. Deploy smart contracts
5. Submit to Ethereum-Lists
6. Configure external integrations

## Support

- Documentation: `docs/`
- Deployment Order: `docs/DEPLOYMENT_ORDER.md`
- Status: `docs/DEPLOYMENT_STATUS.md`

