File size: 5,160 Bytes
e327f0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# scripts/setup/dev.ps1
# One-command dev setup for arac-hasar-v2 on Windows / PowerShell.
#
# Usage:
#   pwsh -File scripts/setup/dev.ps1
# Or (from repo root):
#   .\scripts\setup\dev.ps1
#
# What it does:
#   1. Verify prereqs: pnpm, python 3.11, docker
#   2. pnpm install at repo root (workspace install)
#   3. docker compose up -d postgres redis minio minio-init
#   4. Create Python venv at services/backend/.venv, install requirements
#   5. Run Alembic migrations against the dockerized postgres
#   6. Print the URLs developers need

$ErrorActionPreference = "Stop"
$RepoRoot = (Resolve-Path "$PSScriptRoot\..\..").Path

function Section($msg) {
    Write-Host ""
    Write-Host "=== $msg ===" -ForegroundColor Cyan
}

function Check-Cmd($name, $hint) {
    $cmd = Get-Command $name -ErrorAction SilentlyContinue
    if (-not $cmd) {
        Write-Host "MISSING: $name" -ForegroundColor Red
        Write-Host "        $hint" -ForegroundColor Yellow
        exit 1
    }
    Write-Host "  ok: $name ($($cmd.Source))" -ForegroundColor Green
}

# ---------- 1. Prereqs ----------
Section "Checking prerequisites"
Check-Cmd "pnpm"   "Install: npm i -g pnpm@9"
Check-Cmd "python" "Install Python 3.11 from python.org (must be on PATH)"
Check-Cmd "docker" "Install Docker Desktop and ensure the engine is running"

$pyVersion = (& python --version) 2>&1
if ($pyVersion -notmatch "3\.11") {
    Write-Host "WARN: $pyVersion (3.11.x recommended)" -ForegroundColor Yellow
} else {
    Write-Host "  ok: $pyVersion" -ForegroundColor Green
}

# Ensure docker daemon responds
try {
    docker info --format "{{.ServerVersion}}" | Out-Null
} catch {
    Write-Host "Docker daemon is not reachable. Start Docker Desktop." -ForegroundColor Red
    exit 1
}

# ---------- 2. pnpm install ----------
Section "pnpm install (workspace)"
Push-Location $RepoRoot
try {
    pnpm install --frozen-lockfile
    if ($LASTEXITCODE -ne 0) { throw "pnpm install failed" }
} finally {
    Pop-Location
}

# ---------- 3. Docker dev stack ----------
Section "Starting docker compose: postgres + redis + minio"
Push-Location $RepoRoot
try {
    docker compose up -d postgres redis minio minio-init
    if ($LASTEXITCODE -ne 0) { throw "docker compose up failed" }
} finally {
    Pop-Location
}

# ---------- 4. Backend venv + deps ----------
Section "Setting up backend venv at services/backend/.venv"
$BackendDir = Join-Path $RepoRoot "services\backend"
Push-Location $BackendDir
try {
    if (-not (Test-Path ".venv")) {
        python -m venv .venv
        if ($LASTEXITCODE -ne 0) { throw "venv creation failed" }
    }
    & .\.venv\Scripts\python.exe -m pip install --upgrade pip wheel
    & .\.venv\Scripts\python.exe -m pip install `
        --extra-index-url https://download.pytorch.org/whl/cpu `
        "torch==2.3.1+cpu" "torchvision==0.18.1+cpu"
    & .\.venv\Scripts\python.exe -m pip install -r requirements.txt
    if ($LASTEXITCODE -ne 0) { throw "pip install failed" }

    if (-not (Test-Path ".env")) {
        if (Test-Path ".env.example") {
            Copy-Item ".env.example" ".env"
            Write-Host "  Copied .env.example -> .env (review before running)" -ForegroundColor Yellow
        }
    }
} finally {
    Pop-Location
}

# ---------- 5. Alembic migrations ----------
Section "Running Alembic migrations"
Push-Location $BackendDir
try {
    $env:DATABASE_URL = "postgresql://postgres:postgres@localhost:5432/arac_hasar"
    # Wait briefly for postgres to be ready
    $tries = 0
    while ($tries -lt 30) {
        $ok = docker exec hasarui-postgres pg_isready -U postgres -d arac_hasar 2>&1
        if ($LASTEXITCODE -eq 0) { break }
        Start-Sleep -Seconds 1
        $tries++
    }
    & .\.venv\Scripts\alembic.exe upgrade head
    if ($LASTEXITCODE -ne 0) {
        Write-Host "WARN: alembic upgrade failed (continuing — fix and rerun)." -ForegroundColor Yellow
    }
} finally {
    Pop-Location
}

# ---------- 6. Summary ----------
Section "Dev environment ready"
Write-Host ""
Write-Host "Endpoints:" -ForegroundColor Cyan
Write-Host "  Web (Next.js)    -> http://localhost:3000     (pnpm --filter web dev)"
Write-Host "  API (FastAPI)    -> http://localhost:8000/docs"
Write-Host "  MinIO console    -> http://localhost:9001     (minioadmin / minioadmin)"
Write-Host "  MinIO S3 API     -> http://localhost:9000"
Write-Host "  Postgres         -> postgresql://postgres:postgres@localhost:5432/arac_hasar"
Write-Host "  Redis            -> redis://localhost:6379/0"
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host "  1. Start backend (host):"
Write-Host "       cd services\backend"
Write-Host "       .\.venv\Scripts\Activate.ps1"
Write-Host "       uvicorn main:app --reload"
Write-Host "     or run dockerized:"
Write-Host "       docker compose up backend worker"
Write-Host ""
Write-Host "  2. Start web:"
Write-Host "       pnpm --filter @arac-hasar/web dev"
Write-Host ""
Write-Host "  3. Start desktop:"
Write-Host "       pnpm --filter @arac-hasar/desktop tauri dev"
Write-Host ""
Write-Host "  4. Start mobile (Expo):"
Write-Host "       pnpm --filter @arac-hasar/mobile start"
Write-Host ""