From b8d29283ec6f2edc310db0a993e0d2e4d01a25a4 Mon Sep 17 00:00:00 2001 From: Rafael Matesco Date: Tue, 20 Oct 2026 10:41:28 -0300 Subject: [PATCH] feat: add local development scripts and configure docker to use host ai service --- docker-compose.yml | 6 +++--- start-dev.ps1 | 50 ++++++++++++++++++++++++++++++++++++++++++++++ stop-dev.ps1 | 13 ++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 start-dev.ps1 create mode 100644 stop-dev.ps1 diff --git a/docker-compose.yml b/docker-compose.yml index 216f24a..e132a45 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -76,10 +76,10 @@ services: - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-sinapse_dev_password} - POSTGRES_DB=${POSTGRES_DB:-sinapse} - # AI Service dentro da rede Docker - - AI_SERVICE_URL=http://ai-service:8000 + # AI Service (usa host.docker.internal para acessar IA rodando nativa no Windows) + - AI_SERVICE_URL=${AI_SERVICE_URL:-http://host.docker.internal:8000} - DOCUMENT_INGESTION_TOKEN=${DOCUMENT_INGESTION_TOKEN:-sinapse-dev-document-ingestion-token-2026} - - REPO_ANALYZER_URL=${REPO_ANALYZER_URL:-http://ai-service:8000} + - REPO_ANALYZER_URL=${REPO_ANALYZER_URL:-http://host.docker.internal:8000} - AI_SERVICE_TOKEN=${AI_SERVICE_TOKEN:?Configure AI_SERVICE_TOKEN in .env} - DOCUMENT_MAX_SIZE_MB=${DOCUMENT_MAX_SIZE_MB:-20} diff --git a/start-dev.ps1 b/start-dev.ps1 new file mode 100644 index 0000000..cab1c93 --- /dev/null +++ b/start-dev.ps1 @@ -0,0 +1,50 @@ +# Script para iniciar ambiente de desenvolvimento Sinapse +# 1. Inicia o Ollama (se não estiver rodando) +# 2. Sobe os containers essenciais (Postgres, Backend, Frontend) +# 3. Inicia o AI-Service (FastAPI) nativo no Windows usando aceleração local de hardware + +$ErrorActionPreference = "Stop" +$rootDir = $PSScriptRoot + +Write-Host "======================================================" -ForegroundColor Cyan +Write-Host " SINAPSE - INICIALIZANDO AMBIENTE DEV " -ForegroundColor Cyan +Write-Host "======================================================" -ForegroundColor Cyan + +# 1. Ollama +Write-Host "`n[1/3] Verificando Ollama..." -ForegroundColor Yellow +$ollamaProc = Get-Process -Name "ollama app", "ollama" -ErrorAction SilentlyContinue +if (-not $ollamaProc) { + Write-Host "Iniciando Ollama em segundo plano..." -ForegroundColor Gray + Start-Process "ollama" "serve" -WindowStyle Minimized + Start-Sleep -Seconds 2 +} else { + Write-Host "Ollama ja esta em execucao." -ForegroundColor Green +} + +# 2. Containers Docker +Write-Host "`n[2/3] Subindo containers Docker (Postgres, Backend, Frontend)..." -ForegroundColor Yellow +Set-Location $rootDir +docker compose up -d postgres backend frontend + +# 3. AI Service (Python nativo) +Write-Host "`n[3/3] Configurando e iniciando AI-Service local..." -ForegroundColor Yellow +$aiPath = Join-Path $rootDir "ai-service" + +if (-not (Test-Path "$aiPath\.venv")) { + Write-Host "Ambiente virtual (.venv) nao encontrado em $aiPath. Criando..." -ForegroundColor Cyan + python -m venv "$aiPath\.venv" + Write-Host "Instalando dependencias do ai-service..." -ForegroundColor Cyan + & "$aiPath\.venv\Scripts\pip" install -r "$aiPath\requirements.txt" +} + +Write-Host "Iniciando FastAPI em nova janela..." -ForegroundColor Green +$cmdArgs = "-NoExit -Command `"cd '$aiPath'; .\.venv\Scripts\activate; uvicorn main:app --host 0.0.0.0 --port 8000 --reload`"" +Start-Process powershell -ArgumentList $cmdArgs + +Write-Host "`n======================================================" -ForegroundColor Green +Write-Host " Tudo pronto!" -ForegroundColor Green +Write-Host " - Frontend: http://localhost:5173" -ForegroundColor White +Write-Host " - Backend: http://localhost:3001" -ForegroundColor White +Write-Host " - AI Service: http://localhost:8000" -ForegroundColor White +Write-Host " - Ollama: http://localhost:11434" -ForegroundColor White +Write-Host "======================================================`n" -ForegroundColor Green diff --git a/stop-dev.ps1 b/stop-dev.ps1 new file mode 100644 index 0000000..1ecd3d0 --- /dev/null +++ b/stop-dev.ps1 @@ -0,0 +1,13 @@ +# Script para desligar ambiente de desenvolvimento Sinapse + +$ErrorActionPreference = "SilentlyContinue" +$rootDir = $PSScriptRoot + +Write-Host "Encerrando containers Docker..." -ForegroundColor Yellow +Set-Location $rootDir +docker compose down + +Write-Host "Encerrando processo do AI Service (uvicorn)..." -ForegroundColor Yellow +Get-Process -Name "uvicorn" -ErrorAction SilentlyContinue | Stop-Process -Force + +Write-Host "Ambiente de desenvolvimento finalizado com sucesso." -ForegroundColor Green