📝 docs(deploy): adicionar guia de deploy no servidor e service systemd
parent
0f548a3e1a
commit
8e35d33fd3
@ -0,0 +1,121 @@
|
|||||||
|
# Deploy no Servidor da Empresa (Debian/Ubuntu + systemd)
|
||||||
|
|
||||||
|
## 1) Fluxo correto com Git
|
||||||
|
|
||||||
|
Sim: primeiro voce faz commit e push da sua maquina local, depois no servidor faz pull.
|
||||||
|
|
||||||
|
Exemplo:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# local
|
||||||
|
git add .
|
||||||
|
git commit -m "ajusta mysql/tools + telegram webhook"
|
||||||
|
git push origin main
|
||||||
|
|
||||||
|
# servidor
|
||||||
|
cd /opt/orquestrador
|
||||||
|
git pull origin main
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2) Preparacao no servidor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /opt/orquestrador
|
||||||
|
python3 -m venv venv
|
||||||
|
source venv/bin/activate
|
||||||
|
pip install -U pip
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3) Configurar .env.prod
|
||||||
|
|
||||||
|
Crie/atualize o arquivo `.env.prod` no servidor:
|
||||||
|
|
||||||
|
```env
|
||||||
|
GOOGLE_PROJECT_ID=seu-projeto
|
||||||
|
GOOGLE_LOCATION=us-central1
|
||||||
|
VERTEX_MODEL_NAME=gemini-2.5-flash
|
||||||
|
|
||||||
|
DB_HOST=127.0.0.1
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_USER=root
|
||||||
|
DB_PASSWORD=sua_senha
|
||||||
|
DB_NAME=orquestrador_mock
|
||||||
|
|
||||||
|
MOCK_DB_HOST=127.0.0.1
|
||||||
|
MOCK_DB_PORT=3306
|
||||||
|
MOCK_DB_USER=root
|
||||||
|
MOCK_DB_PASSWORD=sua_senha
|
||||||
|
MOCK_DB_NAME=orquestrador_mock
|
||||||
|
|
||||||
|
AUTO_SEED_TOOLS=true
|
||||||
|
AUTO_SEED_MOCK=true
|
||||||
|
MOCK_SEED_ENABLED=true
|
||||||
|
|
||||||
|
# telegram (opcional)
|
||||||
|
# TELEGRAM_BOT_TOKEN=...
|
||||||
|
# TELEGRAM_WEBHOOK_SECRET=...
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4) Credencial para Vertex AI
|
||||||
|
|
||||||
|
Defina um dos formatos abaixo no servidor:
|
||||||
|
|
||||||
|
- `GOOGLE_APPLICATION_CREDENTIALS=/opt/orquestrador/sa.json`
|
||||||
|
- ou Application Default Credentials (`gcloud auth application-default login`)
|
||||||
|
|
||||||
|
A service account deve ter permissao no Vertex AI (ex.: `roles/aiplatform.user`).
|
||||||
|
|
||||||
|
## 5) Configurar service do systemd
|
||||||
|
|
||||||
|
1. Copie o template e ajuste usuario/path:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo cp deploy/systemd/orquestrador.service.example /etc/systemd/system/orquestrador.service
|
||||||
|
sudo nano /etc/systemd/system/orquestrador.service
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Recarregue e inicie:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable --now orquestrador
|
||||||
|
sudo systemctl status orquestrador
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Logs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
journalctl -u orquestrador -f
|
||||||
|
```
|
||||||
|
|
||||||
|
## 6) Testes rapidos
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s http://127.0.0.1:8080/openapi.json | head
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST http://127.0.0.1:8080/chat \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"message":"Quero um sedan ate 50000"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST http://127.0.0.1:8080/mock/consultar-estoque \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"preco_max":50000,"categoria":"sedan"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
## 7) Atualizacao em producao
|
||||||
|
|
||||||
|
Sempre que subir novas mudancas:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /opt/orquestrador
|
||||||
|
git pull origin main
|
||||||
|
source venv/bin/activate
|
||||||
|
pip install -r requirements.txt
|
||||||
|
sudo systemctl restart orquestrador
|
||||||
|
sudo systemctl status orquestrador
|
||||||
|
```
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=AI Orquestrador API (FastAPI/Uvicorn)
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=vitor
|
||||||
|
Group=vitor
|
||||||
|
WorkingDirectory=/opt/orquestrador
|
||||||
|
EnvironmentFile=/opt/orquestrador/.env.prod
|
||||||
|
Environment=PATH=/opt/orquestrador/venv/bin
|
||||||
|
ExecStart=/opt/orquestrador/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8080
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
# hardening basico
|
||||||
|
NoNewPrivileges=true
|
||||||
|
PrivateTmp=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
Loading…
Reference in New Issue