-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·1208 lines (1120 loc) · 46.4 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·1208 lines (1120 loc) · 46.4 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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -euo pipefail
###############################################################################
# kodiai -- Azure Container Apps Deployment Script
#
# This script provisions all Azure resources and deploys the kodiai container.
# It is idempotent: safe to re-run (existing resources are updated in place).
#
# Prerequisites:
# - Azure CLI installed and logged in (az login)
# - Docker is NOT required (ACR builds the image remotely)
#
# Required environment variables:
# GITHUB_APP_ID - GitHub App ID from the app settings page
# GITHUB_PRIVATE_KEY_BASE64 - Base64-encoded PEM private key
# Generate with: base64 -w0 < private-key.pem
# GITHUB_WEBHOOK_SECRET - Webhook secret configured in the GitHub App
# CLAUDE_CODE_OAUTH_TOKEN - 1-year OAuth token from `claude setup-token`
# Do not use ~/.claude/.credentials.json
# claudeAiOauth.accessToken here — it is a
# rotating Claude login token, not the deploy
# token this runtime expects.
# VOYAGE_API_KEY - VoyageAI API key for embeddings
# SLACK_BOT_TOKEN - Slack bot OAuth token
# SLACK_SIGNING_SECRET - Slack app signing secret
# SLACK_BOT_USER_ID - Slack bot user ID
# SLACK_KODIAI_CHANNEL_ID - Slack channel ID for #kodiai
#
# The app's loadPrivateKey() handles base64 decoding automatically, so we
# pass the base64-encoded value straight through as GITHUB_PRIVATE_KEY.
###############################################################################
# -- Load .env (optional) ------------------------------------------------------
# If you prefer not to export variables in your shell, create a local `.env`
# file and run `./deploy.sh`. This script will source it automatically.
ENV_FILE=${ENV_FILE:-.env}
if [[ -f "$ENV_FILE" ]]; then
# Export all variables defined in the file.
set -a
# shellcheck disable=SC1090
source "$ENV_FILE"
set +a
fi
validate_claude_oauth_token_source() {
CLAUDE_CREDENTIALS_FILE=${CLAUDE_CREDENTIALS_FILE:-$HOME/.claude/.credentials.json}
if [[ -z "${CLAUDE_CODE_OAUTH_TOKEN:-}" || ! -f "$CLAUDE_CREDENTIALS_FILE" ]]; then
return 0
fi
local machine_token=""
if command -v jq >/dev/null 2>&1; then
machine_token=$(jq -r '.claudeAiOauth.accessToken // empty' "$CLAUDE_CREDENTIALS_FILE" 2>/dev/null || true)
elif command -v node >/dev/null 2>&1; then
machine_token=$(node -e 'const fs = require("node:fs"); try { const raw = JSON.parse(fs.readFileSync(process.argv[1], "utf8")); process.stdout.write(raw?.claudeAiOauth?.accessToken ?? ""); } catch { process.stdout.write(""); }' "$CLAUDE_CREDENTIALS_FILE" 2>/dev/null || true)
fi
if [[ -n "$machine_token" && "${CLAUDE_CODE_OAUTH_TOKEN:-}" == "$machine_token" ]]; then
echo "ERROR: CLAUDE_CODE_OAUTH_TOKEN matches $CLAUDE_CREDENTIALS_FILE accessToken."
echo "Use the 1-year token from `claude setup-token`, not the rotating Claude login access token."
exit 1
fi
}
validate_claude_oauth_token_source
yaml_quote() {
python3 -c 'import json, sys; print(json.dumps(sys.argv[1]))' "$1" || {
echo "ERROR: yaml_quote failed for value" >&2
exit 1
}
}
# -- Configuration (customize as needed) --------------------------------------
RESOURCE_GROUP="rg-kodiai"
LOCATION="eastus"
ENVIRONMENT="cae-kodiai"
APP_NAME="ca-kodiai"
LOG_ANALYTICS_WORKSPACE_NAME=${LOG_ANALYTICS_WORKSPACE_NAME:-law-kodiai}
LOG_ANALYTICS_WORKSPACE_RESOURCE_ID=${LOG_ANALYTICS_WORKSPACE_RESOURCE_ID:-}
ACA_DIAGNOSTIC_SETTING_NAME=${ACA_DIAGNOSTIC_SETTING_NAME:-kodiai-containerapp-logs}
ACR_NAME="kodiairegistry" # Must be globally unique, alphanumeric only
BUN_BASE_SOURCE_IMAGE=${BUN_BASE_SOURCE_IMAGE:-docker.io/oven/bun:1.3.8-debian}
BUN_BASE_ACR_IMAGE=${BUN_BASE_ACR_IMAGE:-base/oven-bun:1.3.8-debian}
BUN_BASE_IMAGE="${ACR_NAME}.azurecr.io/${BUN_BASE_ACR_IMAGE}"
IDENTITY_NAME="id-kodiai"
KEY_VAULT_NAME=${KEY_VAULT_NAME:-}
SOURCE_COMMIT=${DEPLOY_SOURCE_COMMIT:-$(git rev-parse --verify HEAD)}
if ! git rev-parse --verify "${SOURCE_COMMIT}^{commit}" >/dev/null 2>&1; then
echo "ERROR: DEPLOY_SOURCE_COMMIT '$SOURCE_COMMIT' is not a valid git commit." >&2
exit 1
fi
SOURCE_COMMIT=$(git rev-parse --verify "${SOURCE_COMMIT}^{commit}")
SOURCE_COMMIT_SHORT=$(git rev-parse --short=12 "$SOURCE_COMMIT")
ACA_MIN_REPLICAS=${ACA_MIN_REPLICAS:-1}
ACA_MAX_REPLICAS=${ACA_MAX_REPLICAS:-1}
if ! [[ "$ACA_MIN_REPLICAS" =~ ^[0-9]+$ && "$ACA_MAX_REPLICAS" =~ ^[0-9]+$ ]]; then
echo "ERROR: ACA_MIN_REPLICAS and ACA_MAX_REPLICAS must be non-negative integers." >&2
exit 1
fi
if (( ACA_MIN_REPLICAS < 1 || ACA_MAX_REPLICAS < ACA_MIN_REPLICAS )); then
echo "ERROR: ACA_MIN_REPLICAS must be >= 1 and ACA_MAX_REPLICAS must be >= ACA_MIN_REPLICAS." >&2
exit 1
fi
if (( ACA_MAX_REPLICAS > 1 )); then
echo "ERROR: ACA_MAX_REPLICAS > 1 is not supported while the MCP callback token registry is process-local." >&2
echo "The current MCP callback token registry is process-local; multi-replica ingress would route callbacks to replicas that cannot validate or serve the job token." >&2
exit 1
fi
# Orchestrator container resources. The orchestrator runs a single-threaded Bun
# event loop that also serves the internal MCP callback server hit by agent jobs.
# Under-provisioning starves the loop during review-time CPU bursts, which makes
# in-flight MCP calls sit idle until the ACA ingress 240s stream_idle_timeout
# resets them (504), so keep real headroom above peak — but size against
# measured peaks, not guesses. Measured over 30 days (2026-07-10..2026-08-09):
# CPU avg 0.0076 vCPU, peak 0.274; memory avg 192MB, peak 229MB. The previous
# 1.75/3.5Gi default was ~15x peak and cost ~$71/mo on ACA's per-allocated-
# vCPU/GiB billing; 0.75/1.5Gi keeps ~2.7x headroom over peak CPU and ~6.5x
# over peak memory for ~$30/mo. Re-check the metrics above before shrinking
# further — 0.5/1Gi would leave under 2x CPU headroom.
#
# Ephemeral disk is the non-obvious coupling: ACA sizes it off vCPU, not memory
# (<=1 vCPU -> 4 GiB, >1 vCPU -> 8 GiB), so 1.75 -> 0.75 also halved this
# replica's disk to 4 GiB. That is deliberate and measured, not overlooked:
# src/jobs/workspace.ts clones each review workspace with --depth=50 into
# tmpdir, and a depth-50 clone of xbmc/xbmc (the largest repo reviewed) is
# 218 MB, so 4 GiB holds ~18 concurrent workspaces against stale-reaping at
# 1 hour and a few reviews per hour. If review concurrency or repo size grows
# materially, go to 1.25/2.5Gi to get back to 8 GiB rather than shrinking CPU.
# NOTE: ACA requires valid cpu/memory pairings (e.g. 0.75/1.5Gi, 1.0/2Gi). Keep
# ACA_MAX_REPLICAS=1 unless the MCP token registry is moved to shared durable
# storage — agent MCP callbacks must reach a replica that can validate and
# reconstruct the job token's server factories.
ACA_CPU=${ACA_CPU:-0.75}
ACA_MEMORY=${ACA_MEMORY:-1.5Gi}
if ! [[ "$ACA_CPU" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
echo "ERROR: ACA_CPU must be a number (cores), e.g. 2.0." >&2
exit 1
fi
if ! [[ "$ACA_MEMORY" =~ ^[0-9]+(\.[0-9]+)?Gi$ ]]; then
echo "ERROR: ACA_MEMORY must look like '4.0Gi'." >&2
exit 1
fi
BUILD_CONTEXT_DIR=$(mktemp -d)
KEYVAULT_TEMP_FILES=()
cleanup_deploy_artifacts() {
rm -rf "$BUILD_CONTEXT_DIR"
if [[ ${#KEYVAULT_TEMP_FILES[@]} -gt 0 ]]; then
rm -f "${KEYVAULT_TEMP_FILES[@]}"
fi
}
trap cleanup_deploy_artifacts EXIT
prepare_build_context() {
mkdir -p "$BUILD_CONTEXT_DIR"
rm -rf "$BUILD_CONTEXT_DIR"/*
git archive --format=tar "$SOURCE_COMMIT" \
package.json bun.lock tsconfig.json Dockerfile Dockerfile.agent src \
| tar -x -C "$BUILD_CONTEXT_DIR"
echo "==> Prepared git build context at $BUILD_CONTEXT_DIR from commit $SOURCE_COMMIT"
}
prepare_build_context
# -- Validate required environment variables ----------------------------------
missing=()
[[ -z "${GITHUB_APP_ID:-}" ]] && missing+=("GITHUB_APP_ID")
[[ -z "${GITHUB_PRIVATE_KEY_BASE64:-}" ]] && missing+=("GITHUB_PRIVATE_KEY_BASE64")
[[ -z "${GITHUB_WEBHOOK_SECRET:-}" ]] && missing+=("GITHUB_WEBHOOK_SECRET")
[[ -z "${CLAUDE_CODE_OAUTH_TOKEN:-}" ]] && missing+=("CLAUDE_CODE_OAUTH_TOKEN")
[[ -z "${VOYAGE_API_KEY:-}" ]] && missing+=("VOYAGE_API_KEY")
[[ -z "${SLACK_BOT_TOKEN:-}" ]] && missing+=("SLACK_BOT_TOKEN")
[[ -z "${SLACK_SIGNING_SECRET:-}" ]] && missing+=("SLACK_SIGNING_SECRET")
[[ -z "${SLACK_BOT_USER_ID:-}" ]] && missing+=("SLACK_BOT_USER_ID")
[[ -z "${SLACK_KODIAI_CHANNEL_ID:-}" ]] && missing+=("SLACK_KODIAI_CHANNEL_ID")
[[ -z "${DATABASE_URL:-}" ]] && missing+=("DATABASE_URL")
if [[ ${#missing[@]} -gt 0 ]]; then
echo "ERROR: The following environment variables are required but not set:"
for var in "${missing[@]}"; do
echo " - $var"
done
echo ""
echo "Hint: base64-encode your PEM key with: base64 -w0 < private-key.pem"
exit 1
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "ERROR: python3 is required for YAML quoting but is not installed."
exit 1
fi
# -- Optional environment variables with defaults --------------------------------
SHUTDOWN_GRACE_MS=${SHUTDOWN_GRACE_MS:-180000}
SHUTDOWN_MAX_TOTAL_GRACE_MS=${SHUTDOWN_MAX_TOTAL_GRACE_MS:-540000}
BOT_USER_ENV_YAML=""
BOT_USER_SECRET_REF_YAML=""
BOT_USER_CREATE_SECRET_ARGS=()
BOT_USER_CREATE_ENV_ARGS=()
echo "==> Installing / upgrading Azure CLI extensions..."
if ! az extension show --name containerapp >/dev/null 2>&1; then
az extension add --name containerapp --upgrade -y 2>/dev/null
fi
AZURE_SUBSCRIPTION_ID=${AZURE_SUBSCRIPTION_ID:-$(az account show --query id -o tsv)}
echo "==> Registering resource providers (may take a minute on first run)..."
APP_PROVIDER_STATE=$(az provider show --namespace Microsoft.App --query registrationState --output tsv 2>/dev/null || true)
if [[ "$APP_PROVIDER_STATE" != "Registered" ]]; then
az provider register --namespace Microsoft.App --wait
fi
OPS_PROVIDER_STATE=$(az provider show --namespace Microsoft.OperationalInsights --query registrationState --output tsv 2>/dev/null || true)
if [[ "$OPS_PROVIDER_STATE" != "Registered" ]]; then
az provider register --namespace Microsoft.OperationalInsights --wait
fi
INSIGHTS_PROVIDER_STATE=$(az provider show --namespace Microsoft.Insights --query registrationState --output tsv 2>/dev/null || true)
if [[ "$INSIGHTS_PROVIDER_STATE" != "Registered" ]]; then
az provider register --namespace Microsoft.Insights --wait
fi
KV_PROVIDER_STATE=$(az provider show --namespace Microsoft.KeyVault --query registrationState --output tsv 2>/dev/null || true)
if [[ "$KV_PROVIDER_STATE" != "Registered" ]]; then
az provider register --namespace Microsoft.KeyVault --wait || {
echo "ERROR: Failed to register Azure provider Microsoft.KeyVault." >&2
exit 1
}
fi
if [[ -z "$KEY_VAULT_NAME" ]]; then
if ! SUBSCRIPTION_ID=$(az account show --query id --output tsv); then
echo "ERROR: Failed to read Azure subscription ID for default Key Vault naming." >&2
exit 1
fi
if [[ -z "$SUBSCRIPTION_ID" ]]; then
echo "ERROR: Azure subscription ID was empty; set KEY_VAULT_NAME explicitly." >&2
exit 1
fi
KEY_VAULT_NAME="kv-kodiai-${SUBSCRIPTION_ID%%-*}"
fi
if [[ ! "$KEY_VAULT_NAME" =~ ^[a-zA-Z][a-zA-Z0-9-]{1,22}[a-zA-Z0-9]$ ]]; then
echo "ERROR: KEY_VAULT_NAME='$KEY_VAULT_NAME' violates Azure naming constraints." >&2
echo " Use 3-24 characters: alphanumerics and hyphens, start with a letter, and do not end with a hyphen." >&2
exit 1
fi
resolve_log_analytics_workspace_resource_id() {
if [[ -n "$LOG_ANALYTICS_WORKSPACE_RESOURCE_ID" ]]; then
echo "$LOG_ANALYTICS_WORKSPACE_RESOURCE_ID"
return 0
fi
local environment_workspace_customer_id=""
environment_workspace_customer_id=$(az containerapp env show \
--name "$ENVIRONMENT" \
--resource-group "$RESOURCE_GROUP" \
--query properties.appLogsConfiguration.logAnalyticsConfiguration.customerId \
--output tsv 2>/dev/null || true)
if [[ -n "$environment_workspace_customer_id" && "$environment_workspace_customer_id" != "null" ]]; then
local existing_workspace_resource_id=""
existing_workspace_resource_id=$(az monitor log-analytics workspace list \
--resource-group "$RESOURCE_GROUP" \
--query "[?customerId=='${environment_workspace_customer_id}'].id | [0]" \
--output tsv 2>/dev/null || true)
if [[ -n "$existing_workspace_resource_id" && "$existing_workspace_resource_id" != "null" ]]; then
echo "$existing_workspace_resource_id"
return 0
fi
fi
local environment_id=""
environment_id=$(az containerapp env show \
--name "$ENVIRONMENT" \
--resource-group "$RESOURCE_GROUP" \
--query id \
--output tsv 2>/dev/null || true)
if [[ -n "$environment_id" && "$environment_id" != "null" ]]; then
local diagnostic_workspace_resource_id=""
diagnostic_workspace_resource_id=$(az monitor diagnostic-settings list \
--resource "$environment_id" \
--query "[?name=='${ACA_DIAGNOSTIC_SETTING_NAME}'].workspaceId | [0]" \
--output tsv 2>/dev/null || true)
if [[ -n "$diagnostic_workspace_resource_id" && "$diagnostic_workspace_resource_id" != "null" ]]; then
echo "$diagnostic_workspace_resource_id"
return 0
fi
fi
if ! az monitor log-analytics workspace show \
--resource-group "$RESOURCE_GROUP" \
--workspace-name "$LOG_ANALYTICS_WORKSPACE_NAME" \
--output none 2>/dev/null; then
echo "==> Creating Log Analytics workspace: $LOG_ANALYTICS_WORKSPACE_NAME..." >&2
az monitor log-analytics workspace create \
--resource-group "$RESOURCE_GROUP" \
--workspace-name "$LOG_ANALYTICS_WORKSPACE_NAME" \
--location "$LOCATION" \
--output none
fi
az monitor log-analytics workspace show \
--resource-group "$RESOURCE_GROUP" \
--workspace-name "$LOG_ANALYTICS_WORKSPACE_NAME" \
--query id \
--output tsv
}
ensure_containerapp_environment_logging() {
local environment_id="$1"
local workspace_resource_id="$2"
echo "==> Configuring Container Apps environment logs through Azure Monitor diagnostics..."
az containerapp env update \
--name "$ENVIRONMENT" \
--resource-group "$RESOURCE_GROUP" \
--logs-destination azure-monitor \
--output none
local logs_json='[{"category":"ContainerAppConsoleLogs","enabled":true},{"category":"ContainerAppSystemLogs","enabled":true},{"category":"ContainerAppHTTPLogs","enabled":true}]'
local metrics_json='[{"category":"AllMetrics","enabled":true}]'
if az monitor diagnostic-settings show \
--name "$ACA_DIAGNOSTIC_SETTING_NAME" \
--resource "$environment_id" \
--output none 2>/dev/null; then
az monitor diagnostic-settings update \
--name "$ACA_DIAGNOSTIC_SETTING_NAME" \
--resource "$environment_id" \
--logs "$logs_json" \
--metrics "$metrics_json" \
--workspace-id "$workspace_resource_id" \
--log-analytics-destination-type Dedicated \
--output none
else
az monitor diagnostic-settings create \
--name "$ACA_DIAGNOSTIC_SETTING_NAME" \
--resource "$environment_id" \
--logs "$logs_json" \
--metrics "$metrics_json" \
--workspace "$workspace_resource_id" \
--export-to-resource-specific true \
--output none
fi
}
# -- Resource Group -----------------------------------------------------------
echo "==> Creating resource group: $RESOURCE_GROUP in $LOCATION..."
az group create \
--name "$RESOURCE_GROUP" \
--location "$LOCATION" \
--output none
# -- Azure Container Registry ------------------------------------------------
echo "==> Creating Azure Container Registry: $ACR_NAME..."
if ! az acr show --resource-group "$RESOURCE_GROUP" --name "$ACR_NAME" --output none 2>/dev/null; then
az acr create \
--resource-group "$RESOURCE_GROUP" \
--name "$ACR_NAME" \
--sku Basic \
--location "$LOCATION" \
--output none
fi
echo "==> Mirroring Bun base image into ACR: $BUN_BASE_SOURCE_IMAGE -> $BUN_BASE_ACR_IMAGE..."
ACR_IMPORT_ARGS=(
--name "$ACR_NAME"
--source "$BUN_BASE_SOURCE_IMAGE"
--image "$BUN_BASE_ACR_IMAGE"
--force
--output none
)
if [[ -n "${DOCKERHUB_USERNAME:-}" && -n "${DOCKERHUB_TOKEN:-}" ]]; then
ACR_IMPORT_ARGS+=(--username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN")
fi
az acr import "${ACR_IMPORT_ARGS[@]}"
# -- Managed Identity ---------------------------------------------------------
echo "==> Creating managed identity: $IDENTITY_NAME..."
if ! az identity show --name "$IDENTITY_NAME" --resource-group "$RESOURCE_GROUP" --output none 2>/dev/null; then
az identity create \
--name "$IDENTITY_NAME" \
--resource-group "$RESOURCE_GROUP" \
--output none
fi
# Grant AcrPull to the managed identity on the ACR
IDENTITY_PRINCIPAL_ID=$(az identity show \
--name "$IDENTITY_NAME" \
--resource-group "$RESOURCE_GROUP" \
--query principalId \
--output tsv)
IDENTITY_RESOURCE_ID=$(az identity show \
--name "$IDENTITY_NAME" \
--resource-group "$RESOURCE_GROUP" \
--query id \
--output tsv)
AZURE_MANAGED_IDENTITY_CLIENT_ID=${AZURE_MANAGED_IDENTITY_CLIENT_ID:-$(az identity show \
--name "$IDENTITY_NAME" \
--resource-group "$RESOURCE_GROUP" \
--query clientId \
--output tsv)}
ACR_RESOURCE_ID=$(az acr show \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP" \
--query id \
--output tsv)
echo "==> Granting AcrPull role to managed identity..."
az role assignment create \
--assignee "$IDENTITY_PRINCIPAL_ID" \
--role AcrPull \
--scope "$ACR_RESOURCE_ID" \
--output none 2>/dev/null || true # Idempotent: ignore "already exists"
# -- Build & Push Image -------------------------------------------------------
echo "==> Building and pushing image via ACR (remote build)..."
APP_IMAGE_DIGEST=$(az acr build \
--registry "$ACR_NAME" \
--image kodiai:latest \
--build-arg "BUN_BASE_IMAGE=$BUN_BASE_IMAGE" \
--no-logs \
"$BUILD_CONTEXT_DIR" \
--query 'outputImages[0].digest' \
--output tsv)
APP_IMAGE="${ACR_NAME}.azurecr.io/kodiai@${APP_IMAGE_DIGEST}"
# -- Azure Storage Account (for Azure Files workspace share) ------------------
STORAGE_ACCOUNT_NAME="kodiaistg" # globally unique, lowercase alphanumeric
FILE_SHARE_NAME="workspaces"
echo "==> Provisioning Azure Storage Account: $STORAGE_ACCOUNT_NAME..."
if ! az storage account show --name "$STORAGE_ACCOUNT_NAME" --resource-group "$RESOURCE_GROUP" --output none 2>/dev/null; then
az storage account create \
--name "$STORAGE_ACCOUNT_NAME" \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--sku Standard_LRS \
--kind StorageV2 \
--output none
fi
STORAGE_KEY=$(az storage account keys list \
--account-name "$STORAGE_ACCOUNT_NAME" \
--resource-group "$RESOURCE_GROUP" \
--query '[0].value' \
--output tsv)
echo "==> Provisioning Azure Files share: $FILE_SHARE_NAME..."
if ! az storage share exists \
--name "$FILE_SHARE_NAME" \
--account-name "$STORAGE_ACCOUNT_NAME" \
--account-key "$STORAGE_KEY" \
--query exists \
--output tsv 2>/dev/null | grep -q true; then
az storage share create \
--name "$FILE_SHARE_NAME" \
--account-name "$STORAGE_ACCOUNT_NAME" \
--account-key "$STORAGE_KEY" \
--output none
fi
# -- Container Apps Environment -----------------------------------------------
echo "==> Creating Container Apps environment: $ENVIRONMENT..."
if ! az containerapp env show --name "$ENVIRONMENT" --resource-group "$RESOURCE_GROUP" --output none 2>/dev/null; then
az containerapp env create \
--name "$ENVIRONMENT" \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--output none
fi
ENVIRONMENT_ID=$(az containerapp env show \
--name "$ENVIRONMENT" \
--resource-group "$RESOURCE_GROUP" \
--query id \
--output tsv)
LOG_ANALYTICS_WORKSPACE_RESOURCE_ID=$(resolve_log_analytics_workspace_resource_id)
ensure_containerapp_environment_logging "$ENVIRONMENT_ID" "$LOG_ANALYTICS_WORKSPACE_RESOURCE_ID"
# -- Storage mount on ACA environment -----------------------------------------
echo "==> Mounting Azure Files share on Container Apps environment..."
az containerapp env storage set \
--name "$ENVIRONMENT" \
--resource-group "$RESOURCE_GROUP" \
--storage-name kodiai-workspaces \
--azure-file-account-name "$STORAGE_ACCOUNT_NAME" \
--azure-file-account-key "$STORAGE_KEY" \
--azure-file-share-name "$FILE_SHARE_NAME" \
--access-mode ReadWrite \
--output none 2>/dev/null || true
# -- Build agent image ---------------------------------------------------------
echo "==> Building and pushing agent image via ACR (remote build)..."
ACA_JOB_IMAGE_DIGEST=$(az acr build \
--registry "$ACR_NAME" \
--image kodiai-agent:latest \
--file Dockerfile.agent \
--build-arg "BUN_BASE_IMAGE=$BUN_BASE_IMAGE" \
--no-logs \
"$BUILD_CONTEXT_DIR" \
--query 'outputImages[0].digest' \
--output tsv)
# -- ACA Job (agent runner) ---------------------------------------------------
ACA_JOB_NAME="caj-kodiai-agent"
# Keep the ACA job timeout above the maximum repo-config execution timeout
# (1800s) so the agent can hit its own deadline and publish timeout/error
# handling instead of being hard-killed by the platform first.
ACA_JOB_REPLICA_TIMEOUT=1860
echo "==> Provisioning ACA Job: $ACA_JOB_NAME..."
ACA_JOB_IMAGE="${ACR_NAME}.azurecr.io/kodiai-agent@${ACA_JOB_IMAGE_DIGEST}"
ACA_JOB_YAML=$(mktemp --suffix=.yaml)
cat > "$ACA_JOB_YAML" <<ACAYAML
properties:
environmentId: /subscriptions/$(az account show --query id -o tsv)/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.App/managedEnvironments/${ENVIRONMENT}
configuration:
triggerType: Manual
replicaTimeout: ${ACA_JOB_REPLICA_TIMEOUT}
replicaRetryLimit: 0
registries:
- server: "${ACR_NAME}.azurecr.io"
identity: "${IDENTITY_RESOURCE_ID}"
template:
containers:
- name: "${ACA_JOB_NAME}"
image: "${ACA_JOB_IMAGE}"
env:
- name: SOURCE_COMMIT
value: ${SOURCE_COMMIT}
volumeMounts:
- volumeName: kodiai-workspaces
mountPath: /mnt/kodiai-workspaces
volumes:
- name: kodiai-workspaces
storageName: kodiai-workspaces
storageType: AzureFile
ACAYAML
if az containerapp job show --name "$ACA_JOB_NAME" --resource-group "$RESOURCE_GROUP" --output none 2>/dev/null; then
az containerapp job update \
--name "$ACA_JOB_NAME" \
--resource-group "$RESOURCE_GROUP" \
--image "$ACA_JOB_IMAGE" \
--yaml "$ACA_JOB_YAML" \
--output none
else
az containerapp job create \
--name "$ACA_JOB_NAME" \
--resource-group "$RESOURCE_GROUP" \
--environment "$ENVIRONMENT" \
--trigger-type Manual \
--replica-timeout "$ACA_JOB_REPLICA_TIMEOUT" \
--replica-retry-limit 0 \
--image "$ACA_JOB_IMAGE" \
--user-assigned "$IDENTITY_RESOURCE_ID" \
--registry-server "$ACR_NAME.azurecr.io" \
--registry-identity "$IDENTITY_RESOURCE_ID" \
--output none
# Apply volume mount via YAML update (az containerapp job create lacks --volume flags)
az containerapp job update \
--name "$ACA_JOB_NAME" \
--resource-group "$RESOURCE_GROUP" \
--yaml "$ACA_JOB_YAML" \
--output none
fi
rm -f "$ACA_JOB_YAML"
# -- Azure Key Vault (shared runtime secrets) ----------------------------------
echo "==> Creating Azure Key Vault: $KEY_VAULT_NAME..."
if ! az keyvault show --name "$KEY_VAULT_NAME" --resource-group "$RESOURCE_GROUP" --output none 2>/dev/null; then
az keyvault create \
--name "$KEY_VAULT_NAME" \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--enable-rbac-authorization true \
--output none || {
echo "ERROR: Failed to create Key Vault '$KEY_VAULT_NAME' in resource group '$RESOURCE_GROUP'." >&2
exit 1
}
fi
if ! KEY_VAULT_ID=$(az keyvault show --name "$KEY_VAULT_NAME" --resource-group "$RESOURCE_GROUP" --query id --output tsv); then
echo "ERROR: Failed to read Key Vault resource ID for '$KEY_VAULT_NAME'." >&2
exit 1
fi
if [[ -z "$KEY_VAULT_ID" ]]; then
echo "ERROR: Key Vault resource ID for '$KEY_VAULT_NAME' was empty." >&2
exit 1
fi
KEY_VAULT_URI="https://${KEY_VAULT_NAME}.vault.azure.net/secrets"
ensure_role_assignment() {
local assignee_object_id="$1"
local principal_type="$2"
local role_name="$3"
local scope="$4"
local description="$5"
local err_file
err_file=$(mktemp)
KEYVAULT_TEMP_FILES+=("$err_file")
if az role assignment create \
--assignee-object-id "$assignee_object_id" \
--assignee-principal-type "$principal_type" \
--role "$role_name" \
--scope "$scope" \
--output none 2>"$err_file"; then
rm -f "$err_file"
return 0
fi
if grep -Eqi "already exists|RoleAssignmentExists" "$err_file"; then
rm -f "$err_file"
return 0
fi
echo "ERROR: Failed to grant $role_name to $description on $scope:" >&2
cat "$err_file" >&2
rm -f "$err_file"
return 1
}
resolve_deployer_principal() {
DEPLOYER_PRINCIPAL_TYPE=${DEPLOYER_PRINCIPAL_TYPE:-}
DEPLOYER_OBJECT_ID=${DEPLOYER_OBJECT_ID:-}
if { [[ -n "$DEPLOYER_OBJECT_ID" ]] && [[ -z "$DEPLOYER_PRINCIPAL_TYPE" ]]; } || { [[ -z "$DEPLOYER_OBJECT_ID" ]] && [[ -n "$DEPLOYER_PRINCIPAL_TYPE" ]]; }; then
echo "ERROR: DEPLOYER_OBJECT_ID and DEPLOYER_PRINCIPAL_TYPE must be set together." >&2
echo " DEPLOYER_PRINCIPAL_TYPE must be User or ServicePrincipal." >&2
exit 1
fi
if [[ -n "$DEPLOYER_OBJECT_ID" && -n "$DEPLOYER_PRINCIPAL_TYPE" ]]; then
case "$DEPLOYER_PRINCIPAL_TYPE" in
User|ServicePrincipal) return 0 ;;
*)
echo "ERROR: DEPLOYER_PRINCIPAL_TYPE must be User or ServicePrincipal, got '$DEPLOYER_PRINCIPAL_TYPE'." >&2
exit 1
;;
esac
fi
local account_user_type
account_user_type=$(az account show --query user.type --output tsv 2>/dev/null || true)
case "$account_user_type" in
user)
if [[ -z "$DEPLOYER_OBJECT_ID" ]]; then
if ! DEPLOYER_OBJECT_ID=$(az ad signed-in-user show --query id --output tsv); then
echo "ERROR: Failed to resolve Azure signed-in user object ID." >&2
echo " Set DEPLOYER_OBJECT_ID and DEPLOYER_PRINCIPAL_TYPE explicitly if directory lookup is blocked." >&2
exit 1
fi
fi
DEPLOYER_PRINCIPAL_TYPE=${DEPLOYER_PRINCIPAL_TYPE:-User}
;;
servicePrincipal)
if [[ -z "$DEPLOYER_OBJECT_ID" ]]; then
local service_principal_app_id
if ! service_principal_app_id=$(az account show --query user.name --output tsv); then
echo "ERROR: Failed to resolve Azure service principal app ID from current account." >&2
exit 1
fi
if [[ -z "$service_principal_app_id" ]]; then
echo "ERROR: Azure service principal app ID was empty." >&2
exit 1
fi
if ! DEPLOYER_OBJECT_ID=$(az ad sp show --id "$service_principal_app_id" --query id --output tsv); then
echo "ERROR: Failed to resolve Azure service principal object ID for '$service_principal_app_id'." >&2
echo " Set DEPLOYER_OBJECT_ID and DEPLOYER_PRINCIPAL_TYPE explicitly if Graph lookup is blocked." >&2
exit 1
fi
fi
DEPLOYER_PRINCIPAL_TYPE=${DEPLOYER_PRINCIPAL_TYPE:-ServicePrincipal}
;;
*)
echo "ERROR: Could not determine Azure deployer principal type." >&2
echo " Set DEPLOYER_OBJECT_ID and DEPLOYER_PRINCIPAL_TYPE explicitly for non-interactive deploys." >&2
exit 1
;;
esac
if [[ -z "$DEPLOYER_OBJECT_ID" ]]; then
echo "ERROR: Could not resolve Azure deployer object ID." >&2
echo " Set DEPLOYER_OBJECT_ID and DEPLOYER_PRINCIPAL_TYPE explicitly for this deployment identity." >&2
exit 1
fi
case "$DEPLOYER_PRINCIPAL_TYPE" in
User|ServicePrincipal) ;;
*)
echo "ERROR: DEPLOYER_PRINCIPAL_TYPE must be User or ServicePrincipal, got '$DEPLOYER_PRINCIPAL_TYPE'." >&2
exit 1
;;
esac
}
if [[ -n "${BOT_USER_PAT:-}" && -n "${BOT_USER_LOGIN:-}" ]]; then
BOT_USER_SECRET_REF_YAML=$(cat <<EOF
- name: bot-user-pat
keyVaultUrl: ${KEY_VAULT_URI}/bot-user-pat
identity: ${IDENTITY_RESOURCE_ID}
EOF
)
BOT_USER_ENV_YAML=$(cat <<EOF
- name: BOT_USER_PAT
secretRef: bot-user-pat
- name: BOT_USER_LOGIN
value: $(yaml_quote "$BOT_USER_LOGIN")
EOF
)
BOT_USER_CREATE_SECRET_ARGS+=("bot-user-pat=keyvaultref:${KEY_VAULT_URI}/bot-user-pat,identityref:${IDENTITY_RESOURCE_ID}")
BOT_USER_CREATE_ENV_ARGS+=(
"BOT_USER_PAT=secretref:bot-user-pat"
"BOT_USER_LOGIN=${BOT_USER_LOGIN}"
)
elif [[ -n "${BOT_USER_PAT:-}" || -n "${BOT_USER_LOGIN:-}" ]]; then
echo "WARNING: BOT_USER_PAT and BOT_USER_LOGIN must both be set to enable fork/gist features; skipping bot-user env injection."
fi
echo "==> Granting Key Vault secret-read access to managed identity..."
ensure_role_assignment \
"$IDENTITY_PRINCIPAL_ID" \
ServicePrincipal \
"Key Vault Secrets User" \
"$KEY_VAULT_ID" \
"managed identity $IDENTITY_NAME" || {
echo "ERROR: Managed identity cannot read Key Vault secrets; aborting deploy." >&2
exit 1
}
echo "==> Granting Key Vault secret-write access to deployer..."
resolve_deployer_principal
ensure_role_assignment \
"$DEPLOYER_OBJECT_ID" \
"$DEPLOYER_PRINCIPAL_TYPE" \
"Key Vault Secrets Officer" \
"$KEY_VAULT_ID" \
"deployer principal $DEPLOYER_OBJECT_ID" || {
echo "ERROR: Deployer cannot write Key Vault secrets; aborting deploy." >&2
exit 1
}
set_keyvault_secret() {
local name="$1"
local value="$2"
local attempts=30
local delay=10
local i
local err_file
local first_err_file
err_file=$(mktemp)
first_err_file=$(mktemp)
KEYVAULT_TEMP_FILES+=("$err_file" "$first_err_file")
for i in $(seq 1 "$attempts"); do
if printf '%s' "$value" | az keyvault secret set --vault-name "$KEY_VAULT_NAME" --name "$name" --file /dev/stdin --output none 2>"$err_file"; then
if [[ "$i" -gt 1 ]]; then
echo " -> $name: succeeded after $i attempts"
fi
rm -f "$err_file" "$first_err_file"
return 0
fi
if [[ "$i" -eq 1 ]]; then
cp "$err_file" "$first_err_file"
fi
if [[ "$i" -lt "$attempts" ]]; then
echo " -> $name: attempt $i/$attempts failed; retrying in ${delay}s..."
fi
sleep "$delay"
done
echo "ERROR: Failed to set Key Vault secret '$name' after $attempts attempts." >&2
echo "First failure:" >&2
cat "$first_err_file" >&2
echo "Last failure:" >&2
cat "$err_file" >&2
rm -f "$err_file" "$first_err_file"
return 1
}
sync_keyvault_secret() {
local name="$1"
local value="$2"
if [[ -z "$value" ]]; then
echo "ERROR: Required Key Vault secret '$name' has an empty deploy input value; aborting deploy." >&2
exit 1
fi
set_keyvault_secret "$name" "$value" || {
echo "ERROR: Required Key Vault secret '$name' was not synced; aborting deploy." >&2
exit 1
}
}
echo "==> Syncing runtime secrets into Azure Key Vault..."
sync_keyvault_secret github-app-id "$GITHUB_APP_ID"
sync_keyvault_secret github-private-key "$GITHUB_PRIVATE_KEY_BASE64"
sync_keyvault_secret github-webhook-secret "$GITHUB_WEBHOOK_SECRET"
sync_keyvault_secret claude-code-oauth-token "$CLAUDE_CODE_OAUTH_TOKEN"
sync_keyvault_secret voyage-api-key "$VOYAGE_API_KEY"
sync_keyvault_secret slack-bot-token "$SLACK_BOT_TOKEN"
sync_keyvault_secret slack-signing-secret "$SLACK_SIGNING_SECRET"
sync_keyvault_secret database-url "$DATABASE_URL"
if [[ -n "${BOT_USER_PAT:-}" && -n "${BOT_USER_LOGIN:-}" ]]; then
sync_keyvault_secret bot-user-pat "$BOT_USER_PAT"
fi
echo "==> Pointing ACA Job secrets at Azure Key Vault..."
az containerapp job secret set \
--name "$ACA_JOB_NAME" \
--resource-group "$RESOURCE_GROUP" \
--secrets \
"claude-code-oauth-token=keyvaultref:${KEY_VAULT_URI}/claude-code-oauth-token,identityref:${IDENTITY_RESOURCE_ID}" \
--output none || {
echo "ERROR: Failed to point ACA Job Claude token secret at Azure Key Vault; aborting deploy." >&2
exit 1
}
# -- Deploy Container App -----------------------------------------------------
echo "==> Deploying container app: $APP_NAME..."
if az containerapp show --name "$APP_NAME" --resource-group "$RESOURCE_GROUP" --output none 2>/dev/null; then
# Single-revision mode means updating the app sends SIGTERM to the currently
# running revision. If jobs are still in flight when that happens, the
# process only gets a bounded grace window (SHUTDOWN_GRACE_MS +
# SHUTDOWN_MAX_TOTAL_GRACE_MS) before it force-exits and abandons them
# (see src/lifecycle/shutdown-manager.ts). Refuse to trigger the swap until
# the running revision reports zero in-flight work, so a deploy never kills
# in-flight jobs -- it waits, or it fails loudly and lets the operator retry.
DEPLOY_DRAIN_WAIT_TIMEOUT_SECONDS=${DEPLOY_DRAIN_WAIT_TIMEOUT_SECONDS:-900}
DEPLOY_DRAIN_POLL_INTERVAL_SECONDS=${DEPLOY_DRAIN_POLL_INTERVAL_SECONDS:-10}
EXISTING_FQDN=$(az containerapp show \
--name "$APP_NAME" \
--resource-group "$RESOURCE_GROUP" \
--query properties.configuration.ingress.fqdn \
--output tsv 2>/dev/null || true)
if [[ -z "$EXISTING_FQDN" ]]; then
echo "WARNING: Could not resolve the running revision's ingress FQDN; skipping the in-flight-job drain check." >&2
else
echo "==> Checking https://${EXISTING_FQDN}/internal/drain-status for in-flight jobs before deploying..."
waited_seconds=0
while true; do
drain_http_code=$(curl -sS -m 5 -o /tmp/kodiai-drain-status.json -w '%{http_code}' "https://${EXISTING_FQDN}/internal/drain-status" 2>/dev/null || echo 000)
if [[ "$drain_http_code" == "404" ]]; then
echo "WARNING: Running revision does not expose /internal/drain-status (pre-dates this check); proceeding without an in-flight-job guarantee." >&2
break
fi
if [[ "$drain_http_code" == "200" ]]; then
drain_status_json=$(cat /tmp/kodiai-drain-status.json 2>/dev/null || echo '{}')
active_total=$(python3 -c '
import json, sys
try:
print(int(json.loads(sys.argv[1]).get("activeTotal", 0)))
except Exception:
print(-1)
' "$drain_status_json" 2>/dev/null || echo -1)
else
active_total=-1
fi
rm -f /tmp/kodiai-drain-status.json
if [[ "$active_total" == "0" ]]; then
echo "==> Running revision is idle. Safe to deploy."
break
fi
if (( waited_seconds >= DEPLOY_DRAIN_WAIT_TIMEOUT_SECONDS )); then
echo "ERROR: Refusing to deploy -- the running revision still reports in-flight work (or was unreachable) after waiting ${DEPLOY_DRAIN_WAIT_TIMEOUT_SECONDS}s (last HTTP status: ${drain_http_code})." >&2
echo " Re-run deploy.sh once the running revision is idle, or raise DEPLOY_DRAIN_WAIT_TIMEOUT_SECONDS if long-running jobs are expected." >&2
exit 1
fi
if [[ "$active_total" == "-1" ]]; then
echo " Could not read drain-status from the running revision yet (HTTP ${drain_http_code}, ${waited_seconds}s/${DEPLOY_DRAIN_WAIT_TIMEOUT_SECONDS}s); retrying..."
else
echo " Waiting for ${active_total} in-flight job(s)/request(s) to finish before deploying (${waited_seconds}s/${DEPLOY_DRAIN_WAIT_TIMEOUT_SECONDS}s)..."
fi
sleep "$DEPLOY_DRAIN_POLL_INTERVAL_SECONDS"
waited_seconds=$((waited_seconds + DEPLOY_DRAIN_POLL_INTERVAL_SECONDS))
done
fi
REVISION_SUFFIX="deploy-${SOURCE_COMMIT_SHORT}-$(date +%Y%m%d-%H%M%S)"
echo "==> Updating existing container app (revision: $REVISION_SUFFIX)..."
APP_YAML=$(mktemp --suffix=.yaml)
cat > "$APP_YAML" <<APPYAML
properties:
configuration:
activeRevisionsMode: Single
ingress:
external: true
targetPort: 3000
transport: Auto
registries:
- server: ${ACR_NAME}.azurecr.io
identity: ${IDENTITY_RESOURCE_ID}
secrets:
- name: github-app-id
keyVaultUrl: ${KEY_VAULT_URI}/github-app-id
identity: ${IDENTITY_RESOURCE_ID}
- name: github-private-key
keyVaultUrl: ${KEY_VAULT_URI}/github-private-key
identity: ${IDENTITY_RESOURCE_ID}
- name: github-webhook-secret
keyVaultUrl: ${KEY_VAULT_URI}/github-webhook-secret
identity: ${IDENTITY_RESOURCE_ID}
- name: claude-code-oauth-token
keyVaultUrl: ${KEY_VAULT_URI}/claude-code-oauth-token
identity: ${IDENTITY_RESOURCE_ID}
- name: voyage-api-key
keyVaultUrl: ${KEY_VAULT_URI}/voyage-api-key
identity: ${IDENTITY_RESOURCE_ID}
- name: slack-bot-token
keyVaultUrl: ${KEY_VAULT_URI}/slack-bot-token
identity: ${IDENTITY_RESOURCE_ID}
- name: slack-signing-secret
keyVaultUrl: ${KEY_VAULT_URI}/slack-signing-secret
identity: ${IDENTITY_RESOURCE_ID}
- name: database-url
keyVaultUrl: ${KEY_VAULT_URI}/database-url
identity: ${IDENTITY_RESOURCE_ID}
${BOT_USER_SECRET_REF_YAML}
template:
revisionSuffix: ${REVISION_SUFFIX}
terminationGracePeriodSeconds: 600
scale:
minReplicas: ${ACA_MIN_REPLICAS}
maxReplicas: ${ACA_MAX_REPLICAS}
containers:
- name: ${APP_NAME}
image: ${APP_IMAGE}
resources:
cpu: ${ACA_CPU}
memory: ${ACA_MEMORY}
env:
- name: GITHUB_APP_ID
secretRef: github-app-id
- name: GITHUB_PRIVATE_KEY
secretRef: github-private-key
- name: GITHUB_WEBHOOK_SECRET
secretRef: github-webhook-secret
- name: CLAUDE_CODE_OAUTH_TOKEN
secretRef: claude-code-oauth-token
- name: VOYAGE_API_KEY
secretRef: voyage-api-key
- name: SLACK_BOT_TOKEN
secretRef: slack-bot-token
- name: SLACK_SIGNING_SECRET
secretRef: slack-signing-secret
- name: DATABASE_URL
secretRef: database-url
- name: SLACK_BOT_USER_ID
value: $(yaml_quote "$SLACK_BOT_USER_ID")
- name: SLACK_KODIAI_CHANNEL_ID
value: $(yaml_quote "$SLACK_KODIAI_CHANNEL_ID")
${BOT_USER_ENV_YAML}
- name: SHUTDOWN_GRACE_MS
value: $(yaml_quote "$SHUTDOWN_GRACE_MS")
- name: SHUTDOWN_MAX_TOTAL_GRACE_MS
value: $(yaml_quote "$SHUTDOWN_MAX_TOTAL_GRACE_MS")
- name: ACA_JOB_IMAGE
value: $(yaml_quote "$ACA_JOB_IMAGE")
- name: AZURE_SUBSCRIPTION_ID
value: $(yaml_quote "$AZURE_SUBSCRIPTION_ID")
- name: AZURE_MANAGED_IDENTITY_CLIENT_ID
value: $(yaml_quote "$AZURE_MANAGED_IDENTITY_CLIENT_ID")
- name: PORT
value: "3000"
- name: LOG_LEVEL
value: info
- name: SOURCE_COMMIT
value: ${SOURCE_COMMIT}
probes:
- type: Liveness
httpGet:
path: /healthz
port: 3000
timeoutSeconds: 3
initialDelaySeconds: 5
periodSeconds: 30
failureThreshold: 3
- type: Readiness
httpGet:
path: /readiness
port: 3000
timeoutSeconds: 5
initialDelaySeconds: 10
periodSeconds: 10
failureThreshold: 3
- type: Startup
httpGet:
path: /healthz
port: 3000