feat: complete remaining phase 1 tasks - multi-chain wallet, atomic swaps, and multi-region deployment

This commit is contained in:
oib
2026-02-28 23:11:55 +01:00
parent 0e6c9eda72
commit bf95cd0d9b
26 changed files with 8091 additions and 6 deletions

View File

@@ -0,0 +1,85 @@
# Geographic Load Balancing Nginx Configuration
# Distributes traffic to the closest regional endpoint based on the client's IP
# Ensure Nginx is compiled with the GeoIP module:
# nginx -V 2>&1 | grep -- --with-http_geoip_module
# Define the GeoIP database location
geoip_country /usr/share/GeoIP/GeoIP.dat;
geoip_city /usr/share/GeoIP/GeoIPCity.dat;
# Map the continent code to an upstream backend
map $geoip_city_continent_code $closest_region {
default us_east_backend; # Default fallback
# North America
NA us_east_backend;
# Europe
EU eu_central_backend;
# Asia
AS ap_northeast_backend;
# Oceania, Africa, South America could map to the nearest available
OC ap_northeast_backend;
AF eu_central_backend;
SA us_east_backend;
}
# Define the upstream backends for each region
upstream us_east_backend {
# US East instances
server 10.1.0.100:8000 max_fails=3 fail_timeout=30s;
server 10.1.0.101:8000 max_fails=3 fail_timeout=30s backup;
keepalive 32;
}
upstream eu_central_backend {
# EU Central instances
server 10.2.0.100:8000 max_fails=3 fail_timeout=30s;
server 10.2.0.101:8000 max_fails=3 fail_timeout=30s backup;
keepalive 32;
}
upstream ap_northeast_backend {
# AP Northeast instances
server 10.3.0.100:8000 max_fails=3 fail_timeout=30s;
server 10.3.0.101:8000 max_fails=3 fail_timeout=30s backup;
keepalive 32;
}
server {
listen 80;
listen 443 ssl http2;
server_name api.aitbc.dev;
# SSL configuration (omitted for brevity, assume Let's Encrypt managed)
# ssl_certificate /etc/letsencrypt/live/api.aitbc.dev/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/api.aitbc.dev/privkey.pem;
# Add headers to indicate routing decisions for debugging
add_header X-Region-Routed $closest_region always;
add_header X-Client-Continent $geoip_city_continent_code always;
location / {
# Proxy traffic to the mapped upstream region
proxy_pass http://$closest_region;
# Standard proxy headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Enable keepalive
proxy_http_version 1.1;
proxy_set_header Connection "";
}
# Health check endpoint for external load balancers/monitors
location /health {
access_log off;
return 200 "OK\n";
}
}

View File

@@ -0,0 +1,77 @@
#!/bin/bash
# Multi-Region Deployment Automation Framework
# Deploys AITBC node services across multiple global regions using systemd over SSH
set -euo pipefail
# Configuration
REGIONS=("us-east" "eu-central" "ap-northeast")
NODE_MAP=(
"us-east:10.1.0.100"
"eu-central:10.2.0.100"
"ap-northeast:10.3.0.100"
)
SSH_USER="aitbc-admin"
SSH_KEY="~/.ssh/aitbc-deploy-key"
APP_DIR="/var/www/aitbc"
SERVICES=("aitbc-coordinator-api" "aitbc-marketplace" "aitbc-agent-worker")
# Logging
log() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')] $1"
}
error() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')] ERROR: $1" >&2
exit 1
}
# Main deployment loop
deploy_to_region() {
local region=$1
local ip=$2
log "Starting deployment to region: $region ($ip)"
# 1. Sync code to remote node
log "[$region] Syncing codebase..."
rsync -avz -e "ssh -i $SSH_KEY" \
--exclude '.git' --exclude 'node_modules' --exclude '.venv' \
../../ $SSH_USER@$ip:$APP_DIR/ || error "Failed to sync to $region"
# 2. Update dependencies
log "[$region] Updating dependencies..."
ssh -i "$SSH_KEY" $SSH_USER@$ip "cd $APP_DIR && poetry install --no-dev" || error "Failed dependency install in $region"
# 3. Apply regional configurations (mocking via sed/echo)
log "[$region] Applying regional configurations..."
ssh -i "$SSH_KEY" $SSH_USER@$ip "sed -i 's/^REGION=.*/REGION=$region/' $APP_DIR/.env"
# 4. Restart systemd services
log "[$region] Restarting systemd services..."
for svc in "${SERVICES[@]}"; do
ssh -i "$SSH_KEY" $SSH_USER@$ip "sudo systemctl restart $svc" || error "Failed to restart $svc in $region"
log "[$region] Service $svc restarted."
done
# 5. Run health check
log "[$region] Verifying health..."
local status
status=$(ssh -i "$SSH_KEY" $SSH_USER@$ip "curl -s -o /dev/null -w '%{http_code}' http://localhost:8000/health")
if [ "$status" != "200" ]; then
error "Health check failed in $region (HTTP $status)"
fi
log "[$region] Deployment successful."
}
# Execute deployments
log "Starting global multi-region deployment..."
for entry in "${NODE_MAP[@]}"; do
region="${entry%%:*}"
ip="${entry##*:}"
# Run deployments sequentially for safety, could be parallelized with &
deploy_to_region "$region" "$ip"
done
log "Global deployment completed successfully across ${#REGIONS[@]} regions."