前后端更新
This commit is contained in:
1 parent
a0c8721fbb
commit
24da604727
33 files changed
+1951
-580
No files matched your search
@@ -0,0 +1,41 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add backend to path
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../backend')))
|
||||
|
||||
from app import create_app, db
|
||||
from app.models import User
|
||||
|
||||
app = create_app()
|
||||
|
||||
with app.app_context():
|
||||
print("Checking users...")
|
||||
|
||||
# Check test1
|
||||
user = db.session.query(User).filter_by(username='test1').first()
|
||||
if not user:
|
||||
print("User 'test1' not found. Creating...")
|
||||
user = User(username='test1', email='test1@example.com', role='user', real_name='Test User', employee_id='T001', phone_number='13800138001')
|
||||
user.set_password('test1')
|
||||
db.session.add(user)
|
||||
else:
|
||||
print("User 'test1' found. Resetting password to 'test1'...")
|
||||
user.set_password('test1')
|
||||
user.status = 'active' # Ensure active
|
||||
|
||||
# Check admin
|
||||
admin = db.session.query(User).filter_by(username='admin').first()
|
||||
if not admin:
|
||||
print("User 'admin' not found. Creating...")
|
||||
admin = User(username='admin', email='admin@example.com', role='admin', real_name='Administrator', employee_id='A001', phone_number='13800138000')
|
||||
admin.set_password('admin') # Default admin password
|
||||
db.session.add(admin)
|
||||
else:
|
||||
print("User 'admin' found. Resetting password to 'admin'...")
|
||||
admin.set_password('admin')
|
||||
admin.status = 'active'
|
||||
|
||||
db.session.commit()
|
||||
print("Done.")
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
SERVER_USER="ai30"
|
||||
SERVER_IP="192.168.100.230"
|
||||
REMOTE_DIR="/data/ai-platform/hxops"
|
||||
BACKEND_CONTAINER="hxops-backend"
|
||||
|
||||
echo "=== Starting Remote Server Initialization ==="
|
||||
echo "Target: $SERVER_USER@$SERVER_IP"
|
||||
|
||||
# 1. Check local files exist
|
||||
if [ ! -f "backend/init_db.py" ] || [ ! -f "backend/seed_production.py" ]; then
|
||||
echo "Error: Required files not found locally (backend/init_db.py or backend/seed_production.py)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Upload updated scripts to server
|
||||
echo ">>> Uploading initialization scripts..."
|
||||
scp backend/init_db.py $SERVER_USER@$SERVER_IP:$REMOTE_DIR/backend/
|
||||
scp backend/seed_production.py $SERVER_USER@$SERVER_IP:$REMOTE_DIR/backend/
|
||||
|
||||
# 3. Execute remote commands
|
||||
echo ">>> Executing remote initialization..."
|
||||
ssh $SERVER_USER@$SERVER_IP "cd $REMOTE_DIR && \
|
||||
echo '--- 1. Initializing Database (Create DB if missing) ---' && \
|
||||
docker-compose exec -T $BACKEND_CONTAINER python3 init_db.py && \
|
||||
echo '--- 2. Running Migrations (Create Tables) ---' && \
|
||||
docker-compose exec -T $BACKEND_CONTAINER flask db upgrade && \
|
||||
echo '--- 3. Seeding Data (Admin User & Languages) ---' && \
|
||||
docker-compose exec -T $BACKEND_CONTAINER python3 seed_production.py"
|
||||
|
||||
echo "=== Initialization Complete! ==="
|
||||
echo "You can now login with:"
|
||||
echo " Username: admin"
|
||||
echo " Password: admin"
|
||||
echo "Please change the password immediately after login."
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
SERVER_USER="ai30"
|
||||
SERVER_IP="192.168.100.230"
|
||||
REMOTE_DIR="/data/ai-platform/hxops"
|
||||
BACKEND_CONTAINER="hxops-backend"
|
||||
|
||||
echo "=== Starting Full Server Sync & Update ==="
|
||||
echo "Target: $SERVER_USER@$SERVER_IP"
|
||||
|
||||
# 1. Sync Backend Code
|
||||
echo ">>> [1/4] Syncing backend code..."
|
||||
# Exclude venv, __pycache__, local db, etc.
|
||||
rsync -avz --exclude 'venv' --exclude '__pycache__' --exclude '*.pyc' --exclude 'local_test.db' \
|
||||
backend/ $SERVER_USER@$SERVER_IP:$REMOTE_DIR/backend/
|
||||
|
||||
# 2. Sync Frontend Build
|
||||
echo ">>> [2/4] Syncing frontend build..."
|
||||
rsync -avz frontend/dist/ $SERVER_USER@$SERVER_IP:$REMOTE_DIR/frontend/dist/
|
||||
|
||||
# 3. Restart Services
|
||||
echo ">>> [3/4] Restarting services..."
|
||||
ssh $SERVER_USER@$SERVER_IP "cd $REMOTE_DIR && \
|
||||
docker-compose down && \
|
||||
docker-compose up -d --build"
|
||||
|
||||
# 4. Update Database Data
|
||||
echo ">>> [4/4] Updating database data (Password & Seeds)..."
|
||||
# Ensure we run seed_production.py to update admin password to Hxit@54321
|
||||
ssh $SERVER_USER@$SERVER_IP "cd $REMOTE_DIR && \
|
||||
echo 'Running seed script...' && \
|
||||
docker-compose exec -T $BACKEND_CONTAINER python3 seed_production.py"
|
||||
|
||||
echo "=== Sync & Update Complete! ==="
|
||||
echo "You can now login at http://$SERVER_IP:8890"
|
||||
echo "Username: admin"
|
||||
echo "Password: Hxit@54321"
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
# Since "ssh ai30" works directly (via ~/.ssh/config or keys), we use it directly.
|
||||
# SERVER_USER and SERVER_IP are implicit in the "ai30" alias.
|
||||
SERVER_ALIAS="ai30"
|
||||
REMOTE_DIR="/data/ai-platform/hxops"
|
||||
BACKEND_CONTAINER="hxops-backend"
|
||||
|
||||
echo "=== Starting Full Server Sync & Update ==="
|
||||
echo "Target: $SERVER_ALIAS (Using SSH alias)"
|
||||
|
||||
# 1. Sync Backend Code
|
||||
echo ">>> [1/4] Syncing backend code..."
|
||||
# Exclude venv, __pycache__, local db, etc.
|
||||
rsync -avz --exclude 'venv' --exclude '__pycache__' --exclude '*.pyc' --exclude 'local_test.db' \
|
||||
backend/ $SERVER_ALIAS:$REMOTE_DIR/backend/
|
||||
|
||||
# 2. Sync Frontend Build
|
||||
echo ">>> [2/4] Syncing frontend build..."
|
||||
rsync -avz frontend/dist/ $SERVER_ALIAS:$REMOTE_DIR/frontend/dist/
|
||||
|
||||
# 3. Restart Services
|
||||
echo ">>> [3/4] Restarting services..."
|
||||
ssh $SERVER_ALIAS "cd $REMOTE_DIR && \
|
||||
docker compose down && \
|
||||
docker compose up -d --build"
|
||||
|
||||
# 4. Update Database Data
|
||||
echo ">>> [4/4] Updating database data (Password & Seeds)..."
|
||||
# Ensure we run seed_production.py to update admin password to Hxit@54321
|
||||
# We use 'flask db upgrade' but if it fails due to existing tables, we proceed to seeding.
|
||||
# The '|| true' allows the script to continue if migration fails.
|
||||
ssh $SERVER_ALIAS "cd $REMOTE_DIR && \
|
||||
echo 'Checking/Creating database...' && \
|
||||
docker compose exec -T $BACKEND_CONTAINER python3 init_db.py && \
|
||||
echo 'Running migrations (ignoring errors if tables exist)...' && \
|
||||
docker compose exec -T $BACKEND_CONTAINER flask db upgrade || echo 'Migration step had errors, possibly existing tables. Continuing...' && \
|
||||
echo 'Running seed script...' && \
|
||||
docker compose exec -T $BACKEND_CONTAINER python3 seed_production.py"
|
||||
|
||||
echo "=== Sync & Update Complete! ==="
|
||||
echo "You can now login at http://192.168.100.230:8890"
|
||||
echo "Username: admin"
|
||||
echo "Password: Hxit@54321"
|
||||
@@ -0,0 +1,52 @@
|
||||
import requests
|
||||
import sys
|
||||
|
||||
BASE_URL = "http://192.168.100.230:8890"
|
||||
|
||||
def test_frontend():
|
||||
print(f"Testing Frontend at {BASE_URL}...")
|
||||
try:
|
||||
resp = requests.get(BASE_URL, timeout=5)
|
||||
print(f"Status Code: {resp.status_code}")
|
||||
if resp.status_code == 200 and "<html" in resp.text.lower():
|
||||
print("✅ Frontend is serving HTML.")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Frontend check failed. Content snippet: {resp.text[:100]}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Frontend connection failed: {e}")
|
||||
return False
|
||||
|
||||
def test_backend_proxy():
|
||||
# Attempt to hit an API endpoint. Even 401/403 is good because it means Nginx proxied to Flask.
|
||||
# If Nginx fails to proxy, it might return 502 Bad Gateway.
|
||||
url = f"{BASE_URL}/api/agents"
|
||||
print(f"Testing Backend Proxy at {url}...")
|
||||
try:
|
||||
resp = requests.get(url, timeout=5)
|
||||
print(f"Status Code: {resp.status_code}")
|
||||
if resp.status_code in [200, 401, 403, 404]: # 404 might come from Flask if path wrong, but 502 is bad.
|
||||
print("✅ Backend is reachable via Nginx proxy.")
|
||||
return True
|
||||
elif resp.status_code == 502:
|
||||
print("❌ Nginx 502 Bad Gateway - Backend container might be down or unreachable.")
|
||||
return False
|
||||
else:
|
||||
print(f"⚠️ Unexpected status code: {resp.status_code}")
|
||||
return True # Still technically reachable
|
||||
except Exception as e:
|
||||
print(f"❌ Backend connection failed: {e}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = True
|
||||
if not test_frontend(): success = False
|
||||
if not test_backend_proxy(): success = False
|
||||
|
||||
if success:
|
||||
print("\n🎉 Deployment Verification PASSED!")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("\n💥 Deployment Verification FAILED.")
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,76 @@
|
||||
import requests
|
||||
import sys
|
||||
import time
|
||||
|
||||
FRONTEND_URL = "http://localhost:8881"
|
||||
BACKEND_URL = "http://localhost:5002"
|
||||
|
||||
def test_backend_direct():
|
||||
print(f"Testing Backend Direct at {BACKEND_URL}...")
|
||||
try:
|
||||
# Trying a likely endpoint, or just root which might 404 but proves connectivity
|
||||
resp = requests.get(f"{BACKEND_URL}/api/agents", timeout=5)
|
||||
print(f"Backend Direct Status Code: {resp.status_code}")
|
||||
if resp.status_code in [200, 401, 403, 404]:
|
||||
print("✅ Backend is running and reachable directly.")
|
||||
return True
|
||||
else:
|
||||
print(f"⚠️ Unexpected status code from Backend: {resp.status_code}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"❌ Backend connection failed: {e}")
|
||||
return False
|
||||
|
||||
def test_frontend_serve():
|
||||
print(f"Testing Frontend Serve at {FRONTEND_URL}...")
|
||||
try:
|
||||
resp = requests.get(FRONTEND_URL, timeout=5)
|
||||
print(f"Frontend Status Code: {resp.status_code}")
|
||||
if resp.status_code == 200 and "<html" in resp.text.lower():
|
||||
print("✅ Frontend is serving HTML.")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Frontend check failed. Content snippet: {resp.text[:100]}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Frontend connection failed: {e}")
|
||||
return False
|
||||
|
||||
def test_frontend_proxy():
|
||||
# Vite proxy: /api -> http://127.0.0.1:5002
|
||||
url = f"{FRONTEND_URL}/api/agents"
|
||||
print(f"Testing Frontend Proxy at {url}...")
|
||||
try:
|
||||
resp = requests.get(url, timeout=5)
|
||||
print(f"Proxy Status Code: {resp.status_code}")
|
||||
if resp.status_code in [200, 401, 403, 404]:
|
||||
print("✅ Frontend Proxy to Backend is working.")
|
||||
return True
|
||||
elif resp.status_code == 502:
|
||||
print("❌ Frontend Proxy 502 - Backend might be unreachable via Proxy.")
|
||||
return False
|
||||
elif resp.status_code == 504: # Gateway Timeout
|
||||
print("❌ Frontend Proxy 504 - Backend timed out.")
|
||||
return False
|
||||
else:
|
||||
print(f"⚠️ Unexpected status code: {resp.status_code}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"❌ Frontend Proxy connection failed: {e}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Waiting 5 seconds for services to settle...")
|
||||
time.sleep(5)
|
||||
|
||||
success = True
|
||||
if not test_backend_direct(): success = False
|
||||
if not test_frontend_serve(): success = False
|
||||
if not test_frontend_proxy(): success = False
|
||||
|
||||
if success:
|
||||
print("\n🎉 Local Verification PASSED!")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("\n💥 Local Verification FAILED.")
|
||||
sys.exit(1)
|
||||
Reference in new issue
Block a user