-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfluent.ps1
More file actions
279 lines (255 loc) · 10.8 KB
/
fluent.ps1
File metadata and controls
279 lines (255 loc) · 10.8 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#Requires -Version 5.1
param(
[Parameter(Position = 0)]
[string]$Command = "help",
[Parameter(Position = 1, ValueFromRemainingArguments)]
[string[]]$Args
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ScriptDir
# ── Runtime detection (prefer Podman) ──────────────────────────────────────────
function Get-ComposeCommand {
if ((Get-Command podman -ErrorAction SilentlyContinue) -and (Get-Command podman-compose -ErrorAction SilentlyContinue)) {
return "podman-compose"
}
if (Get-Command docker -ErrorAction SilentlyContinue) {
$v2 = & docker compose version 2>&1
if ($LASTEXITCODE -eq 0) { return "docker compose" }
if (Get-Command docker-compose -ErrorAction SilentlyContinue) { return "docker-compose" }
}
Write-Error @"
No container runtime found. Install one of:
- Podman + podman-compose
- Docker Desktop (includes docker compose V2)
- Docker Engine + docker-compose
"@
exit 1
}
$Compose = Get-ComposeCommand
function Invoke-Compose {
param([string[]]$ComposeArgs)
if ($Compose -eq "docker compose") {
& docker compose @ComposeArgs
} else {
& $Compose @ComposeArgs
}
}
# ── Repo path helpers ──────────────────────────────────────────────────────────
$ApiContext = if ($env:API_CONTEXT) { $env:API_CONTEXT } else { "../fluent-api" }
$AiContext = if ($env:AI_CONTEXT) { $env:AI_CONTEXT } else { "../fluent-ai" }
$WebContext = if ($env:WEB_CONTEXT) { $env:WEB_CONTEXT } else { "../fluent-web" }
$Repos = @(
@{ Name = "fluent-api"; Path = $ApiContext; Url = "git@github.com:eten-tech-foundation/fluent-api.git" },
@{ Name = "fluent-ai"; Path = $AiContext; Url = "git@github.com:eten-tech-foundation/fluent-ai.git" },
@{ Name = "fluent-web"; Path = $WebContext; Url = "git@github.com:eten-tech-foundation/fluent-web.git" }
)
function Test-Repos {
$missing = $false
foreach ($repo in $Repos) {
if (Test-Path $repo.Path) {
Write-Host " [ok] $($repo.Name) -> $($repo.Path)"
} else {
Write-Host " [missing] $($repo.Name) -> $($repo.Path)"
$missing = $true
}
}
return -not $missing
}
# ── Commands ───────────────────────────────────────────────────────────────────
switch ($Command) {
"up" {
Invoke-Compose @("up", "-d", "--build") + $Args
}
"down" {
Invoke-Compose @("down") + $Args
}
"restart" {
Invoke-Compose @("restart") + $Args
}
"logs" {
Invoke-Compose @("logs", "-f") + $Args
}
"status" {
Invoke-Compose @("ps") + $Args
}
"shell" {
$service = if ($Args.Count -gt 0) { $Args[0] } else { "api" }
if ($service -eq "db") {
Invoke-Compose @("exec", "db", "psql", "-U", "postgres", "-d", "fluent")
} else {
Invoke-Compose @("exec", $service, "sh")
}
}
"run" {
if ($Args.Count -lt 2) { Write-Error "Usage: fluent.ps1 run <service> <script>"; exit 1 }
$service = $Args[0]
$remaining = $Args[1..($Args.Count - 1)]
Invoke-Compose @("exec", $service, "npm", "run") + $remaining
}
"test" {
if ($Args.Count -lt 1) { Write-Error "Usage: fluent.ps1 test <service>"; exit 1 }
$service = $Args[0]
$remaining = if ($Args.Count -gt 1) { $Args[1..($Args.Count - 1)] } else { @() }
Invoke-Compose @("exec", $service, "npm", "run", "test") + $remaining
}
# ── Database commands ──────────────────────────────────────────────────────
"db:migrate" {
$target = if ($Args.Count -gt 0) { $Args[0] } else { "all" }
switch ($target) {
"api" {
Write-Host "Running fluent-api migrations..."
Invoke-Compose @("exec", "api", "npx", "drizzle-kit", "migrate")
}
"ai" {
Write-Host "Running fluent-ai migrations..."
Invoke-Compose @("exec", "ai", "npm", "run", "db:migrate")
}
"all" {
Write-Host "Running fluent-api migrations..."
Invoke-Compose @("exec", "api", "npx", "drizzle-kit", "migrate")
Write-Host "Running fluent-ai migrations..."
Invoke-Compose @("exec", "ai", "npm", "run", "db:migrate")
}
default {
Write-Error "Unknown migrate target: $target (use api, ai, or all)"
}
}
}
"db:seed" {
$target = if ($Args.Count -gt 0) { $Args[0] } else { "all" }
switch ($target) {
"api" {
Write-Host "Running fluent-api seeds..."
Invoke-Compose @("exec", "api", "npx", "tsx", "src/db/seeds/roles.ts")
Invoke-Compose @("exec", "api", "npx", "tsx", "src/db/seeds/rbac.ts")
Invoke-Compose @("exec", "api", "npx", "tsx", "src/db/seeds/users.ts")
}
"ai" {
Write-Host "Running fluent-ai seeds..."
Invoke-Compose @("exec", "ai", "npm", "run", "db:seed")
}
"all" {
Write-Host "Running fluent-api seeds..."
Invoke-Compose @("exec", "api", "npx", "tsx", "src/db/seeds/roles.ts")
Invoke-Compose @("exec", "api", "npx", "tsx", "src/db/seeds/rbac.ts")
Invoke-Compose @("exec", "api", "npx", "tsx", "src/db/seeds/users.ts")
Write-Host "Running fluent-ai seeds..."
Invoke-Compose @("exec", "ai", "npm", "run", "db:seed")
}
default {
Write-Error "Unknown seed target: $target (use api, ai, or all)"
}
}
}
"db:init" {
Write-Host "Full database initialization (migrations + seeds)..."
& $MyInvocation.MyCommand.Path "db:migrate" "all"
& $MyInvocation.MyCommand.Path "db:seed" "all"
Write-Host "Database initialization complete."
}
"db:studio" {
$port = if ($env:DB_PORT) { $env:DB_PORT } else { "5432" }
Write-Host "Running Drizzle Studio on host (requires local Node.js)..."
Write-Host "Connects to DB via DATABASE_URL in .env (localhost:$port)"
npx drizzle-kit studio
}
"db:psql" {
Invoke-Compose @("exec", "db", "psql", "-U", "postgres", "-d", "fluent")
}
# ── Lifecycle commands ─────────────────────────────────────────────────────
"clean" {
$target = if ($Args.Count -gt 0) { $Args[0] } else { "all" }
Write-Host "This will remove containers AND volumes (full DB reset)."
$confirm = Read-Host "Continue? [y/N]"
if ($confirm -match "^[Yy]$") {
if ($target -eq "all") {
Invoke-Compose @("down", "-v")
Remove-Item -Force -ErrorAction SilentlyContinue "$ApiContext/.db-initialized"
Remove-Item -Force -ErrorAction SilentlyContinue "$AiContext/.db-initialized"
} else {
Invoke-Compose @("rm", "-sf", $target)
switch ($target) {
{ $_ -in "api", "worker" } { Remove-Item -Force -ErrorAction SilentlyContinue "$ApiContext/.db-initialized" }
"ai" { Remove-Item -Force -ErrorAction SilentlyContinue "$AiContext/.db-initialized" }
}
}
} else {
Write-Host "Aborted."
}
}
"build" {
Invoke-Compose @("build", "--no-cache") + $Args
}
"check-repos" {
Write-Host "Checking sibling repositories..."
Test-Repos | Out-Null
}
"setup" {
Write-Host "=== Fluent Platform Setup ==="
Write-Host ""
Write-Host "Checking sibling repositories..."
$allPresent = Test-Repos
if (-not $allPresent) {
Write-Host ""
Write-Host "Missing repositories detected. Clone them with:"
foreach ($repo in $Repos) {
if (-not (Test-Path $repo.Path)) {
Write-Host " git clone $($repo.Url) $($repo.Path)"
}
}
Write-Host ""
$cloneConfirm = Read-Host "Clone missing repos now? [y/N]"
if ($cloneConfirm -match "^[Yy]$") {
foreach ($repo in $Repos) {
if (-not (Test-Path $repo.Path)) {
Write-Host "Cloning $($repo.Name)..."
git clone $repo.Url $repo.Path
}
}
}
}
Write-Host ""
if (-not (Test-Path .env)) {
Copy-Item .env.example .env
Write-Host "Created .env from .env.example"
} else {
Write-Host ".env already exists, skipping."
}
foreach ($repo in $Repos) {
if ((Test-Path $repo.Path) -and (Test-Path "$($repo.Path)/.env.example") -and (-not (Test-Path "$($repo.Path)/.env"))) {
Copy-Item "$($repo.Path)/.env.example" "$($repo.Path)/.env"
Write-Host "Created $($repo.Path)/.env from .env.example"
}
}
Write-Host ""
Write-Host "Setup complete. Next steps:"
Write-Host " 1. Fill in credentials in each .env file (Auth0, etc.)"
Write-Host " 2. Run: .\fluent.ps1 up"
}
default {
@"
Usage: .\fluent.ps1 <command> [args]
Services:
up [service...] Start all or specific services
down [service...] Stop all or specific services
restart [service...] Restart specific or all services
logs [service] Tail logs (default: all services)
status Show container status
shell <service> Open a shell (db opens psql)
run <service> <script> Run an npm script in a service container
test <service> Run tests for a service
Database:
db:migrate [target] Run migrations (api, ai, or all)
db:seed [target] Run seeds (api, ai, or all)
db:init Run all migrations then all seeds
db:studio Launch Drizzle Studio on the host
db:psql Open psql session
Lifecycle:
clean [service] Remove containers and volumes (full reset)
build [service...] Rebuild containers without cache
check-repos Verify sibling repos exist
setup Clone repos, copy .env files, first-time setup
"@
}
}