forked from Fadil369/HealthLinc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-workers.ps1
More file actions
345 lines (290 loc) · 11.2 KB
/
Copy pathdeploy-workers.ps1
File metadata and controls
345 lines (290 loc) · 11.2 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# HealthLinc Cloudflare Workers Deployment Script
# This script sets up and deploys all HealthLinc agents to Cloudflare Workers
param(
[Parameter(Mandatory=$false)]
[string]$Environment = "production",
[Parameter(Mandatory=$false)]
[switch]$SetupKV,
[Parameter(Mandatory=$false)]
[switch]$Deploy,
[Parameter(Mandatory=$false)]
[switch]$CreateWorkers,
[Parameter(Mandatory=$false)]
[switch]$All
)
Write-Host "🚀 HealthLinc Cloudflare Workers Deployment" -ForegroundColor Cyan
Write-Host "Environment: $Environment" -ForegroundColor Yellow
# Configuration
$WorkersConfig = @{
"healthlinc-mcp" = @{
Path = "backend\mcp-server"
Description = "HealthLinc MCP Server - Main routing and orchestration"
Type = "mcp-server"
}
"authlinc" = @{
Path = "backend\linc-agents\authlinc"
Description = "AuthLinc Agent - Authentication and Authorization"
Type = "python-agent"
}
"claimlinc" = @{
Path = "backend\linc-agents\claimlinc"
Description = "ClaimLinc Agent - Claims Processing"
Type = "python-agent"
}
"matchlinc" = @{
Path = "backend\linc-agents\matchlinc"
Description = "MatchLinc Agent - Code Matching and Validation"
Type = "python-agent"
}
"doculinc" = @{
Path = "backend\linc-agents\doculinc"
Description = "DocuLinc Agent - Documentation Enhancement"
Type = "python-agent"
}
"notifylinc" = @{
Path = "backend\linc-agents\notifylinc"
Description = "NotifyLinc Agent - Notifications and Communications"
Type = "python-agent"
}
"recordlinc" = @{
Path = "backend\linc-agents\recordlinc"
Description = "RecordLinc Agent - Patient Records Management"
Type = "python-agent"
}
"reviewerlinc" = @{
Path = "backend\linc-agents\reviewerlinc"
Description = "ReviewerLinc Agent - Claims Review and Analysis"
Type = "python-agent"
}
"claimtrackerlinc" = @{
Path = "backend\linc-agents\claimtrackerlinc"
Description = "ClaimTrackerLinc Agent - Claims Tracking"
Type = "python-agent"
}
"nphieslinc" = @{
Path = "backend\linc-agents\nphieslinc"
Description = "NphiesLinc Agent - NPHIES Integration"
Type = "python-agent"
}
"nphies-integration" = @{
Path = "backend\nphies-integration"
Description = "NPHIES Integration Service"
Type = "python-service"
}
"fhir-gateway" = @{
Path = "backend\fhir-gateway"
Description = "FHIR Gateway - Interoperability Layer"
Type = "python-service"
}
}
function Setup-KVNamespaces {
Write-Host "📦 Setting up KV Namespaces..." -ForegroundColor Green
# Create KV namespaces for MCP server
try {
$tokensProd = wrangler kv:namespace create "HEALTHLINC_TOKENS" 2>&1
$tokensPreview = wrangler kv:namespace create "HEALTHLINC_TOKENS" --preview 2>&1
$logsProd = wrangler kv:namespace create "HEALTHLINC_LOGS" 2>&1
$logsPreview = wrangler kv:namespace create "HEALTHLINC_LOGS" --preview 2>&1
Write-Host "✅ KV Namespaces created successfully" -ForegroundColor Green
Write-Host "Update your wrangler.toml with the following IDs:" -ForegroundColor Yellow
Write-Host $tokensProd -ForegroundColor Gray
Write-Host $tokensPreview -ForegroundColor Gray
Write-Host $logsProd -ForegroundColor Gray
Write-Host $logsPreview -ForegroundColor Gray
}
catch {
Write-Host "❌ Error creating KV namespaces: $_" -ForegroundColor Red
return $false
}
return $true
}
function Create-PythonWorker {
param(
[string]$Name,
[string]$Path,
[string]$Description
)
Write-Host "🐍 Creating Python Worker: $Name" -ForegroundColor Cyan
# Create JavaScript wrapper for Python worker
$workerScript = @'
// Cloudflare Worker wrapper for Python LINC Agent
// This is a simplified approach - in production use Pyodide or similar
import { Router } from 'itty-router';
const router = Router();
// Basic health check for Python workers
router.get('/health', () => {
return new Response(JSON.stringify({
status: 'healthy',
service: 'WORKER_NAME',
timestamp: new Date().toISOString(),
type: 'python-wrapper'
}), { headers: { 'Content-Type': 'application/json' } });
});
// Placeholder endpoint - implement actual logic
router.post('/agents/*', async (request) => {
return new Response(JSON.stringify({
status: 'success',
message: 'Python worker placeholder - implement actual logic',
service: 'WORKER_NAME',
timestamp: Date.now()
}), { headers: { 'Content-Type': 'application/json' } });
});
router.all('*', () => new Response('Not Found', { status: 404 }));
export default {
async fetch(request, env, ctx) {
return router.handle(request, env);
}
};
'@
# Replace placeholder with actual worker name
$workerScript = $workerScript -replace "WORKER_NAME", $Name
# Create worker directory
$workerDir = "deploy\workers\$Name"
if (!(Test-Path $workerDir)) {
New-Item -ItemType Directory -Force -Path $workerDir | Out-Null
}
# Create worker files
Set-Content -Path "$workerDir\index.js" -Value $workerScript
# Copy Python files as reference
if (Test-Path $Path) {
Copy-Item -Path "$Path\*" -Destination $workerDir -Recurse -Force
}
Write-Host "✅ Worker $Name created at $workerDir" -ForegroundColor Green
}
function Deploy-Worker {
param(
[string]$Name,
[string]$Path,
[string]$Type
)
Write-Host "🚀 Deploying Worker: $Name" -ForegroundColor Cyan
try {
Push-Location $Path
if ($Type -eq "mcp-server") {
# TypeScript/Node.js worker
Write-Host "📦 Installing dependencies..." -ForegroundColor Yellow
npm install
Write-Host "🔨 Building TypeScript..." -ForegroundColor Yellow
npm run build 2>$null
Write-Host "🚀 Deploying to Cloudflare Workers..." -ForegroundColor Yellow
wrangler deploy --env $Environment
}
elseif ($Type -eq "python-agent" -or $Type -eq "python-service") {
# For Python workers, we need to use a different approach
# Create a Node.js wrapper that can run Python code
Create-PythonWorker -Name $Name -Path $Path -Description $WorkersConfig[$Name].Description
Push-Location "..\..\deploy\workers\$Name"
wrangler deploy --env $Environment
Pop-Location
}
Write-Host "✅ Worker $Name deployed successfully" -ForegroundColor Green
}
catch {
Write-Host "❌ Error deploying worker $Name : $_" -ForegroundColor Red
return $false
}
finally {
Pop-Location
}
return $true
}
function Create-DeployDirectory {
Write-Host "📁 Creating deployment directory structure..." -ForegroundColor Green
$deployDir = "deploy\workers"
if (!(Test-Path $deployDir)) {
New-Item -ItemType Directory -Force -Path $deployDir | Out-Null
}
# Create package.json for TypeScript builds
$packageJson = @"
{
"name": "healthlinc-workers",
"version": "1.0.0",
"description": "HealthLinc Cloudflare Workers Deployment",
"scripts": {
"build": "tsc",
"deploy:all": "powershell -File deploy-workers.ps1 -All",
"deploy:mcp": "wrangler deploy --config backend/mcp-server/wrangler.toml",
"setup:kv": "powershell -File deploy-workers.ps1 -SetupKV"
},
"dependencies": {
"@cloudflare/workers-types": "^4.20231121.0",
"@cloudflare/pyodide-worker": "^1.0.0",
"itty-router": "^4.0.0",
"uuid": "^9.0.0"
},
"devDependencies": {
"typescript": "^5.0.0",
"wrangler": "^3.15.0"
}
}
"@
Set-Content -Path "deploy\package.json" -Value $packageJson
Write-Host "✅ Deployment structure created" -ForegroundColor Green
}
function Show-DeploymentStatus {
Write-Host "`n🎯 HealthLinc Cloudflare Workers Deployment Summary" -ForegroundColor Cyan
Write-Host "=" * 60 -ForegroundColor Gray
Write-Host "`nWorkers to be deployed:" -ForegroundColor Yellow
foreach ($worker in $WorkersConfig.Keys) {
$config = $WorkersConfig[$worker]
Write-Host " • $worker" -ForegroundColor White -NoNewline
Write-Host " ($($config.Type))" -ForegroundColor Gray
Write-Host " └── $($config.Description)" -ForegroundColor Gray
Write-Host " └── URL: https://$worker.healthlinc.workers.dev" -ForegroundColor Green
}
Write-Host "`nNext Steps:" -ForegroundColor Yellow
Write-Host "1. Run with -SetupKV to create KV namespaces" -ForegroundColor White
Write-Host "2. Update wrangler.toml files with KV namespace IDs" -ForegroundColor White
Write-Host "3. Run with -Deploy to deploy all workers" -ForegroundColor White
Write-Host "4. Test endpoints and configure custom domains" -ForegroundColor White
Write-Host "`nUsage Examples:" -ForegroundColor Yellow
Write-Host " .\deploy-workers.ps1 -SetupKV" -ForegroundColor Gray
Write-Host " .\deploy-workers.ps1 -Deploy" -ForegroundColor Gray
Write-Host " .\deploy-workers.ps1 -All" -ForegroundColor Gray
}
# Main execution logic
if ($All) {
$SetupKV = $true
$CreateWorkers = $true
$Deploy = $true
}
# Create deployment directory
Create-DeployDirectory
# Setup KV namespaces
if ($SetupKV) {
$kvSuccess = Setup-KVNamespaces
if (!$kvSuccess) {
Write-Host "❌ KV setup failed. Exiting..." -ForegroundColor Red
exit 1
}
}
# Create worker configurations
if ($CreateWorkers) {
Write-Host "`n🏗️ Creating worker configurations..." -ForegroundColor Green
foreach ($workerName in $WorkersConfig.Keys) {
$config = $WorkersConfig[$workerName]
if ($config.Type -eq "python-agent" -or $config.Type -eq "python-service") {
Create-PythonWorker -Name $workerName -Path $config.Path -Description $config.Description
}
}
}
# Deploy workers
if ($Deploy) {
Write-Host "`n🚀 Deploying workers to Cloudflare..." -ForegroundColor Green
# First deploy the MCP server
Write-Host "`n📡 Deploying MCP Server first..." -ForegroundColor Cyan
Deploy-Worker -Name "healthlinc-mcp" -Path $WorkersConfig["healthlinc-mcp"].Path -Type $WorkersConfig["healthlinc-mcp"].Type
# Deploy other workers
foreach ($workerName in $WorkersConfig.Keys) {
if ($workerName -ne "healthlinc-mcp") {
$config = $WorkersConfig[$workerName]
Deploy-Worker -Name $workerName -Path $config.Path -Type $config.Type
}
}
Write-Host "`n🎉 All workers deployed successfully!" -ForegroundColor Green
Write-Host "`nMCP Server URL: https://healthlinc-mcp.healthlinc.workers.dev" -ForegroundColor Cyan
Write-Host "API Documentation: https://healthlinc-mcp.healthlinc.workers.dev/docs" -ForegroundColor Cyan
}
# Show deployment status
Show-DeploymentStatus
Write-Host "`n🎯 HealthLinc Cloudflare Workers deployment script completed!" -ForegroundColor Green