Initial lightweight AI agent admin
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=AI Agent Admin FastAPI backend
|
||||
After=network.target postgresql@17-main.service redis-server.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=ubuntu
|
||||
WorkingDirectory=/opt/apps/ai-agent-admin/backend
|
||||
EnvironmentFile=/opt/apps/ai-agent-admin/backend/.env
|
||||
ExecStart=/opt/apps/ai-agent-admin/backend/.venv/bin/uvicorn app.main:app --host 127.0.0.1 --port 18083
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
APP_DIR=/opt/apps/ai-agent-admin
|
||||
WEB_DIR=/var/www/ai-agent-admin
|
||||
DB_NAME=ai_agent_admin
|
||||
DB_USER=ai_agent_admin
|
||||
DB_PASSWORD=${DB_PASSWORD:-ai_agent_admin}
|
||||
|
||||
cd "$APP_DIR"
|
||||
|
||||
sudo -n -u postgres psql -tc "select 1 from pg_roles where rolname='${DB_USER}'" | grep -q 1 || \
|
||||
sudo -n -u postgres psql -c "create user ${DB_USER} with password '${DB_PASSWORD}'"
|
||||
sudo -n -u postgres psql -tc "select 1 from pg_database where datname='${DB_NAME}'" | grep -q 1 || \
|
||||
sudo -n -u postgres createdb -O "${DB_USER}" "${DB_NAME}"
|
||||
|
||||
cd "$APP_DIR/backend"
|
||||
python3 -m venv .venv
|
||||
.venv/bin/pip install --upgrade pip
|
||||
.venv/bin/pip install -r requirements.txt
|
||||
if [ ! -f .env ]; then
|
||||
cp .env.example .env
|
||||
fi
|
||||
python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
p = Path('.env')
|
||||
text = p.read_text()
|
||||
text = text.replace('change-me@127.0.0.1:5432/ai_agent_admin', 'ai_agent_admin@127.0.0.1:5432/ai_agent_admin')
|
||||
text = text.replace('JWT_SECRET_KEY=change-me-in-production', 'JWT_SECRET_KEY=ai-agent-admin-prod-secret-change-later')
|
||||
p.write_text(text)
|
||||
PY
|
||||
|
||||
sudo -n cp "$APP_DIR/deploy/ai-agent-admin-backend.service" /etc/systemd/system/ai-agent-admin-backend.service
|
||||
sudo -n systemctl daemon-reload
|
||||
sudo -n systemctl enable ai-agent-admin-backend.service
|
||||
sudo -n systemctl restart ai-agent-admin-backend.service
|
||||
|
||||
mkdir -p "$WEB_DIR"
|
||||
rm -rf "$WEB_DIR"/*
|
||||
cp -a "$APP_DIR/frontend/dist/." "$WEB_DIR/"
|
||||
|
||||
NGINX_SITE=/etc/nginx/sites-enabled/default
|
||||
if ! sudo -n grep -q "AI Agent Admin begin" "$NGINX_SITE"; then
|
||||
tmp=$(mktemp)
|
||||
sudo -n awk 'BEGIN{done=0} /location \\// && done==0 {while ((getline line < "/opt/apps/ai-agent-admin/deploy/nginx-ai-agent-admin.conf") > 0) print line; done=1} {print}' "$NGINX_SITE" > "$tmp"
|
||||
sudo -n cp "$tmp" "$NGINX_SITE"
|
||||
rm -f "$tmp"
|
||||
fi
|
||||
sudo -n nginx -t
|
||||
sudo -n systemctl reload nginx
|
||||
@@ -0,0 +1,20 @@
|
||||
# AI Agent Admin begin
|
||||
location = /ai-agent-admin {
|
||||
return 301 /ai-agent-admin/;
|
||||
}
|
||||
|
||||
location ^~ /ai-agent-admin/basic-api/ {
|
||||
proxy_pass http://127.0.0.1:18083/;
|
||||
proxy_http_version 1.1;
|
||||
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;
|
||||
proxy_read_timeout 300s;
|
||||
client_max_body_size 100m;
|
||||
}
|
||||
|
||||
location ^~ /ai-agent-admin/ {
|
||||
try_files $uri $uri/ /ai-agent-admin/index.html;
|
||||
}
|
||||
# AI Agent Admin end
|
||||
Reference in New Issue
Block a user