<!-- a13f0d0f-7fa5-4ecc-82e3-96ec883dc1c9 b794cc5c-b9e3-43ba-832f-f6f6b3c16d3e -->
# Phase 2 Docker Compose Implementation

## Overview

Create and integrate 5 region-specific docker-compose files for Phase 2 deployment. Each file contains a complete multi-service stack for its respective region node.

## Files to Create

### Docker Compose Files

- `docker/phase2/docker-compose.cus.yml` - Central US (Besu + FireFly Core A + Cacti Core A + Chainlink A + shared DBs + agents)
- `docker/phase2/docker-compose.eus.yml` - East US (Besu + FireFly Core B + primary FireFly/Cacti DBs + Chainlink B + agents)
- `docker/phase2/docker-compose.eus2.yml` - East US 2 (Besu + FireFly DataExchange A + IPFS + Cacti UI + Prometheus primary + agents)
- `docker/phase2/docker-compose.wus.yml` - West US (Besu + FireFly DataExchange B + Prometheus secondary + Grafana + Alertmanager + Chainlink C + agents)
- `docker/phase2/docker-compose.wus2.yml` - West US 2 (Besu + Loki + Log UI + FireFly Postgres Replica + Cacti Core B + agents)

### Terraform Integration

- `terraform/phases/phase2/phase2-main.tf` - Main Phase 2 Terraform configuration
- `terraform/phases/phase2/variables.tf` - Phase 2 variables
- `terraform/phases/phase2/outputs.tf` - Phase 2 outputs

## Implementation Details

### Docker Compose Files Structure

Each docker-compose file includes:

- Besu service (consistent across all regions)
- Region-specific services (FireFly, Cacti, Chainlink variants)
- Database services (PostgreSQL for FireFly and Cacti)
- Monitoring agents (node-exporter, cadvisor, log-shipper)
- Additional services per region (IPFS, Prometheus, Grafana, Loki, etc.)

### Terraform Integration Strategy

1. Create Phase 2 Terraform configuration that:

- References Phase 1 VM outputs to get VM connection details
- Uses `file` provisioner or `remote-exec` to copy docker-compose files to VMs
- Deploys docker-compose files to `/opt/docker-compose/` directory on each VM
- Updates systemd service or creates deployment script to use region-specific compose file

2. Region-to-file mapping:

- `centralus` → `docker-compose.cus.yml`
- `eastus` → `docker-compose.eus.yml`
- `eastus2` → `docker-compose.eus2.yml`
- `westus` → `docker-compose.wus.yml`
- `westus2` → `docker-compose.wus2.yml`

### Key Considerations

- Preserve Phase 1 deployment (don't modify existing Phase 1 configs)
- Use Phase 1 outputs to reference existing VMs
- Handle file deployment via Terraform provisioners
- Update systemd service or create deployment scripts to use correct compose file per region
- Ensure all volume paths are created (e.g., `/opt/besu/*`, `/opt/firefly/*`, `/opt/cacti/*`, `/opt/prometheus/*`, etc.)

### To-dos

- [ ] Create 5 docker-compose files in docker/phase2/ directory (cus, eus, eus2, wus, wus2) with all services from user specifications
- [ ] Create terraform/phases/phase2/ directory structure with main.tf, variables.tf, and outputs.tf
- [ ] Implement Terraform configuration to deploy docker-compose files to VMs using file provisioner or remote-exec
- [ ] Create deployment scripts or systemd service updates to use region-specific docker-compose files on VMs
- [ ] Add Terraform outputs for Phase 2 deployment status and VM connection information