Files
aitbc/scripts/deployment/deploy/deploy-to-container.sh
aitbc 1d4bc5aac1
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 16s
Blockchain Synchronization Verification / sync-verification (push) Successful in 3s
CLI Tests / test-cli (push) Successful in 13s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Failing after 2s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 2s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Failing after 2s
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Cross-Node Transaction Testing / transaction-test (push) Successful in 9s
Deploy to Testnet / deploy-testnet (push) Successful in 1m7s
Documentation Validation / validate-docs (push) Successful in 8s
Documentation Validation / validate-policies-strict (push) Successful in 14s
Integration Tests / test-service-integration (push) Successful in 2m42s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 10s
Multi-Node Stress Testing / stress-test (push) Successful in 8s
Node Failover Simulation / failover-test (push) Failing after 6s
P2P Network Verification / p2p-verification (push) Successful in 7s
Deploy to Testnet / notify-deployment (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
Package Tests / Python package - aitbc-agent-sdk (push) Failing after 1m5s
Package Tests / Python package - aitbc-core (push) Successful in 58s
Package Tests / Python package - aitbc-crypto (push) Successful in 36s
Package Tests / Python package - aitbc-sdk (push) Successful in 30s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 28s
Package Tests / JavaScript package - aitbc-token (push) Successful in 23s
Production Tests / Production Integration Tests (push) Failing after 1m7s
Staking Tests / test-staking-service (push) Failing after 3s
Staking Tests / test-staking-integration (push) Has been skipped
Staking Tests / test-staking-contract (push) Has been skipped
Staking Tests / run-staking-test-runner (push) Has been skipped
fix: replace hardcoded IPs in deployment scripts with environment variables
- Replace hardcoded IPs in deploy-to-server.sh with AITBC_DEPLOY_SERVER
- Replace hardcoded IPs in deploy-to-container.sh with AITBC_CONTAINER_IP
- Replace hardcoded IPs in deploy-explorer.sh with AITBC_DEPLOY_SERVER
- Replace hardcoded IPs in deploy-exchange.sh with AITBC_DEPLOY_SERVER
- Replace hardcoded IPs in container-deploy.py with AITBC_CONTAINER_IP
- Replace hardcoded IPs in deploy_gpu_to_container.py with AITBC_CONTAINER_IP
- Replace hardcoded IPs in deploy_container_with_miner.py with AITBC_CONTAINER_IP
- Default to localhost if env vars not set
- Addresses report item #4 (hardcoded IPs in deployment scripts)
2026-04-30 08:43:20 +02:00

254 lines
7.3 KiB
Bash
Executable File

#!/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="${AITBC_CONTAINER_IP:-127.0.0.1}"
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-*"