```
chore: enhance .gitignore and remove obsolete documentation files - Reorganize .gitignore with categorized sections for better maintainability - Add comprehensive ignore patterns for Python, Node.js, databases, logs, and build artifacts - Add project-specific ignore rules for coordinator, explorer, and deployment files - Remove outdated documentation: BITCOIN-WALLET-SETUP.md, LOCAL_ASSETS_SUMMARY.md, README-CONTAINER-DEPLOYMENT.md, README-DOMAIN-DEPLOYMENT.md ```
This commit is contained in:
109
scripts/deploy/container-deploy.py
Normal file
109
scripts/deploy/container-deploy.py
Normal file
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Deploy AITBC services to incus container
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import time
|
||||
import sys
|
||||
|
||||
def run_command(cmd, container=None):
|
||||
"""Run command locally or in container"""
|
||||
if container:
|
||||
cmd = f"incus exec {container} -- {cmd}"
|
||||
print(f"Running: {cmd}")
|
||||
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
print(f"Error: {result.stderr}")
|
||||
return False
|
||||
return True
|
||||
|
||||
def deploy_to_container():
|
||||
container = "aitbc"
|
||||
container_ip = "10.1.223.93"
|
||||
|
||||
print("🚀 Deploying AITBC services to container...")
|
||||
|
||||
# Stop local services
|
||||
print("\n📋 Stopping local services...")
|
||||
subprocess.run("sudo fuser -k 8000/tcp 2>/dev/null || true", shell=True)
|
||||
subprocess.run("sudo fuser -k 9080/tcp 2>/dev/null || true", shell=True)
|
||||
subprocess.run("pkill -f 'marketplace-ui' 2>/dev/null || true", shell=True)
|
||||
subprocess.run("pkill -f 'trade-exchange' 2>/dev/null || true", shell=True)
|
||||
|
||||
# Copy project to container
|
||||
print("\n📁 Copying project to container...")
|
||||
subprocess.run(f"incus file push -r /home/oib/windsurf/aitbc {container}/home/oib/", shell=True)
|
||||
|
||||
# Setup Python environment in container
|
||||
print("\n🐍 Setting up Python environment...")
|
||||
run_command("cd /home/oib/aitbc && python3 -m venv .venv", container)
|
||||
run_command("cd /home/oib/aitbc && source .venv/bin/activate && pip install fastapi uvicorn httpx sqlmodel", container)
|
||||
|
||||
# Install dependencies
|
||||
print("\n📦 Installing dependencies...")
|
||||
run_command("cd /home/oib/aitbc/apps/coordinator-api && source ../../.venv/bin/activate && pip install -e .", container)
|
||||
run_command("cd /home/oib/aitbc/apps/blockchain-node && source ../../.venv/bin/activate && pip install -e .", container)
|
||||
|
||||
# Create startup script
|
||||
print("\n🔧 Creating startup script...")
|
||||
startup_script = """#!/bin/bash
|
||||
cd /home/oib/aitbc
|
||||
|
||||
# Start blockchain node
|
||||
echo "Starting blockchain node..."
|
||||
cd apps/blockchain-node
|
||||
source ../../.venv/bin/activate
|
||||
python -m uvicorn aitbc_chain.app:app --host 0.0.0.0 --port 9080 &
|
||||
NODE_PID=$!
|
||||
|
||||
# Start coordinator API
|
||||
echo "Starting coordinator API..."
|
||||
cd ../coordinator-api
|
||||
source ../../.venv/bin/activate
|
||||
python -m uvicorn src.app.main:app --host 0.0.0.0 --port 8000 &
|
||||
COORD_PID=$!
|
||||
|
||||
# Start marketplace UI
|
||||
echo "Starting marketplace UI..."
|
||||
cd ../marketplace-ui
|
||||
python server.py --port 3001 &
|
||||
MARKET_PID=$!
|
||||
|
||||
# Start trade exchange
|
||||
echo "Starting trade exchange..."
|
||||
cd ../trade-exchange
|
||||
python server.py --port 3002 &
|
||||
EXCHANGE_PID=$!
|
||||
|
||||
echo "Services started!"
|
||||
echo "Blockchain: http://10.1.223.93:9080"
|
||||
echo "API: http://10.1.223.93:8000"
|
||||
echo "Marketplace: http://10.1.223.93:3001"
|
||||
echo "Exchange: http://10.1.223.93:3002"
|
||||
|
||||
# Wait for services
|
||||
wait $NODE_PID $COORD_PID $MARKET_PID $EXCHANGE_PID
|
||||
"""
|
||||
|
||||
# Write startup script to container
|
||||
with open('/tmp/start_aitbc.sh', 'w') as f:
|
||||
f.write(startup_script)
|
||||
|
||||
subprocess.run("incus file push /tmp/start_aitbc.sh aitbc/home/oib/", shell=True)
|
||||
run_command("chmod +x /home/oib/start_aitbc.sh", container)
|
||||
|
||||
# Start services
|
||||
print("\n🚀 Starting AITBC services...")
|
||||
run_command("/home/oib/start_aitbc.sh", container)
|
||||
|
||||
print(f"\n✅ Services deployed to container!")
|
||||
print(f"\n📋 Access URLs:")
|
||||
print(f" 🌐 Container IP: {container_ip}")
|
||||
print(f" 📊 Marketplace: http://{container_ip}:3001")
|
||||
print(f" 💱 Trade Exchange: http://{container_ip}:3002")
|
||||
print(f" 🔗 API: http://{container_ip}:8000")
|
||||
print(f" ⛓️ Blockchain: http://{container_ip}:9080")
|
||||
|
||||
if __name__ == "__main__":
|
||||
deploy_to_container()
|
||||
88
scripts/deploy/deploy-domain.sh
Executable file
88
scripts/deploy/deploy-domain.sh
Executable file
@@ -0,0 +1,88 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Deploy AITBC services to domain https://aitbc.bubuit.net
|
||||
|
||||
set -e
|
||||
|
||||
DOMAIN="aitbc.bubuit.net"
|
||||
CONTAINER="aitbc"
|
||||
|
||||
echo "🚀 Deploying AITBC services to https://$DOMAIN"
|
||||
echo ""
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
# Stop local services
|
||||
print_status "Stopping local services..."
|
||||
sudo fuser -k 8000/tcp 2>/dev/null || true
|
||||
sudo fuser -k 9080/tcp 2>/dev/null || true
|
||||
sudo fuser -k 3001/tcp 2>/dev/null || true
|
||||
sudo fuser -k 3002/tcp 2>/dev/null || true
|
||||
|
||||
# Deploy to container
|
||||
print_status "Deploying to container..."
|
||||
python /home/oib/windsurf/aitbc/container-deploy.py
|
||||
|
||||
# Copy nginx config to container
|
||||
print_status "Configuring nginx for domain..."
|
||||
incus file push /home/oib/windsurf/aitbc/nginx-aitbc.conf $CONTAINER/etc/nginx/sites-available/aitbc
|
||||
|
||||
# Enable site
|
||||
incus exec $CONTAINER -- ln -sf /etc/nginx/sites-available/aitbc /etc/nginx/sites-enabled/
|
||||
incus exec $CONTAINER -- rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
# Test nginx config
|
||||
incus exec $CONTAINER -- nginx -t
|
||||
|
||||
# Reload nginx
|
||||
incus exec $CONTAINER -- systemctl reload nginx
|
||||
|
||||
# Install SSL certificate (Let's Encrypt)
|
||||
print_warning "SSL Certificate Setup:"
|
||||
echo "1. Ensure port 80/443 are forwarded to container IP (10.1.223.93)"
|
||||
echo "2. Run certbot in container:"
|
||||
echo " incus exec $CONTAINER -- certbot --nginx -d $DOMAIN"
|
||||
echo ""
|
||||
|
||||
# Update UIs to use correct API endpoints
|
||||
print_status "Updating API endpoints..."
|
||||
|
||||
# Update marketplace API base URL
|
||||
incus exec $CONTAINER -- sed -i "s|http://127.0.0.1:8000|https://$DOMAIN/api|g" /home/oib/aitbc/apps/marketplace-ui/index.html
|
||||
|
||||
# Update exchange API endpoints
|
||||
incus exec $CONTAINER -- sed -i "s|http://127.0.0.1:8000|https://$DOMAIN/api|g" /home/oib/aitbc/apps/trade-exchange/index.html
|
||||
incus exec $CONTAINER -- sed -i "s|http://127.0.0.1:9080|https://$DOMAIN/rpc|g" /home/oib/aitbc/apps/trade-exchange/index.html
|
||||
|
||||
# Restart services to apply changes
|
||||
print_status "Restarting services..."
|
||||
incus exec $CONTAINER -- pkill -f "server.py"
|
||||
sleep 2
|
||||
incus exec $CONTAINER -- /home/oib/start_aitbc.sh
|
||||
|
||||
echo ""
|
||||
print_status "✅ Deployment complete!"
|
||||
echo ""
|
||||
echo "📋 Service URLs:"
|
||||
echo " 🌐 Domain: https://$DOMAIN"
|
||||
echo " 📊 Marketplace: https://$DOMAIN/Marketplace"
|
||||
echo " 💱 Trade Exchange: https://$DOMAIN/Exchange"
|
||||
echo " 🔗 API: https://$DOMAIN/api"
|
||||
echo " ⛓️ Blockchain RPC: https://$DOMAIN/rpc"
|
||||
echo ""
|
||||
echo "📝 Next Steps:"
|
||||
echo "1. Forward ports 80/443 to container IP (10.1.223.93)"
|
||||
echo "2. Install SSL certificate:"
|
||||
echo " incus exec $CONTAINER -- certbot --nginx -d $DOMAIN"
|
||||
echo "3. Test services at the URLs above"
|
||||
74
scripts/deploy/deploy-exchange.sh
Executable file
74
scripts/deploy/deploy-exchange.sh
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Deploy AITBC Trade Exchange to the server
|
||||
|
||||
set -e
|
||||
|
||||
SERVER="root@10.1.223.93"
|
||||
EXCHANGE_DIR="/root/aitbc/apps/trade-exchange"
|
||||
|
||||
echo "🚀 Deploying AITBC Trade Exchange"
|
||||
echo "=================================="
|
||||
echo "Server: $SERVER"
|
||||
echo ""
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
# Test SSH connection
|
||||
print_status "Testing SSH connection..."
|
||||
ssh $SERVER "hostname && ip a show eth0 | grep inet"
|
||||
|
||||
# Copy updated files
|
||||
print_status "Copying updated Exchange files..."
|
||||
scp /home/oib/windsurf/aitbc/apps/trade-exchange/index.html $SERVER:$EXCHANGE_DIR/
|
||||
scp /home/oib/windsurf/aitbc/apps/trade-exchange/server.py $SERVER:$EXCHANGE_DIR/
|
||||
|
||||
# Ensure assets are available
|
||||
print_status "Ensuring assets directory exists..."
|
||||
ssh $SERVER "mkdir -p /var/www/aitbc.bubuit.net/assets"
|
||||
ssh $SERVER "mkdir -p /var/www/aitbc.bubuit.net/assets/css"
|
||||
ssh $SERVER "mkdir -p /var/www/aitbc.bubuit.net/assets/js"
|
||||
|
||||
# Copy assets if they don't exist
|
||||
print_status "Copying assets if needed..."
|
||||
if ! ssh $SERVER "test -f /var/www/aitbc.bubuit.net/assets/css/aitbc.css"; then
|
||||
scp -r /home/oib/windsurf/aitbc/assets/* $SERVER:/var/www/aitbc.bubuit.net/assets/
|
||||
fi
|
||||
|
||||
# Restart the exchange service
|
||||
print_status "Restarting Trade Exchange service..."
|
||||
ssh $SERVER "systemctl restart aitbc-exchange"
|
||||
|
||||
# Wait for service to start
|
||||
print_status "Waiting for service to start..."
|
||||
sleep 5
|
||||
|
||||
# Check service status
|
||||
print_status "Checking service status..."
|
||||
ssh $SERVER "systemctl status aitbc-exchange --no-pager -l | head -10"
|
||||
|
||||
# Test the endpoint
|
||||
print_status "Testing Exchange endpoint..."
|
||||
ssh $SERVER "curl -s http://127.0.0.1:3002/ | head -c 100"
|
||||
echo ""
|
||||
|
||||
echo ""
|
||||
print_status "✅ Exchange deployment complete!"
|
||||
echo ""
|
||||
echo "📋 URLs:"
|
||||
echo " 🌐 IP: http://10.1.223.93/Exchange"
|
||||
echo " 🔒 Domain: https://aitbc.bubuit.net/Exchange"
|
||||
echo ""
|
||||
echo "🔍 To check logs:"
|
||||
echo " ssh $SERVER 'journalctl -u aitbc-exchange -f'"
|
||||
66
scripts/deploy/deploy-explorer.sh
Executable file
66
scripts/deploy/deploy-explorer.sh
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Deploy AITBC Explorer to the server
|
||||
|
||||
set -e
|
||||
|
||||
SERVER="root@10.1.223.93"
|
||||
EXPLORER_DIR="/root/aitbc/apps/explorer-web"
|
||||
NGINX_CONFIG="/etc/nginx/sites-available/aitbc"
|
||||
|
||||
echo "🚀 Deploying AITBC Explorer to Server"
|
||||
echo "====================================="
|
||||
echo "Server: $SERVER"
|
||||
echo ""
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
# Build the explorer locally first
|
||||
print_status "Building explorer locally..."
|
||||
cd /home/oib/windsurf/aitbc/apps/explorer-web
|
||||
npm run build
|
||||
|
||||
# Copy built files to server
|
||||
print_status "Copying explorer build to server..."
|
||||
scp -r dist $SERVER:$EXPLORER_DIR/
|
||||
|
||||
# Update nginx config to include explorer
|
||||
print_status "Updating nginx configuration..."
|
||||
|
||||
# Backup current config
|
||||
ssh $SERVER "cp $NGINX_CONFIG ${NGINX_CONFIG}.backup"
|
||||
|
||||
# Add explorer location to nginx config
|
||||
ssh $SERVER "sed -i '/# Health endpoint/i\\
|
||||
# Explorer\\
|
||||
location /explorer/ {\\
|
||||
alias /root/aitbc/apps/explorer-web/dist/;\\
|
||||
try_files \$uri \$uri/ /explorer/index.html;\\
|
||||
}\\
|
||||
\\
|
||||
# Explorer mock data\\
|
||||
location /explorer/mock/ {\\
|
||||
alias /root/aitbc/apps/explorer-web/public/mock/;\\
|
||||
}\\
|
||||
' $NGINX_CONFIG"
|
||||
|
||||
# Test and reload nginx
|
||||
print_status "Testing and reloading nginx..."
|
||||
ssh $SERVER "nginx -t && systemctl reload nginx"
|
||||
|
||||
print_status "✅ Explorer deployment complete!"
|
||||
echo ""
|
||||
echo "📋 Explorer URL:"
|
||||
echo " 🌐 Explorer: https://aitbc.bubuit.net/explorer/"
|
||||
echo ""
|
||||
55
scripts/deploy/deploy-production.sh
Normal file
55
scripts/deploy/deploy-production.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🚀 Deploying AITBC for Production..."
|
||||
|
||||
# 1. Setup production assets
|
||||
echo "📦 Setting up production assets..."
|
||||
bash setup-production-assets.sh
|
||||
|
||||
# 2. Copy assets to server
|
||||
echo "📋 Copying assets to server..."
|
||||
scp -r assets/ aitbc:/var/www/html/
|
||||
|
||||
# 3. Update Nginx configuration
|
||||
echo "⚙️ Updating Nginx configuration..."
|
||||
ssh aitbc "cat >> /etc/nginx/sites-available/aitbc.conf << 'EOF'
|
||||
|
||||
# Serve production assets
|
||||
location /assets/ {
|
||||
alias /var/www/html/assets/;
|
||||
expires 1y;
|
||||
add_header Cache-Control \"public, immutable\";
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
|
||||
# Gzip compression
|
||||
gzip on;
|
||||
gzip_types text/css application/javascript image/svg+xml;
|
||||
}
|
||||
|
||||
# Security headers
|
||||
add_header Referrer-Policy \"strict-origin-when-cross-origin\" always;
|
||||
add_header X-Frame-Options \"SAMEORIGIN\" always;
|
||||
add_header X-Content-Type-Options \"nosniff\" always;
|
||||
EOF"
|
||||
|
||||
# 4. Reload Nginx
|
||||
echo "🔄 Reloading Nginx..."
|
||||
ssh aitbc "nginx -t && systemctl reload nginx"
|
||||
|
||||
# 5. Update Exchange page to use production assets
|
||||
echo "🔄 Updating Exchange page..."
|
||||
scp apps/trade-exchange/index.prod.html aitbc:/root/aitbc/apps/trade-exchange/index.html
|
||||
|
||||
# 6. Update Marketplace page
|
||||
echo "🔄 Updating Marketplace page..."
|
||||
sed -i 's|https://cdn.tailwindcss.com|/assets/js/tailwind.js|g' apps/marketplace-ui/index.html
|
||||
sed -i 's|https://unpkg.com/axios/dist/axios.min.js|/assets/js/axios.min.js|g' apps/marketplace-ui/index.html
|
||||
sed -i 's|https://unpkg.com/lucide@latest|/assets/js/lucide.js|g' apps/marketplace-ui/index.html
|
||||
scp apps/marketplace-ui/index.html aitbc:/root/aitbc/apps/marketplace-ui/
|
||||
|
||||
echo "✅ Production deployment complete!"
|
||||
echo ""
|
||||
echo "📝 Next steps:"
|
||||
echo "1. Restart services: ssh aitbc 'systemctl restart aitbc-exchange aitbc-marketplace-ui'"
|
||||
echo "2. Clear browser cache"
|
||||
echo "3. Test all pages"
|
||||
253
scripts/deploy/deploy-to-container.sh
Executable file
253
scripts/deploy/deploy-to-container.sh
Executable file
@@ -0,0 +1,253 @@
|
||||
#!/bin/bash
|
||||
|
||||
# AITBC Services Deployment to Incus Container
|
||||
# This script deploys all AITBC services to the 'aitbc' container
|
||||
|
||||
set -e
|
||||
|
||||
CONTAINER_NAME="aitbc"
|
||||
CONTAINER_IP="10.1.223.93"
|
||||
PROJECT_DIR="/home/oib/windsurf/aitbc"
|
||||
|
||||
echo "🚀 Deploying AITBC services to container: $CONTAINER_NAME"
|
||||
echo "Container IP: $CONTAINER_IP"
|
||||
echo ""
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Stop local services
|
||||
print_status "Stopping local AITBC services..."
|
||||
sudo fuser -k 8000/tcp 2>/dev/null || true
|
||||
sudo fuser -k 9080/tcp 2>/dev/null || true
|
||||
sudo fuser -k 3001/tcp 2>/dev/null || true
|
||||
sudo fuser -k 3002/tcp 2>/dev/null || true
|
||||
pkill -f "aitbc_chain.app" 2>/dev/null || true
|
||||
pkill -f "marketplace-ui" 2>/dev/null || true
|
||||
pkill -f "trade-exchange" 2>/dev/null || true
|
||||
|
||||
# Copy project to container
|
||||
print_status "Copying AITBC project to container..."
|
||||
incus file push -r $PROJECT_DIR $CONTAINER_NAME/home/oib/
|
||||
|
||||
# Setup container environment
|
||||
print_status "Setting up container environment..."
|
||||
incus exec $CONTAINER_NAME -- bash -c "
|
||||
cd /home/oib/aitbc
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate
|
||||
pip install --upgrade pip
|
||||
"
|
||||
|
||||
# Install dependencies for each service
|
||||
print_status "Installing dependencies..."
|
||||
|
||||
# Coordinator API
|
||||
print_status "Installing Coordinator API dependencies..."
|
||||
incus exec $CONTAINER_NAME -- bash -c "
|
||||
cd /home/oib/aitbc/apps/coordinator-api
|
||||
source ../.venv/bin/activate
|
||||
pip install -e .
|
||||
pip install fastapi uvicorn
|
||||
"
|
||||
|
||||
# Blockchain Node
|
||||
print_status "Installing Blockchain Node dependencies..."
|
||||
incus exec $CONTAINER_NAME -- bash -c "
|
||||
cd /home/oib/aitbc/apps/blockchain-node
|
||||
source ../.venv/bin/activate
|
||||
pip install -e .
|
||||
pip install fastapi uvicorn
|
||||
"
|
||||
|
||||
# Create systemd service files
|
||||
print_status "Creating systemd services..."
|
||||
|
||||
# Coordinator API service
|
||||
incus exec $CONTAINER_NAME -- tee /etc/systemd/system/aitbc-coordinator.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=AITBC Coordinator API
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=oib
|
||||
Group=oib
|
||||
WorkingDirectory=/home/oib/aitbc/apps/coordinator-api
|
||||
Environment=PATH=/home/oib/aitbc/.venv/bin
|
||||
ExecStart=/home/oib/aitbc/.venv/bin/python -m uvicorn src.app.main:app --host 0.0.0.0 --port 8000
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Blockchain Node service
|
||||
incus exec $CONTAINER_NAME -- tee /etc/systemd/system/aitbc-blockchain.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=AITBC Blockchain Node
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=oib
|
||||
Group=oib
|
||||
WorkingDirectory=/home/oib/aitbc/apps/blockchain-node
|
||||
Environment=PATH=/home/oib/aitbc/.venv/bin
|
||||
ExecStart=/home/oib/aitbc/.venv/bin/python -m uvicorn aitbc_chain.app:app --host 0.0.0.0 --port 9080
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Marketplace UI service
|
||||
incus exec $CONTAINER_NAME -- tee /etc/systemd/system/aitbc-marketplace.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=AITBC Marketplace UI
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=oib
|
||||
Group=oib
|
||||
WorkingDirectory=/home/oib/aitbc/apps/marketplace-ui
|
||||
Environment=PATH=/home/oib/aitbc/.venv/bin
|
||||
ExecStart=/home/oib/aitbc/.venv/bin/python server.py --port 3001
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Trade Exchange service
|
||||
incus exec $CONTAINER_NAME -- tee /etc/systemd/system/aitbc-exchange.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=AITBC Trade Exchange
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=oib
|
||||
Group=oib
|
||||
WorkingDirectory=/home/oib/aitbc/apps/trade-exchange
|
||||
Environment=PATH=/home/oib/aitbc/.venv/bin
|
||||
ExecStart=/home/oib/aitbc/.venv/bin/python server.py --port 3002
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Reload systemd and start services
|
||||
print_status "Starting AITBC services..."
|
||||
incus exec $CONTAINER_NAME -- systemctl daemon-reload
|
||||
incus exec $CONTAINER_NAME -- systemctl enable aitbc-coordinator
|
||||
incus exec $CONTAINER_NAME -- systemctl enable aitbc-blockchain
|
||||
incus exec $CONTAINER_NAME -- systemctl enable aitbc-marketplace
|
||||
incus exec $CONTAINER_NAME -- systemctl enable aitbc-exchange
|
||||
|
||||
incus exec $CONTAINER_NAME -- systemctl start aitbc-coordinator
|
||||
incus exec $CONTAINER_NAME -- systemctl start aitbc-blockchain
|
||||
incus exec $CONTAINER_NAME -- systemctl start aitbc-marketplace
|
||||
incus exec $CONTAINER_NAME -- systemctl start aitbc-exchange
|
||||
|
||||
# Wait for services to start
|
||||
print_status "Waiting for services to start..."
|
||||
sleep 10
|
||||
|
||||
# Check service status
|
||||
print_status "Checking service status..."
|
||||
incus exec $CONTAINER_NAME -- systemctl status aitbc-coordinator --no-pager -l
|
||||
incus exec $CONTAINER_NAME -- systemctl status aitbc-blockchain --no-pager -l
|
||||
incus exec $CONTAINER_NAME -- systemctl status aitbc-marketplace --no-pager -l
|
||||
incus exec $CONTAINER_NAME -- systemctl status aitbc-exchange --no-pager -l
|
||||
|
||||
# Create nginx configuration for reverse proxy
|
||||
print_status "Setting up Nginx reverse proxy..."
|
||||
incus exec $CONTAINER_NAME -- tee /etc/nginx/sites-available/aitbc > /dev/null <<EOF
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
# Coordinator API
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:8000/v1/;
|
||||
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;
|
||||
}
|
||||
|
||||
# Blockchain RPC
|
||||
location /rpc/ {
|
||||
proxy_pass http://127.0.0.1:9080/rpc/;
|
||||
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;
|
||||
}
|
||||
|
||||
# Marketplace UI
|
||||
location /marketplace/ {
|
||||
proxy_pass http://127.0.0.1:3001/;
|
||||
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;
|
||||
}
|
||||
|
||||
# Trade Exchange
|
||||
location /exchange/ {
|
||||
proxy_pass http://127.0.0.1:3002/;
|
||||
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;
|
||||
}
|
||||
|
||||
# Default redirect to marketplace
|
||||
location / {
|
||||
return 301 /marketplace/;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Enable nginx site
|
||||
incus exec $CONTAINER_NAME -- ln -sf /etc/nginx/sites-available/aitbc /etc/nginx/sites-enabled/
|
||||
incus exec $CONTAINER_NAME -- rm -f /etc/nginx/sites-enabled/default
|
||||
incus exec $CONTAINER_NAME -- nginx -t && incus exec $CONTAINER_NAME -- systemctl reload nginx
|
||||
|
||||
# Print access information
|
||||
echo ""
|
||||
print_status "✅ AITBC services deployed successfully!"
|
||||
echo ""
|
||||
echo "📋 Service URLs:"
|
||||
echo " 🌐 Public IP: $CONTAINER_IP"
|
||||
echo " 📊 Marketplace: http://$CONTAINER_IP/marketplace/"
|
||||
echo " 💱 Trade Exchange: http://$CONTAINER_IP/exchange/"
|
||||
echo " 🔗 API: http://$CONTAINER_IP/api/"
|
||||
echo " ⛓️ Blockchain RPC: http://$CONTAINER_IP/rpc/"
|
||||
echo ""
|
||||
print_status "To check logs: incus exec $CONTAINER_NAME -- journalctl -u aitbc-coordinator -f"
|
||||
print_status "To restart services: incus exec $CONTAINER_NAME -- systemctl restart aitbc-*"
|
||||
241
scripts/deploy/deploy-to-server.sh
Executable file
241
scripts/deploy/deploy-to-server.sh
Executable file
@@ -0,0 +1,241 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Deploy AITBC services to the aitbc server (10.1.223.93)
|
||||
|
||||
set -e
|
||||
|
||||
SERVER="root@10.1.223.93"
|
||||
PROJECT_DIR="/root/aitbc"
|
||||
|
||||
echo "🚀 Deploying AITBC to Server"
|
||||
echo "=========================="
|
||||
echo "Server: $SERVER"
|
||||
echo ""
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
# Test SSH connection
|
||||
print_status "Testing SSH connection..."
|
||||
ssh $SERVER "hostname && ip a show eth0 | grep inet"
|
||||
|
||||
# Copy project to server
|
||||
print_status "Copying project to server..."
|
||||
ssh $SERVER "rm -rf $PROJECT_DIR 2>/dev/null || true"
|
||||
scp -r /home/oib/windsurf/aitbc $SERVER:/root/
|
||||
|
||||
# Setup Python environment
|
||||
print_status "Setting up Python environment..."
|
||||
ssh $SERVER "cd $PROJECT_DIR && python3 -m venv .venv && source .venv/bin/activate && pip install --upgrade pip"
|
||||
|
||||
# Install dependencies
|
||||
print_status "Installing dependencies..."
|
||||
ssh $SERVER "cd $PROJECT_DIR/apps/coordinator-api && source ../../.venv/bin/activate && pip install -e ."
|
||||
ssh $SERVER "cd $PROJECT_DIR/apps/blockchain-node && source ../../.venv/bin/activate && pip install -e ."
|
||||
|
||||
# Create systemd service files
|
||||
print_status "Creating systemd services..."
|
||||
|
||||
# Coordinator API service
|
||||
ssh $SERVER 'cat > /etc/systemd/system/aitbc-coordinator.service << EOF
|
||||
[Unit]
|
||||
Description=AITBC Coordinator API
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=root
|
||||
WorkingDirectory=/root/aitbc/apps/coordinator-api
|
||||
Environment=PATH=/root/aitbc/.venv/bin
|
||||
ExecStart=/root/aitbc/.venv/bin/python -m uvicorn src.app.main:app --host 0.0.0.0 --port 8000
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF'
|
||||
|
||||
# Blockchain Node service
|
||||
ssh $SERVER 'cat > /etc/systemd/system/aitbc-blockchain.service << EOF
|
||||
[Unit]
|
||||
Description=AITBC Blockchain Node
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=root
|
||||
WorkingDirectory=/root/aitbc/apps/blockchain-node
|
||||
Environment=PATH=/root/aitbc/.venv/bin
|
||||
ExecStart=/root/aitbc/.venv/bin/python -m uvicorn aitbc_chain.app:app --host 0.0.0.0 --port 9080
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF'
|
||||
|
||||
# Marketplace UI service
|
||||
ssh $SERVER 'cat > /etc/systemd/system/aitbc-marketplace.service << EOF
|
||||
[Unit]
|
||||
Description=AITBC Marketplace UI
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=root
|
||||
WorkingDirectory=/root/aitbc/apps/marketplace-ui
|
||||
Environment=PATH=/root/aitbc/.venv/bin
|
||||
ExecStart=/root/aitbc/.venv/bin/python server.py --port 3001
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF'
|
||||
|
||||
# Trade Exchange service
|
||||
ssh $SERVER 'cat > /etc/systemd/system/aitbc-exchange.service << EOF
|
||||
[Unit]
|
||||
Description=AITBC Trade Exchange
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
User=root
|
||||
WorkingDirectory=/root/aitbc/apps/trade-exchange
|
||||
Environment=PATH=/root/aitbc/.venv/bin
|
||||
ExecStart=/root/aitbc/.venv/bin/python server.py --port 3002
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF'
|
||||
|
||||
# Install nginx if not installed
|
||||
print_status "Installing nginx..."
|
||||
ssh $SERVER "apt update && apt install -y nginx"
|
||||
|
||||
# Create nginx configuration
|
||||
print_status "Configuring nginx..."
|
||||
ssh $SERVER 'cat > /etc/nginx/sites-available/aitbc << EOF
|
||||
server {
|
||||
listen 80;
|
||||
server_name aitbc.bubuit.net;
|
||||
|
||||
# API routes
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:8000/v1/;
|
||||
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;
|
||||
}
|
||||
|
||||
# Admin routes
|
||||
location /admin/ {
|
||||
proxy_pass http://127.0.0.1:8000/admin/;
|
||||
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;
|
||||
}
|
||||
|
||||
# Blockchain RPC
|
||||
location /rpc/ {
|
||||
proxy_pass http://127.0.0.1:9080/rpc/;
|
||||
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;
|
||||
}
|
||||
|
||||
# Marketplace UI
|
||||
location /Marketplace {
|
||||
proxy_pass http://127.0.0.1:3001/;
|
||||
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;
|
||||
}
|
||||
|
||||
# Trade Exchange
|
||||
location /Exchange {
|
||||
proxy_pass http://127.0.0.1:3002/;
|
||||
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;
|
||||
}
|
||||
|
||||
# Health endpoint
|
||||
location /health {
|
||||
proxy_pass http://127.0.0.1:8000/v1/health;
|
||||
proxy_set_header Host \$host;
|
||||
}
|
||||
|
||||
# Default redirect
|
||||
location / {
|
||||
return 301 /Marketplace;
|
||||
}
|
||||
}
|
||||
EOF'
|
||||
|
||||
# Enable nginx site
|
||||
ssh $SERVER "ln -sf /etc/nginx/sites-available/aitbc /etc/nginx/sites-enabled/"
|
||||
ssh $SERVER "rm -f /etc/nginx/sites-enabled/default"
|
||||
|
||||
# Test and reload nginx
|
||||
ssh $SERVER "nginx -t && systemctl reload nginx"
|
||||
|
||||
# Start services
|
||||
print_status "Starting AITBC services..."
|
||||
ssh $SERVER "systemctl daemon-reload"
|
||||
ssh $SERVER "systemctl enable aitbc-coordinator aitbc-blockchain aitbc-marketplace aitbc-exchange"
|
||||
ssh $SERVER "systemctl start aitbc-coordinator aitbc-blockchain aitbc-marketplace aitbc-exchange"
|
||||
|
||||
# Wait for services to start
|
||||
print_status "Waiting for services to start..."
|
||||
sleep 10
|
||||
|
||||
# Check service status
|
||||
print_status "Checking service status..."
|
||||
ssh $SERVER "systemctl status aitbc-coordinator --no-pager -l | head -10"
|
||||
ssh $SERVER "systemctl status aitbc-blockchain --no-pager -l | head -10"
|
||||
|
||||
# Test endpoints
|
||||
print_status "Testing endpoints..."
|
||||
ssh $SERVER "curl -s http://127.0.0.1:8000/v1/health | head -c 100"
|
||||
echo ""
|
||||
ssh $SERVER "curl -s http://127.0.0.1:8000/v1/admin/stats -H 'X-Api-Key: REDACTED_ADMIN_KEY' | head -c 100"
|
||||
echo ""
|
||||
|
||||
echo ""
|
||||
print_status "✅ Deployment complete!"
|
||||
echo ""
|
||||
echo "📋 Service URLs:"
|
||||
echo " 🌐 Server IP: 10.1.223.93"
|
||||
echo " 📊 Marketplace: http://10.1.223.93/Marketplace"
|
||||
echo " 💱 Trade Exchange: http://10.1.223.93/Exchange"
|
||||
echo " 🔗 API: http://10.1.223.93/api"
|
||||
echo " ⛓️ Blockchain RPC: http://10.1.223.93/rpc"
|
||||
echo ""
|
||||
echo "🔒 Domain URLs (with SSL):"
|
||||
echo " 📊 Marketplace: https://aitbc.bubuit.net/Marketplace"
|
||||
echo " 💱 Trade Exchange: https://aitbc.bubuit.net/Exchange"
|
||||
echo " 🔗 API: https://aitbc.bubuit.net/api"
|
||||
echo " ⛓️ Blockchain RPC: https://aitbc.bubuit.net/rpc"
|
||||
echo ""
|
||||
print_status "To manage services:"
|
||||
echo " ssh aitbc 'systemctl status aitbc-coordinator'"
|
||||
echo " ssh aitbc 'journalctl -u aitbc-coordinator -f'"
|
||||
158
scripts/deploy/deploy_container_with_miner.py
Normal file
158
scripts/deploy/deploy_container_with_miner.py
Normal file
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Deploy AITBC services to incus container with GPU miner integration
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import time
|
||||
import sys
|
||||
|
||||
def run_command(cmd, container=None):
|
||||
"""Run command locally or in container"""
|
||||
if container:
|
||||
cmd = f"incus exec {container} -- {cmd}"
|
||||
print(f"Running: {cmd}")
|
||||
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
print(f"Error: {result.stderr}")
|
||||
return False
|
||||
return True
|
||||
|
||||
def deploy_to_container():
|
||||
container = "aitbc"
|
||||
container_ip = "10.1.223.93"
|
||||
|
||||
print("🚀 Deploying AITBC services to container with GPU miner...")
|
||||
|
||||
# Check if container exists
|
||||
result = subprocess.run("incus list -c n", shell=True, capture_output=True, text=True)
|
||||
if container not in result.stdout:
|
||||
print(f"\n📦 Creating container {container}...")
|
||||
subprocess.run(f"incus launch images:ubuntu/22.04 {container}", shell=True)
|
||||
time.sleep(10)
|
||||
|
||||
# Ensure container is running
|
||||
subprocess.run(f"incus start {container}", shell=True)
|
||||
time.sleep(5)
|
||||
|
||||
# Update and install packages in container
|
||||
print("\n📦 Installing packages in container...")
|
||||
run_command("apt-get update", container)
|
||||
run_command("apt-get install -y python3 python3-pip python3-venv curl", container)
|
||||
|
||||
# Stop local services
|
||||
print("\n📋 Stopping local services...")
|
||||
subprocess.run("sudo fuser -k 8000/tcp 2>/dev/null || true", shell=True)
|
||||
subprocess.run("sudo fuser -k 9080/tcp 2>/dev/null || true", shell=True)
|
||||
subprocess.run("pkill -f 'marketplace-ui' 2>/dev/null || true", shell=True)
|
||||
subprocess.run("pkill -f 'trade-exchange' 2>/dev/null || true", shell=True)
|
||||
|
||||
# Copy project to container
|
||||
print("\n📁 Copying project to container...")
|
||||
subprocess.run(f"incus file push -r /home/oib/windsurf/aitbc {container}/home/oib/", shell=True)
|
||||
|
||||
# Setup Python environment in container
|
||||
print("\n🐍 Setting up Python environment...")
|
||||
run_command("cd /home/oib/aitbc && python3 -m venv .venv", container)
|
||||
run_command("cd /home/oib/aitbc && source .venv/bin/activate && pip install fastapi uvicorn httpx sqlmodel psutil", container)
|
||||
|
||||
# Install dependencies
|
||||
print("\n📦 Installing dependencies...")
|
||||
run_command("cd /home/oib/aitbc/apps/coordinator-api && source ../../.venv/bin/activate && pip install -e .", container)
|
||||
run_command("cd /home/oib/aitbc/apps/blockchain-node && source ../../.venv/bin/activate && pip install -e .", container)
|
||||
|
||||
# Create startup script with GPU miner
|
||||
print("\n🔧 Creating startup script with GPU miner...")
|
||||
startup_script = """#!/bin/bash
|
||||
cd /home/oib/aitbc
|
||||
source .venv/bin/activate
|
||||
|
||||
# Start coordinator API
|
||||
echo "Starting Coordinator API..."
|
||||
cd apps/coordinator-api
|
||||
source ../../.venv/bin/activate
|
||||
python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 &
|
||||
COORD_PID=$!
|
||||
|
||||
# Start blockchain node
|
||||
echo "Starting Blockchain Node..."
|
||||
cd ../../apps/blockchain-node
|
||||
source ../../.venv/bin/activate
|
||||
python -m uvicorn aitbc_chain.app:app --host 0.0.0.0 --port 9080 &
|
||||
BLOCK_PID=$!
|
||||
|
||||
# Start trade exchange
|
||||
echo "Starting Trade Exchange..."
|
||||
cd ../../apps/trade-exchange
|
||||
source ../../.venv/bin/activate
|
||||
python simple_exchange_api.py &
|
||||
EXCHANGE_PID=$!
|
||||
|
||||
# Start GPU registry
|
||||
echo "Starting GPU Registry..."
|
||||
cd ../..
|
||||
python gpu_registry_demo.py &
|
||||
REGISTRY_PID=$!
|
||||
|
||||
# Start GPU miner
|
||||
echo "Starting GPU Miner..."
|
||||
python gpu_miner_with_wait.py &
|
||||
MINER_PID=$!
|
||||
|
||||
echo "All services started!"
|
||||
echo "Coordinator API: http://10.1.223.93:8000"
|
||||
echo "Blockchain RPC: http://10.1.223.93:9080"
|
||||
echo "Trade Exchange: http://10.1.223.93:3002"
|
||||
echo "GPU Registry: http://10.1.223.93:8091"
|
||||
|
||||
# Wait for services
|
||||
wait $COORD_PID $BLOCK_PID $EXCHANGE_PID $REGISTRY_PID $MINER_PID
|
||||
"""
|
||||
|
||||
# Write startup script to container
|
||||
with open('/tmp/startup.sh', 'w') as f:
|
||||
f.write(startup_script)
|
||||
subprocess.run(f"incus file push /tmp/startup.sh {container}/home/oib/aitbc/", shell=True)
|
||||
run_command("chmod +x /home/oib/aitbc/startup.sh", container)
|
||||
|
||||
# Create systemd service
|
||||
print("\n⚙️ Creating systemd service...")
|
||||
service_content = """[Unit]
|
||||
Description=AITBC Services with GPU Miner
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=oib
|
||||
WorkingDirectory=/home/oib/aitbc
|
||||
ExecStart=/home/oib/aitbc/startup.sh
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
"""
|
||||
|
||||
with open('/tmp/aitbc.service', 'w') as f:
|
||||
f.write(service_content)
|
||||
subprocess.run(f"incus file push /tmp/aitbc.service {container}/tmp/", shell=True)
|
||||
run_command("mv /tmp/aitbc.service /etc/systemd/system/", container)
|
||||
run_command("systemctl daemon-reload", container)
|
||||
run_command("systemctl enable aitbc.service", container)
|
||||
run_command("systemctl start aitbc.service", container)
|
||||
|
||||
print("\n✅ Deployment complete!")
|
||||
print(f"\n📊 Service URLs:")
|
||||
print(f" - Coordinator API: http://{container_ip}:8000")
|
||||
print(f" - Blockchain RPC: http://{container_ip}:9080")
|
||||
print(f" - Trade Exchange: http://{container_ip}:3002")
|
||||
print(f" - GPU Registry: http://{container_ip}:8091")
|
||||
print(f"\n🔍 Check GPU status:")
|
||||
print(f" curl http://{container_ip}:8091/miners/list")
|
||||
|
||||
print(f"\n📋 To manage services in container:")
|
||||
print(f" incus exec {container} -- systemctl status aitbc")
|
||||
print(f" incus exec {container} -- journalctl -u aitbc -f")
|
||||
|
||||
if __name__ == "__main__":
|
||||
deploy_to_container()
|
||||
130
scripts/deploy/deploy_gpu_to_container.py
Normal file
130
scripts/deploy/deploy_gpu_to_container.py
Normal file
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Deploy GPU Miner Integration to AITBC Container
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def run_in_container(cmd):
|
||||
"""Run command in aitbc container"""
|
||||
full_cmd = f"incus exec aitbc -- {cmd}"
|
||||
print(f"Running: {full_cmd}")
|
||||
result = subprocess.run(full_cmd, shell=True, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
print(f"Error: {result.stderr}")
|
||||
return False, result.stderr
|
||||
return True, result.stdout
|
||||
|
||||
def deploy_gpu_miner_to_container():
|
||||
print("🚀 Deploying GPU Miner Integration to AITBC Container...")
|
||||
|
||||
# Check container access
|
||||
print("\n1. 🔍 Checking container access...")
|
||||
success, output = run_in_container("whoami")
|
||||
if success:
|
||||
print(f" Container user: {output.strip()}")
|
||||
else:
|
||||
print(" ❌ Cannot access container")
|
||||
return
|
||||
|
||||
# Copy GPU miner files to container
|
||||
print("\n2. 📁 Copying GPU miner files...")
|
||||
files_to_copy = [
|
||||
"gpu_miner_with_wait.py",
|
||||
"gpu_registry_demo.py"
|
||||
]
|
||||
|
||||
for file in files_to_copy:
|
||||
cmd = f"incus file push /home/oib/windsurf/aitbc/{file} aitbc/home/oib/"
|
||||
print(f" Copying {file}...")
|
||||
result = subprocess.run(cmd, shell=True)
|
||||
if result.returncode == 0:
|
||||
print(f" ✅ {file} copied")
|
||||
else:
|
||||
print(f" ❌ Failed to copy {file}")
|
||||
|
||||
# Install dependencies in container
|
||||
print("\n3. 📦 Installing dependencies...")
|
||||
run_in_container("pip install httpx fastapi uvicorn psutil")
|
||||
|
||||
# Create GPU miner service in container
|
||||
print("\n4. ⚙️ Creating GPU miner service...")
|
||||
service_content = """[Unit]
|
||||
Description=AITBC GPU Miner Client
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=oib
|
||||
WorkingDirectory=/home/oib
|
||||
ExecStart=/usr/bin/python3 gpu_miner_with_wait.py
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
"""
|
||||
|
||||
# Write service file to container
|
||||
with open('/tmp/gpu-miner.service', 'w') as f:
|
||||
f.write(service_content)
|
||||
subprocess.run("incus file push /tmp/gpu-miner.service aitbc/tmp/", shell=True)
|
||||
run_in_container("sudo mv /tmp/gpu-miner.service /etc/systemd/system/")
|
||||
run_in_container("sudo systemctl daemon-reload")
|
||||
run_in_container("sudo systemctl enable gpu-miner.service")
|
||||
run_in_container("sudo systemctl start gpu-miner.service")
|
||||
|
||||
# Create GPU registry service in container
|
||||
print("\n5. 🎮 Creating GPU registry service...")
|
||||
registry_service = """[Unit]
|
||||
Description=AITBC GPU Registry
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=oib
|
||||
WorkingDirectory=/home/oib
|
||||
ExecStart=/usr/bin/python3 gpu_registry_demo.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
"""
|
||||
|
||||
with open('/tmp/gpu-registry.service', 'w') as f:
|
||||
f.write(registry_service)
|
||||
subprocess.run("incus file push /tmp/gpu-registry.service aitbc/tmp/", shell=True)
|
||||
run_in_container("sudo mv /tmp/gpu-registry.service /etc/systemd/system/")
|
||||
run_in_container("sudo systemctl daemon-reload")
|
||||
run_in_container("sudo systemctl enable gpu-registry.service")
|
||||
run_in_container("sudo systemctl start gpu-registry.service")
|
||||
|
||||
# Check services
|
||||
print("\n6. 📊 Checking services...")
|
||||
success, output = run_in_container("sudo systemctl status gpu-miner.service --no-pager")
|
||||
print(output)
|
||||
|
||||
success, output = run_in_container("sudo systemctl status gpu-registry.service --no-pager")
|
||||
print(output)
|
||||
|
||||
# Update coordinator to include miner endpoints
|
||||
print("\n7. 🔗 Updating coordinator API...")
|
||||
|
||||
print("\n✅ GPU Miner deployed to container!")
|
||||
print("\n📊 Access URLs:")
|
||||
print(" - Container IP: 10.1.223.93")
|
||||
print(" - GPU Registry: http://10.1.223.93:8091/miners/list")
|
||||
print(" - Coordinator API: http://10.1.223.93:8000")
|
||||
|
||||
print("\n🔧 To manage services in container:")
|
||||
print(" incus exec aitbc -- sudo systemctl status gpu-miner")
|
||||
print(" incus exec aitbc -- sudo journalctl -u gpu-miner -f")
|
||||
|
||||
if __name__ == "__main__":
|
||||
deploy_gpu_miner_to_container()
|
||||
Reference in New Issue
Block a user