-
Notifications
You must be signed in to change notification settings - Fork 2
482 lines (432 loc) · 18.5 KB
/
deploy.yml
File metadata and controls
482 lines (432 loc) · 18.5 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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
name: Build & Deploy to Cloud
on:
push:
branches: [main]
paths:
- 'apps/**'
- 'infrastructure/helm/**'
- '.github/workflows/deploy.yml'
workflow_dispatch: # Manual trigger (builds all)
env:
REGISTRY: ghcr.io
IMAGE_PREFIX: ${{ github.repository_owner }}/taskflow
jobs:
# =============================================================================
# Detect which services changed
# =============================================================================
changes:
runs-on: ubuntu-latest
outputs:
api: ${{ steps.filter.outputs.api }}
sso: ${{ steps.filter.outputs.sso }}
mcp: ${{ steps.filter.outputs.mcp }}
notification: ${{ steps.filter.outputs.notification }}
web: ${{ steps.filter.outputs.web }}
helm: ${{ steps.filter.outputs.helm }}
any_service: ${{ steps.filter.outputs.api == 'true' || steps.filter.outputs.sso == 'true' || steps.filter.outputs.mcp == 'true' || steps.filter.outputs.notification == 'true' || steps.filter.outputs.web == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect changes
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
api:
- 'apps/api/**'
sso:
- 'apps/sso/**'
mcp:
- 'apps/mcp-server/**'
notification:
- 'apps/notification-service/**'
web:
- 'apps/web/**'
helm:
- 'infrastructure/helm/**'
# =============================================================================
# Build Docker images (only changed services)
# =============================================================================
build-api:
needs: changes
if: needs.changes.outputs.api == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/api
tags: |
type=raw,value=${{ github.sha }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: apps/api
file: apps/api/Dockerfile
push: true
platforms: linux/arm64
no-cache: true
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-sso:
needs: changes
if: needs.changes.outputs.sso == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/sso
tags: |
type=raw,value=${{ github.sha }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: apps/sso
file: apps/sso/Dockerfile
push: true
platforms: linux/arm64
no-cache: true
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
NEXT_PUBLIC_BETTER_AUTH_URL=https://sso.${{ vars.DOMAIN }}
NEXT_PUBLIC_CONTINUE_URL=https://${{ vars.DOMAIN }}
NEXT_PUBLIC_APP_NAME=Taskflow SSO
build-mcp:
needs: changes
if: needs.changes.outputs.mcp == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/mcp
tags: |
type=raw,value=${{ github.sha }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: apps/mcp-server
file: apps/mcp-server/Dockerfile
push: true
platforms: linux/arm64
no-cache: true
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-notification:
needs: changes
if: needs.changes.outputs.notification == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/notification
tags: |
type=raw,value=${{ github.sha }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: apps/notification-service
file: apps/notification-service/Dockerfile
push: true
platforms: linux/arm64
no-cache: true
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-web:
needs: changes
if: needs.changes.outputs.web == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/web
tags: |
type=raw,value=${{ github.sha }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: apps/web
file: apps/web/Dockerfile
push: true
platforms: linux/arm64
no-cache: true
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
NEXT_PUBLIC_SSO_URL=https://sso.${{ vars.DOMAIN }}
NEXT_PUBLIC_API_URL=https://api.${{ vars.DOMAIN }}
NEXT_PUBLIC_APP_URL=https://${{ vars.DOMAIN }}
NEXT_PUBLIC_OAUTH_REDIRECT_URI=https://${{ vars.DOMAIN }}/api/auth/callback
NEXT_PUBLIC_CHATKIT_DOMAIN_KEY=${{ secrets.CHATKIT_DOMAIN_KEY }}
# =============================================================================
# Deploy to Kubernetes cluster
# =============================================================================
deploy:
needs: [changes, build-api, build-sso, build-mcp, build-notification, build-web]
# Run if any build ran OR if only helm changed
if: |
always() &&
(needs.changes.outputs.any_service == 'true' || needs.changes.outputs.helm == 'true' || github.event_name == 'workflow_dispatch') &&
!contains(needs.*.result, 'failure')
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up kubectl
uses: azure/setup-kubectl@v3
with:
version: 'v1.28.0'
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: 'v3.13.0'
# For Azure AKS
- name: Azure Login
if: ${{ vars.CLOUD_PROVIDER == 'azure' }}
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Get AKS credentials
if: ${{ vars.CLOUD_PROVIDER == 'azure' }}
run: |
az aks get-credentials \
--resource-group ${{ vars.AZURE_RESOURCE_GROUP }} \
--name ${{ vars.AZURE_CLUSTER_NAME }}
# For GKE
- name: Authenticate to GKE
if: ${{ vars.CLOUD_PROVIDER == 'gke' }}
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: Get GKE credentials
if: ${{ vars.CLOUD_PROVIDER == 'gke' }}
uses: google-github-actions/get-gke-credentials@v1
with:
cluster_name: ${{ vars.GKE_CLUSTER_NAME }}
location: ${{ vars.GKE_CLUSTER_ZONE }}
# For any provider with kubeconfig
- name: Set kubeconfig
if: ${{ vars.CLOUD_PROVIDER == 'kubeconfig' }}
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
- name: Add Dapr Helm repo
run: |
helm repo add dapr https://dapr.github.io/helm-charts/
helm repo update
- name: Install/Upgrade Dapr
run: |
helm upgrade --install dapr dapr/dapr \
--version=1.15 \
--namespace dapr-system \
--create-namespace \
--set dapr_scheduler.cluster.storageSize=4Gi \
--wait
- name: Create namespace
run: kubectl create namespace taskflow --dry-run=client -o yaml | kubectl apply -f -
- name: Create GHCR pull secret
run: |
kubectl create secret docker-registry ghcr-secret \
--namespace taskflow \
--docker-server=ghcr.io \
--docker-username=${{ github.actor }} \
--docker-password=${{ secrets.GITHUB_TOKEN }} \
--dry-run=client -o yaml | kubectl apply -f -
- name: Deploy with Helm
run: |
# Determine ingress class based on what's installed
INGRESS_CLASS="${{ vars.INGRESS_CLASS }}"
if [ -z "$INGRESS_CLASS" ]; then
INGRESS_CLASS="traefik" # Default to traefik
fi
# Create temporary values file for comma-containing values (avoids Helm --set parsing issues)
cat > /tmp/helm-overrides.yaml << 'ENDOFVALUES'
sso:
env:
ALLOWED_ORIGINS: "https://${{ vars.DOMAIN }},https://sso.${{ vars.DOMAIN }},https://api.${{ vars.DOMAIN }},https://mcp.${{ vars.DOMAIN }}"
api:
env:
CORS_ORIGINS: "https://${{ vars.DOMAIN }},https://sso.${{ vars.DOMAIN }},https://api.${{ vars.DOMAIN }},https://mcp.${{ vars.DOMAIN }}"
ENDOFVALUES
# Build image override args - only set tags for services that were actually built
IMAGE_ARGS=""
# Always set repositories
IMAGE_ARGS="$IMAGE_ARGS --set sso.image.repository=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/sso"
IMAGE_ARGS="$IMAGE_ARGS --set api.image.repository=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/api"
IMAGE_ARGS="$IMAGE_ARGS --set web.image.repository=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/web"
IMAGE_ARGS="$IMAGE_ARGS --set mcpServer.image.repository=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/mcp"
IMAGE_ARGS="$IMAGE_ARGS --set notificationService.image.repository=${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/notification"
# Only set tags for services that were built (or all on manual trigger)
if [ "${{ needs.changes.outputs.sso }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
IMAGE_ARGS="$IMAGE_ARGS --set sso.image.tag=${{ github.sha }}"
fi
if [ "${{ needs.changes.outputs.api }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
IMAGE_ARGS="$IMAGE_ARGS --set api.image.tag=${{ github.sha }}"
fi
if [ "${{ needs.changes.outputs.web }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
IMAGE_ARGS="$IMAGE_ARGS --set web.image.tag=${{ github.sha }}"
fi
if [ "${{ needs.changes.outputs.mcp }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
IMAGE_ARGS="$IMAGE_ARGS --set mcpServer.image.tag=${{ github.sha }}"
fi
if [ "${{ needs.changes.outputs.notification }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
IMAGE_ARGS="$IMAGE_ARGS --set notificationService.image.tag=${{ github.sha }}"
fi
helm upgrade --install taskflow ./infrastructure/helm/taskflow \
--namespace taskflow \
--values infrastructure/helm/taskflow/values-cloud.yaml \
--values /tmp/helm-overrides.yaml \
--set global.imagePullSecrets[0].name=ghcr-secret \
$IMAGE_ARGS \
--set managedServices.neon.enabled=true \
--set "managedServices.neon.ssoDatabase=${{ secrets.NEON_SSO_DATABASE_URL }}" \
--set "managedServices.neon.apiDatabase=${{ secrets.NEON_API_DATABASE_URL }}" \
--set "managedServices.neon.chatkitDatabase=${{ secrets.NEON_CHATKIT_DATABASE_URL }}" \
--set "managedServices.neon.notificationDatabase=${{ secrets.NEON_NOTIFICATION_DATABASE_URL }}" \
--set managedServices.upstash.enabled=true \
--set "managedServices.upstash.host=${{ secrets.UPSTASH_REDIS_HOST }}" \
--set "managedServices.upstash.password=${{ secrets.UPSTASH_REDIS_PASSWORD }}" \
--set "managedServices.upstash.restUrl=${{ secrets.REDIS_URL }}" \
--set "managedServices.upstash.restToken=${{ secrets.REDIS_TOKEN }}" \
--set "sso.env.BETTER_AUTH_SECRET=${{ secrets.BETTER_AUTH_SECRET }}" \
--set "sso.env.BETTER_AUTH_URL=https://sso.${{ vars.DOMAIN }}" \
--set "sso.smtp.user=${{ secrets.SMTP_USER }}" \
--set "sso.smtp.password=${{ secrets.SMTP_PASSWORD }}" \
--set "api.openai.apiKey=${{ secrets.OPENAI_API_KEY }}" \
--set notificationService.enabled=true \
--set dapr.enabled=true \
--set "dapr.pubsub.redisHost=${{ secrets.UPSTASH_REDIS_HOST }}" \
--set "dapr.pubsub.redisPassword=${{ secrets.UPSTASH_REDIS_PASSWORD }}" \
--set "global.domain=${{ vars.DOMAIN }}" \
--set "sso.ingress.className=$INGRESS_CLASS" \
--set "sso.ingress.host=sso.${{ vars.DOMAIN }}" \
--set "api.ingress.className=$INGRESS_CLASS" \
--set "api.ingress.host=api.${{ vars.DOMAIN }}" \
--set "mcpServer.ingress.enabled=true" \
--set "mcpServer.ingress.className=$INGRESS_CLASS" \
--set "mcpServer.ingress.host=mcp.${{ vars.DOMAIN }}" \
--set "mcpServer.env.TASKFLOW_SSO_PUBLIC_URL=https://sso.${{ vars.DOMAIN }}" \
--set "mcpServer.env.TASKFLOW_MCP_PUBLIC_URL=https://mcp.${{ vars.DOMAIN }}" \
--set "web.ingress.className=$INGRESS_CLASS" \
--set "web.ingress.host=${{ vars.DOMAIN }}" \
--set "ingress-nginx.enabled=false" \
--wait \
--timeout 10m
- name: Verify deployment
run: |
echo "Checking pod status..."
kubectl get pods -n taskflow
echo ""
echo "Checking services..."
kubectl get svc -n taskflow
echo ""
echo "Checking ingress..."
kubectl get ingress -n taskflow 2>/dev/null || echo "No ingress configured"
- name: Post deployment URLs
run: |
echo "## Deployment Complete! :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Services Built" >> $GITHUB_STEP_SUMMARY
echo "| Service | Built |" >> $GITHUB_STEP_SUMMARY
echo "|---------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| API | ${{ needs.changes.outputs.api == 'true' && '✅' || '⏭️ skipped' }} |" >> $GITHUB_STEP_SUMMARY
echo "| SSO | ${{ needs.changes.outputs.sso == 'true' && '✅' || '⏭️ skipped' }} |" >> $GITHUB_STEP_SUMMARY
echo "| MCP | ${{ needs.changes.outputs.mcp == 'true' && '✅' || '⏭️ skipped' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Notification | ${{ needs.changes.outputs.notification == 'true' && '✅' || '⏭️ skipped' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Web | ${{ needs.changes.outputs.web == 'true' && '✅' || '⏭️ skipped' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### URLs" >> $GITHUB_STEP_SUMMARY
echo "| Service | URL |" >> $GITHUB_STEP_SUMMARY
echo "|---------|-----|" >> $GITHUB_STEP_SUMMARY
echo "| Web Dashboard | https://${{ vars.DOMAIN }} |" >> $GITHUB_STEP_SUMMARY
echo "| SSO Platform | https://sso.${{ vars.DOMAIN }} |" >> $GITHUB_STEP_SUMMARY
echo "| API | https://api.${{ vars.DOMAIN }} |" >> $GITHUB_STEP_SUMMARY
echo "| MCP Server | https://mcp.${{ vars.DOMAIN }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Commit: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY