forked from quarkusio/quarkus-super-heroes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy-to-azure-containerapps.sh
executable file
·791 lines (691 loc) · 27.5 KB
/
deploy-to-azure-containerapps.sh
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
#!/bin/bash -e
# This script automates the deployment to Azure Container Apps
# See /docs/deploying-to-azure-containerapps.md for details
# Display help
help() {
echo "This script deploys the superheroes to Azure Container Apps."
echo "It assumes you have the the following utilities installed on your machine:"
echo " 1) The Azure CLI (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)"
echo " 2) jq (https://stedolan.github.io/jq)"
echo " 3) curl (https://curl.se)"
echo
echo "Additionally, it assumes you are already logged into your Azure environment via the Azure CLI."
echo
echo "Syntax: deploy-to-azure-containerapps.sh [options]"
echo "options:"
echo " -a Create Azure OpenAI resources and bind to the narration service"
echo " By default this is not created and the narration service will serve a default narration on all requests."
echo " -g <resource_group_name> Name of the Azure resource group to use to deploy resources"
echo " Default: 'super-heroes'"
echo " -h Prints this help message"
echo " -l <location> The location (region) to deploy resources into"
echo " Default: 'eastus2'"
echo " -p <database_server_tier> Compute tier of the PostgreSQL/MariaDB servers"
echo " Accepted values: 'Burstable', 'GeneralPurpose', 'MemoryOptimized'"
echo " Default: 'Burstable'"
echo " -r If present, create an Azure Container Registry instance (see https://azure.microsoft.com/en-us/services/container-registry). This is optional. No container images are pushed here by this script."
echo " -s <database_server_sku> The SKU to use for the PostgreSQL/MariaDB servers (see https://azure.microsoft.com/en-us/pricing/details/postgresql/flexible-server / https://azure.microsoft.com/en-us/pricing/details/mysql/flexible-server)"
echo " Default: 'B1ms'"
echo " -t <tag> The tag for the images to deploy"
echo " Accepted values: 'java17-latest' or 'native-latest'"
echo " Default: 'java17-latest'"
echo " -u <unique_identifier> A unique identifier to append to some resources. Some Azure services require unique names within a region (across users)."
echo " Default is to use the output of the 'whoami' command."
}
exit_abnormal() {
echo
help
exit 1
}
cleanup() {
echo "Removing temp directory $TEMP_DIR"
rm -rf $TMP_DIR
}
create_container_registry() {
echo "Creating the $CONTAINER_REGISTRY_NAME container registry"
az acr create \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--name "$CONTAINER_REGISTRY_NAME" \
--sku Standard \
--tags system="$TAG_SYSTEM"
# Allow anonymous pull access
echo "Allowing anonymous pull access to the $CONTAINER_REGISTRY_NAME container registry"
az acr update \
--name "$CONTAINER_REGISTRY_NAME" \
--resource-group "$RESOURCE_GROUP" \
--anonymous-pull-enabled
echo "Getting the URL for the $CONTAINER_REGISTRY_NAME container registry"
CONTAINER_REGISTRY_URL=$(az acr show \
--resource-group "$RESOURCE_GROUP" \
--name "$CONTAINER_REGISTRY_NAME" \
--output json | jq -r .loginServer)
}
create_maria_db() {
local APP_NAME=$1
local DB_NAME=$2
local DB_SCHEMA=$3
local DB_SQL=$4
local DOWNLOADED_SQL_FILE="$TEMP_DIR/${APP_NAME}.sql"
echo "Creating the $DB_NAME MySQL database"
az mysql flexible-server create \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--tags system="$TAG_SYSTEM" application="$APP_NAME" \
--name "$DB_NAME" \
--admin-user "$MARIADB_ADMIN_USER" \
--admin-password "$MARIADB_ADMIN_PWD" \
--public all \
--sku-name "Standard_$MARIADB_SKU" \
--tier "$MARIADB_TIER" \
--storage-size 32 \
--version "$MARIADB_VERSION"
echo
echo "Creating the $DB_SCHEMA schema on the $DB_NAME database"
az mysql flexible-server db create \
--resource-group "$RESOURCE_GROUP" \
--server-name "$DB_NAME" \
--database-name "$DB_SCHEMA"
echo
echo "Downloading $APP_NAME data from $DB_SQL to $DOWNLOADED_SQL_FILE"
curl "$DB_SQL" --output "$DOWNLOADED_SQL_FILE"
echo
echo "Adding data to the $DB_SCHEMA schema in the $DB_NAME database"
az mysql flexible-server execute \
--name "$DB_NAME" \
--admin-user "$POSTGRES_DB_ADMIN" \
--admin-password "$POSTGRES_DB_PWD" \
--database-name "$DB_SCHEMA" \
--file-path "$DOWNLOADED_SQL_FILE"
echo
}
create_postgres_db() {
local APP_NAME=$1
local DB_NAME=$2
local DB_SCHEMA=$3
local DB_SQL=$4
local DOWNLOADED_SQL_FILE="$TEMP_DIR/${APP_NAME}.sql"
echo "Creating the $DB_NAME postgres database"
az postgres flexible-server create \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--tags system="$TAG_SYSTEM" application="$APP_NAME" \
--name "$DB_NAME" \
--admin-user "$POSTGRES_DB_ADMIN" \
--admin-password "$POSTGRES_DB_PWD" \
--public all \
--sku-name "Standard_$POSTGRES_SKU" \
--tier "$POSTGRES_TIER" \
--storage-size 32 \
--version "$POSTGRES_DB_VERSION"
echo
echo "Creating the $DB_SCHEMA schema on the $DB_NAME database"
az postgres flexible-server db create \
--resource-group "$RESOURCE_GROUP" \
--server-name "$DB_NAME" \
--database-name "$DB_SCHEMA"
echo
echo "Downloading $APP_NAME data from $DB_SQL to $DOWNLOADED_SQL_FILE"
curl "$DB_SQL" --output "$DOWNLOADED_SQL_FILE"
echo
echo "Adding data to the $DB_SCHEMA schema in the $DB_NAME database"
az postgres flexible-server execute \
--name "$DB_NAME" \
--admin-user "$POSTGRES_DB_ADMIN" \
--admin-password "$POSTGRES_DB_PWD" \
--database-name "$DB_SCHEMA" \
--file-path "$DOWNLOADED_SQL_FILE"
echo
}
create_mongo_db() {
local DB_NAME=$1
local DB_SCHEMA=$2
echo "Creating the $DB_NAME MongoDB database"
az cosmosdb create \
--resource "$RESOURCE_GROUP" \
--locations regionName="$LOCATION" failoverPriority=0 \
--tags system="$TAG_SYSTEM" application="$FIGHTS_APP" \
--name "$DB_NAME" \
--kind MongoDB \
--server-version "$MONGO_DB_VERSION"
echo
echo "Creating the $DB_SCHEMA schema on the $DB_NAME MongoDB"
az cosmosdb mongodb database create \
--resource-group "$RESOURCE_GROUP" \
--account-name "$DB_NAME" \
--name "$DB_SCHEMA"
echo
}
get_mongo_connect_string() {
local DB_NAME=$1
echo $(az cosmosdb keys list \
--resource-group "$RESOURCE_GROUP" \
--name "$DB_NAME" \
--type connection-strings \
--query "connectionStrings[?description=='Primary MongoDB Connection String'].connectionString" \
--output tsv)
}
create_eventhub() {
echo "Creating the EventHub namespace $KAFKA_NAMESPACE"
az eventhubs namespace create \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--tags system="$TAG_SYSTEM" application="$FIGHTS_APP" \
--name "$KAFKA_NAMESPACE"
echo "Creating the Kafka topic $KAFKA_TOPIC in the EventHub namespace $KAFKA_NAMESPACE"
az eventhubs eventhub create \
--resource-group "$RESOURCE_GROUP" \
--name "$KAFKA_TOPIC" \
--namespace-name "$KAFKA_NAMESPACE"
}
get_eventhub_connect_string() {
echo $(az eventhubs namespace authorization-rule keys list \
--resource-group "$RESOURCE_GROUP" \
--namespace-name "$KAFKA_NAMESPACE" \
--name RootManageSharedAccessKey \
--output json | jq -r .primaryConnectionString)
}
create_apicurio() {
echo "Creating Apicurio Container App"
az containerapp create \
--resource-group "$RESOURCE_GROUP" \
--tags system="$TAG_SYSTEM" application="$FIGHTS_APP" \
--image "$APICURIO_IMAGE" \
--name "$APICURIO_APP" \
--environment "$CONTAINERAPPS_ENVIRONMENT" \
--ingress external \
--target-port 8080 \
--min-replicas 1 \
--env-vars REGISTRY_AUTH_ANONYMOUS_READ_ACCESS_ENABLED=true
echo "Getting Apicurio URL"
APICURIO_URL="https://$(az containerapp ingress show \
--resource-group "$RESOURCE_GROUP" \
--name "$APICURIO_APP" \
--output json | jq -r .fqdn)"
echo "Setting https URLs for Apicurio"
az containerapp update \
--resource-group "$RESOURCE_GROUP" \
--name "$APICURIO_APP" \
--set-env-vars REGISTRY_UI_CONFIG_APIURL="${APICURIO_URL}/apis/registry" \
REGISTRY_UI_CONFIG_UIURL="${APICURIO_URL}/ui"
}
create_heroes_app() {
echo "Creating Heroes Container App"
az containerapp create \
--resource-group "$RESOURCE_GROUP" \
--tags system="$TAG_SYSTEM" application="$HEROES_APP" \
--image "$HEROES_IMAGE" \
--name "$HEROES_APP" \
--environment "$CONTAINERAPPS_ENVIRONMENT" \
--ingress external \
--target-port 8083 \
--min-replicas 1 \
--env-vars QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION=validate \
QUARKUS_HIBERNATE_ORM_SQL_LOAD_SCRIPT=no-file \
QUARKUS_DATASOURCE_USERNAME="$POSTGRES_DB_ADMIN" \
QUARKUS_DATASOURCE_PASSWORD="$POSTGRES_DB_PWD" \
QUARKUS_DATASOURCE_REACTIVE_URL="$HEROES_DB_CONNECT_STRING"
echo "Getting URL to heroes app"
HEROES_URL="https://$(az containerapp ingress show \
--resource-group $RESOURCE_GROUP \
--name $HEROES_APP \
--output json | jq -r .fqdn)"
}
create_villains_app() {
echo "Creating Villains Container App"
az containerapp create \
--resource-group "$RESOURCE_GROUP" \
--tags system="$TAG_SYSTEM" application="$VILLAINS_APP" \
--image "$VILLAINS_IMAGE" \
--name "$VILLAINS_APP" \
--environment "$CONTAINERAPPS_ENVIRONMENT" \
--ingress external \
--target-port 8084 \
--min-replicas 1 \
--env-vars QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION=validate \
QUARKUS_HIBERNATE_ORM_SQL_LOAD_SCRIPT=no-file \
QUARKUS_DATASOURCE_USERNAME="$POSTGRES_DB_ADMIN" \
QUARKUS_DATASOURCE_PASSWORD="$POSTGRES_DB_PWD" \
QUARKUS_DATASOURCE_JDBC_URL="$VILLAINS_DB_CONNECT_STRING"
echo "Getting URL to villains app"
VILLAINS_URL="https://$(az containerapp ingress show \
--resource-group $RESOURCE_GROUP \
--name $VILLAINS_APP \
--output json | jq -r .fqdn)"
}
create_locations_app() {
echo "Creating Locations Container App"
az containerapp create \
--resource-group "$RESOURCE_GROUP" \
--tags system="$TAG_SYSTEM" application="$LOCATIONS_APP" \
--image "$LOCATIONS_IMAGE" \
--name "$LOCATIONS_APP" \
--environment "$CONTAINERAPPS_ENVIRONMENT" \
--ingress external \
--transport http2 \
--target-port 8089 \
--min-replicas 1 \
--env-vars QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION=validate \
QUARKUS_HIBERNATE_ORM_SQL_LOAD_SCRIPT=no-file \
QUARKUS_DATASOURCE_USERNAME="$MARIADB_ADMIN_USER" \
QUARKUS_DATASOURCE_PASSWORD="$MARIADB_ADMIN_PWD" \
QUARKUS_DATASOURCE_JDBC_URL="$LOCATIONS_DB_CONNECT_STRING"
echo "Getting URL to locations app"
LOCATIONS_HOST="$(az containerapp ingress show \
--resource-group $RESOURCE_GROUP \
--name $LOCATIONS_APP \
--output json | jq -r .fqdn)"
}
create_narration_app() {
echo "Creating Narration Container App"
if "$CREATE_AZURE_OPENAI_RESOURCES"; then
az containerapp create \
--resource-group "$RESOURCE_GROUP" \
--tags system="$TAG_SYSTEM" application="$NARRATION_APP" \
--image "${NARRATION_IMAGE}-azure-openai" \
--name "$NARRATION_APP" \
--environment "$CONTAINERAPPS_ENVIRONMENT" \
--ingress external \
--target-port 8087 \
--min-replicas 1 \
--env-vars QUARKUS_PROFILE=azure-openai \
QUARKUS_LANGCHAIN4J_AZURE_OPENAI_API_KEY="$AZURE_OPENAI_KEY" \
QUARKUS_LANGCHAIN4J_AZURE_OPENAI_RESOURCE_NAME="$NARRATION_COGNITIVE_SERVICE" \
QUARKUS_LANGCHAIN4J_AZURE_OPENAI_DEPLOYMENT_ID="$NARRATION_COGNITIVE_SERVICE_DEPLOYMENT_NAME"
else
az containerapp create \
--resource-group "$RESOURCE_GROUP" \
--tags system="$TAG_SYSTEM" application="$NARRATION_APP" \
--image "$NARRATION_IMAGE" \
--name "$NARRATION_APP" \
--environment "$CONTAINERAPPS_ENVIRONMENT" \
--ingress external \
--target-port 8087 \
--min-replicas 1
fi
echo "Getting URL to narration app"
NARRATION_URL="https://$(az containerapp ingress show \
--resource-group $RESOURCE_GROUP \
--name $NARRATION_APP \
--output json | jq -r .fqdn)"
}
create_statistics_app() {
echo "Creating Event Statistics Container App"
az containerapp create \
--resource-group "$RESOURCE_GROUP" \
--tags system="$TAG_SYSTEM" application="$STATISTICS_APP" \
--image "$STATISTICS_IMAGE" \
--name "$STATISTICS_APP" \
--environment "$CONTAINERAPPS_ENVIRONMENT" \
--ingress external \
--target-port 8085 \
--min-replicas 1 \
--env-vars KAFKA_BOOTSTRAP_SERVERS="$KAFKA_BOOTSTRAP_SERVERS" \
KAFKA_SECURITY_PROTOCOL=SASL_SSL \
KAFKA_SASL_MECHANISM=PLAIN \
KAFKA_SASL_JAAS_CONFIG="$KAFKA_JAAS_CONFIG" \
MP_MESSAGING_CONNECTOR_SMALLRYE_KAFKA_APICURIO_REGISTRY_URL="${APICURIO_URL}/apis/registry/v2"
echo "Getting URL to event statistics app"
STATISTICS_URL="https://$(az containerapp ingress show \
--resource-group $RESOURCE_GROUP \
--name $STATISTICS_APP \
--output json | jq -r .fqdn)"
}
create_fights_app() {
echo "Creating Fights Container App"
az containerapp create \
--resource-group "$RESOURCE_GROUP" \
--tags system="$TAG_SYSTEM" application="$FIGHTS_APP" \
--image "$FIGHTS_IMAGE" \
--name "$FIGHTS_APP" \
--environment "$CONTAINERAPPS_ENVIRONMENT" \
--ingress external \
--target-port 8082 \
--min-replicas 1 \
--env-vars KAFKA_BOOTSTRAP_SERVERS="$KAFKA_BOOTSTRAP_SERVERS" \
KAFKA_SECURITY_PROTOCOL=SASL_SSL \
KAFKA_SASL_MECHANISM=PLAIN \
KAFKA_SASL_JAAS_CONFIG="$KAFKA_JAAS_CONFIG" \
MP_MESSAGING_CONNECTOR_SMALLRYE_KAFKA_APICURIO_REGISTRY_URL="${APICURIO_URL}/apis/registry/v2" \
QUARKUS_LIQUIBASE_MONGODB_MIGRATE_AT_START=false \
QUARKUS_MONGODB_CONNECTION_STRING="$MONGO_COLLECTION_CONNECT_STRING" \
QUARKUS_REST_CLIENT_HERO_CLIENT_URL="$HEROES_URL" \
QUARKUS_REST_CLIENT_NARRATION_CLIENT_URL="$NARRATION_URL" \
QUARKUS_GRPC_CLIENTS_LOCATIONS_HOST="$LOCATIONS_HOST" \
QUARKUS_GRPC_CLIENTS_LOCATIONS_PORT=443 \
QUARKUS_GRPC_CLIENTS_LOCATIONS_PLAIN_TEXT=false \
FIGHT_VILLAIN_CLIENT_BASE_URL="$VILLAINS_URL"
echo "Getting URL to event fights app"
FIGHTS_URL="https://$(az containerapp ingress show \
--resource-group $RESOURCE_GROUP \
--name $FIGHTS_APP \
--output json | jq -r .fqdn)"
}
create_ui_app() {
echo "Creating Super Heroes UI Container App"
az containerapp create \
--resource-group "$RESOURCE_GROUP" \
--tags system="$TAG_SYSTEM" application="$UI_APP" \
--image "$UI_IMAGE" \
--name "$UI_APP" \
--environment "$CONTAINERAPPS_ENVIRONMENT" \
--ingress external \
--target-port 8080 \
--env-vars API_BASE_URL="$FIGHTS_URL"
echo "Getting URL to Super Heroes UI app"
UI_URL="https://$(az containerapp ingress show \
--resource-group $RESOURCE_GROUP \
--name $UI_APP \
--output json | jq -r .fqdn)"
}
create_azure_openai_resources() {
./create-azure-openai-resources.sh \
-c "$COGNITIVE_SERVICE_NAME" \
-d "$COGNITIVE_SERVICE_DEPLOYMENT_NAME" \
-g "$RESOURCE_GROUP" \
-l "$LOCATION" \
-t "$TAG_SYSTEM" \
-u "$UNIQUE_IDENTIFIER"
echo
AZURE_OPENAI_KEY=$(
az cognitiveservices account keys list \
--name "$NARRATION_COGNITIVE_SERVICE" \
--resource-group "$RESOURCE_GROUP" \
| jq -r .key1
)
}
# Define defaults
RESOURCE_GROUP="super-heroes"
LOCATION="eastus2"
IMAGES_TAG="java17-latest"
UNIQUE_IDENTIFIER=$(whoami)
POSTGRES_SKU="B1ms"
POSTGRES_TIER="Burstable"
MARIADB_SKU="$POSTGRES_SKU"
MARIADB_TIER="$POSTGRES_TIER"
CREATE_CONTAINER_REGISTRY=false
CREATE_AZURE_OPENAI_RESOURCES=false
# Process the input options
while getopts "ag:hl:p:rs:t:u:" option; do
case $option in
a) CREATE_AZURE_OPENAI_RESOURCES=true
;;
g) RESOURCE_GROUP=$OPTARG
;;
h) help
exit
;;
l) LOCATION=$OPTARG
;;
p) POSTGRES_TIER=$OPTARG
;;
r) CREATE_CONTAINER_REGISTRY=true
;;
s) POSTGRES_SKU=$OPTARG
;;
t) IMAGES_TAG=$OPTARG
;;
u) UNIQUE_IDENTIFIER=$OPTARG
;;
*) exit_abnormal
;;
esac
done
# Define variables
# Other
TEMP_DIR=$(mktemp -d)
GITHUB_RAW_BASE_URL="https://raw.githubusercontent.com/quarkusio/quarkus-super-heroes/main"
SUPERHEROES_IMAGES_BASE="quay.io/quarkus-super-heroes"
TAG_SYSTEM=quarkus-super-heroes
# Container registry
CONTAINER_REGISTRY_NAME="superheroes${UNIQUE_IDENTIFIER}"
# Container Apps
LOG_ANALYTICS_WORKSPACE="super-heroes-logs"
CONTAINERAPPS_ENVIRONMENT="super-heroes-env"
# Postgres
POSTGRES_DB_ADMIN="superheroesadmin"
POSTGRES_DB_PWD="p@ssw0rd-12046"
POSTGRES_DB_VERSION=14
# MariaDB
MARIADB_ADMIN_USER="$POSTGRES_DB_ADMIN"
MARIADB_ADMIN_PWD="$POSTGRES_DB_PWD"
MARIADB_VERSION="5.7"
# MongoDB
MONGO_DB="fights-db-$UNIQUE_IDENTIFIER"
MONGO_DB_VERSION="4.2"
# Kafka
KAFKA_NAMESPACE="fights-kafka-$UNIQUE_IDENTIFIER"
KAFKA_TOPIC="fights"
KAFKA_BOOTSTRAP_SERVERS="$KAFKA_NAMESPACE.servicebus.windows.net:9093"
# Apicurio
APICURIO_APP="apicurio"
APICURIO_IMAGE="apicurio/apicurio-registry-mem:2.4.2.Final"
# Narration
NARRATION_APP="rest-narration"
NARRATION_IMAGE="${SUPERHEROES_IMAGES_BASE}/${NARRATION_APP}:${IMAGES_TAG}"
COGNITIVE_SERVICE_NAME="cs-super-heroes"
COGNITIVE_SERVICE_DEPLOYMENT_NAME="csdeploy-super-heroes"
NARRATION_COGNITIVE_SERVICE="$COGNITIVE_SERVICE_NAME-$UNIQUE_IDENTIFIER"
NARRATION_COGNITIVE_SERVICE_DEPLOYMENT_NAME="$COGNITIVE_SERVICE_DEPLOYMENT_NAME-$UNIQUE_IDENTIFIER"
# Location
LOCATIONS_APP="grpc-locations"
LOCATIONS_DB="locations-db-$UNIQUE_IDENTIFIER"
LOCATIONS_IMAGE="${SUPERHEROES_IMAGES_BASE}/${LOCATIONS_APP}:${IMAGES_TAG}"
LOCATIONS_DB_SCHEMA="locations"
LOCATIONS_DB_SQL="$GITHUB_RAW_BASE_URL/$LOCATIONS_APP/deploy/db-init/initialize-tables.sql"
LOCATIONS_DB_CONNECT_STRING="jdbc:mariadb://${LOCATIONS_DB}.mysql.database.azure.com:3306/${LOCATIONS_DB_SCHEMA}?sslmode=trust&useMysqlMetadata=true"
# Heroes
HEROES_APP="rest-heroes"
HEROES_DB="heroes-db-$UNIQUE_IDENTIFIER"
HEROES_IMAGE="${SUPERHEROES_IMAGES_BASE}/${HEROES_APP}:${IMAGES_TAG}"
HEROES_DB_SCHEMA="heroes"
HEROES_DB_SQL="$GITHUB_RAW_BASE_URL/$HEROES_APP/deploy/db-init/initialize-tables.sql"
HEROES_DB_CONNECT_STRING="postgresql://${HEROES_DB}.postgres.database.azure.com:5432/${HEROES_DB_SCHEMA}?ssl=true&sslmode=require"
# Villains
VILLAINS_APP="rest-villains"
VILLAINS_DB="villains-db-$UNIQUE_IDENTIFIER"
VILLAINS_IMAGE="${SUPERHEROES_IMAGES_BASE}/${VILLAINS_APP}:${IMAGES_TAG}"
VILLAINS_DB_SCHEMA="villains"
VILLAINS_DB_SQL="$GITHUB_RAW_BASE_URL/$VILLAINS_APP/deploy/db-init/initialize-tables.sql"
VILLAINS_DB_CONNECT_STRING="jdbc:postgresql://${VILLAINS_DB}.postgres.database.azure.com:5432/${VILLAINS_DB_SCHEMA}?ssl=true&sslmode=require"
# Fights
FIGHTS_APP="rest-fights"
FIGHTS_DB_SCHEMA="fights"
FIGHTS_IMAGE="${SUPERHEROES_IMAGES_BASE}/${FIGHTS_APP}:${IMAGES_TAG}"
# Statistics
STATISTICS_APP="event-statistics"
STATISTICS_IMAGE="${SUPERHEROES_IMAGES_BASE}/${STATISTICS_APP}:${IMAGES_TAG}"
# UI
UI_APP="ui-super-heroes"
UI_IMAGE="${SUPERHEROES_IMAGES_BASE}/${UI_APP}:${IMAGES_TAG}"
# Now run the script
echo "Deploying Quarkus Superheroes to Azure Container Apps with the following configuration:"
echo " Resource Group: $RESOURCE_GROUP"
echo " Location: $LOCATION"
echo " Container image tag: $IMAGES_TAG"
echo " Unique identifier: $UNIQUE_IDENTIFIER"
echo " PostgreSQL/MySQL SKU: $POSTGRES_SKU"
echo " PostgreSQL/MySQL Tier: $POSTGRES_TIER"
echo
echo "Please be patient. This may take a while."
echo
# Install the required extensions
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Installing required Azure CLI extensions"
echo "-----------------------------------------"
az extension add --name containerapp
az extension add --name rdbms-connect
az extension add --name log-analytics
echo
# Register the Microsoft.App namespace
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Registering the Microsoft.App namespace"
echo "-----------------------------------------"
az provider register --namespace Microsoft.App --wait
echo
# Register the Microsoft.OperationalInsights provider
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Registering the Microsoft.OperationalInsights provider"
echo "-----------------------------------------"
az provider register --namespace Microsoft.OperationalInsights --wait
echo
# Create resource group
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $RESOURCE_GROUP resource group in the $LOCATION location"
echo "-----------------------------------------"
az group create \
--name "$RESOURCE_GROUP" \
--location "$LOCATION" \
--tags system="$TAG_SYSTEM"
echo
# Create Container registry (if needed)
if "$CREATE_CONTAINER_REGISTRY"; then
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $CONTAINER_REGISTRY_NAME container registry"
echo "-----------------------------------------"
create_container_registry
fi
# Create the Azure OpenAI resources (if needed)
if "$CREATE_AZURE_OPENAI_RESOURCES"; then
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the Azure OpenAI resources"
echo "-----------------------------------------"
create_azure_openai_resources
fi
# Create the Heroes Postgres db
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $HEROES_DB PostgreSQL database"
echo "-----------------------------------------"
create_postgres_db "$HEROES_APP" "$HEROES_DB" "$HEROES_DB_SCHEMA" "$HEROES_DB_SQL"
echo
# Create the Villains Postgres db
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $VILLAINS_DB PostgreSQL database"
echo "-----------------------------------------"
create_postgres_db "$VILLAINS_APP" "$VILLAINS_DB" "$VILLAINS_DB_SCHEMA" "$VILLAINS_DB_SQL"
echo
# Create the Locations MariaDB db
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $LOCATIONS_DB MariaDB database"
echo "-----------------------------------------"
create_maria_db "$LOCATIONS_APP" "$LOCATIONS_DB" "$LOCATIONS_DB_SCHEMA" "$LOCATIONS_DB_SQL"
echo
# Create the Fights MongoDB db
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $MONGO_DB MongoDB database"
echo "-----------------------------------------"
create_mongo_db "$MONGO_DB" "$FIGHTS_DB_SCHEMA"
MONGO_COLLECTION_CONNECT_STRING=$(get_mongo_connect_string "$MONGO_DB")
echo
# Create the EventHub
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $KAFKA_NAMESPACE EventHub and the $KAFKA_TOPIC topic"
echo "-----------------------------------------"
create_eventhub
KAFKA_CONNECTION_STRING=$(get_eventhub_connect_string)
JAAS_CONFIG='org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="'
KAFKA_JAAS_CONFIG="${JAAS_CONFIG}${KAFKA_CONNECTION_STRING}\";"
echo
# Create a Log Analytics workspace
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $LOG_ANALYTICS_WORKSPACE Log Analytics workspace"
echo "-----------------------------------------"
az monitor log-analytics workspace create \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--tags system="$TAG_SYSTEM" \
--workspace-name "$LOG_ANALYTICS_WORKSPACE"
echo
# Retrieve the Log Analytics Client ID & Secret
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Retrieving the Log Analytics Client ID and secret"
echo "-----------------------------------------"
LOG_ANALYTICS_WORKSPACE_CLIENT_ID=$(az monitor log-analytics workspace show \
--resource-group "$RESOURCE_GROUP" \
--workspace-name "$LOG_ANALYTICS_WORKSPACE" \
--query customerId \
--output tsv | tr -d '[:space:]')
LOG_ANALYTICS_WORKSPACE_CLIENT_SECRET=$(az monitor log-analytics workspace get-shared-keys \
--resource-group "$RESOURCE_GROUP" \
--workspace-name "$LOG_ANALYTICS_WORKSPACE" \
--query primarySharedKey \
--output tsv | tr -d '[:space:]')
echo
# Create the Container Apps environment
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $CONTAINERAPPS_ENVIRONMENT Container Apps environment"
echo "-----------------------------------------"
az containerapp env create \
--resource-group "$RESOURCE_GROUP" \
--location "$LOCATION" \
--tags system="$TAG_SYSTEM" \
--name "$CONTAINERAPPS_ENVIRONMENT" \
--logs-workspace-id "$LOG_ANALYTICS_WORKSPACE_CLIENT_ID" \
--logs-workspace-key "$LOG_ANALYTICS_WORKSPACE_CLIENT_SECRET"
echo
# Create Apicurio
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $APICURIO_APP Container App"
echo "-----------------------------------------"
create_apicurio
echo
# Create heroes
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $HEROES_APP Container App"
echo "-----------------------------------------"
create_heroes_app
echo
# Create villains
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $VILLAINS_APP Container App"
echo "-----------------------------------------"
create_villains_app
echo
# Create locations
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $LOCATIONS_APP Container App"
echo "-----------------------------------------"
create_locations_app
echo
# Create narration
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $NARRATION_APP Container App"
echo "-----------------------------------------"
create_narration_app
echo
# Create statistics
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $STATISTICS_APP Container App"
echo "-----------------------------------------"
create_statistics_app
echo
# Create fights
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $FIGHTS_APP Container App"
echo "-----------------------------------------"
create_fights_app
echo
# Create UI
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Creating the $UI_APP Container App"
echo "-----------------------------------------"
create_ui_app
echo
cleanup
echo
echo "Deployment took $SECONDS seconds to complete."
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: All services have been deployed"
echo "-----------------------------------------"
echo " Super Heroes UI: $UI_URL"
echo " Event stats: $STATISTICS_URL"
echo " Fights URL: $FIGHTS_URL"
echo " Heroes URL: $HEROES_URL"
echo " Villains URL: $VILLAINS_URL"
echo " Narration URL: $NARRATION_URL"
echo " Locations URL: grpc://$LOCATIONS_HOST:443"
echo " Apicurio Schema Registry: $APICURIO_URL"
if "$CREATE_CONTAINER_REGISTRY"; then
echo " Container Registry URL: $CONTAINER_REGISTRY_URL"
fi
echo