-
Notifications
You must be signed in to change notification settings - Fork 3
/
deploy.sh
executable file
·94 lines (78 loc) · 3.89 KB
/
deploy.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
#!/bin/bash
set -eoux pipefail
case "${1:-shared}" in
shared)
PATTERN=shared
;;
sidecar)
PATTERN=sidecar
;;
*)
echo "usage: deploy.sh (shared|sidecar)"
exit 1
esac
# ---- init
REPO_ROOT=`git rev-parse --show-toplevel`
source <(cat $REPO_ROOT/.env)
RUNTIME=`echo $STACK | awk -F'-' '{print $1 "-" $2}'`
TARGET_INFRA_FOLDER=$REPO_ROOT/$INFRA_FOLDER
RESOURCE_GROUP_NAME=`terraform -chdir=$TARGET_INFRA_FOLDER output -json script_vars | jq -r .resource_group`
APP=express-dapr-ts
SERVICEBUS_NAMESPACE=`az resource list -g $RESOURCE_GROUP_NAME --resource-type Microsoft.ServiceBus/namespaces --query '[0].name' -o tsv`
SERVICEBUS_CONNECTION=`az servicebus namespace authorization-rule keys list -g $RESOURCE_GROUP_NAME --namespace-name $SERVICEBUS_NAMESPACE -n RootManageSharedAccessKey --query primaryConnectionString -o tsv`
STORAGE_NAME=`az resource list -g $RESOURCE_GROUP_NAME --resource-type Microsoft.Storage/storageAccounts --query '[0].name' -o tsv`
STORAGE_ACCOUNT_KEY=`az storage account keys list -g $RESOURCE_GROUP_NAME -n $STORAGE_NAME --query "[?permissions == 'FULL'] | [0].value" -o tsv `
AZURE_CONTAINER_REGISTRY_NAME=`az resource list -g $RESOURCE_GROUP_NAME --resource-type Microsoft.ContainerRegistry/registries --query '[0].name' -o tsv`
AZURE_CONTAINER_REGISTRY_ENDPOINT=`az acr show -n $AZURE_CONTAINER_REGISTRY_NAME --query loginServer -o tsv`
TAG=`az acr repository show-tags -n $AZURE_CONTAINER_REGISTRY_NAME --repository $APP --top 1 --orderby time_desc -o tsv`
IMAGE_NAME=$AZURE_CONTAINER_REGISTRY_ENDPOINT/$APP:$TAG
# ---- set connection strings as secrets
kubectl delete secret servicebus-secret --ignore-not-found
kubectl create secret generic servicebus-secret --from-literal=connectionString=$SERVICEBUS_CONNECTION
kubectl delete secret storage-secret --ignore-not-found
kubectl create secret generic storage-secret --from-literal=accountName=$STORAGE_NAME \
--from-literal=accountKey=$STORAGE_ACCOUNT_KEY
kubectl apply -f ./dapr-components.yml
if [[ "$STACK" =~ "-kn-" ]]; then
SVC_SUFFIX=.default.svc.cluster.local
cat ./workload-$RUNTIME-$PATTERN.yml | \
yq eval ".|=select(.metadata.name==\"distributor\")
.spec.template.spec.containers[0].image = \"$IMAGE_NAME\"" | \
yq eval ".|=select(.metadata.name==\"receiver-express\")
.spec.template.spec.containers[0].image = \"$IMAGE_NAME\"" | \
yq eval ".|=select(.metadata.name==\"receiver-standard\")
.spec.template.spec.containers[0].image = \"$IMAGE_NAME\"" | \
kubectl apply -f -
else
SVC_SUFFIX=-svc
cat ./workload-$RUNTIME-$PATTERN.yml | \
yq eval ".spec|=select(.selector.matchLabels.app==\"distributor\")
.template.spec.containers[0].image = \"$IMAGE_NAME\"" | \
yq eval ".spec|=select(.selector.matchLabels.app==\"receiver-express\")
.template.spec.containers[0].image = \"$IMAGE_NAME\"" | \
yq eval ".spec|=select(.selector.matchLabels.app==\"receiver-standard\")
.template.spec.containers[0].image = \"$IMAGE_NAME\"" | \
kubectl apply -f -
fi
DAPR_VERSION=$(helm get metadata dapr -n dapr-system -o yaml | yq -r .appVersion)
if [ $PATTERN = 'shared' ]; then
apps=("distributor" "receiver-express" "receiver-standard")
for app in "${apps[@]}"
do
echo "$app"
helm upgrade --install $app-dapr oci://registry-1.docker.io/daprio/dapr-shared-chart \
--set fullnameOverride=$app-dapr \
--set shared.strategy=deployment \
--set shared.scheduling.nodeSelector.agentpool=classic \
--set shared.deployment.replicas=10 \
--set shared.daprd.image.tag=$DAPR_VERSION \
--set shared.appId=$app \
--set shared.daprd.config=appconfig \
--set shared.remoteURL=$app$SVC_SUFFIX \
--set shared.remotePort=80 \
--set shared.controlPlane.placementServerAddress="''" \
--set shared.daprd.listenAddresses=0.0.0.0 \
--set shared.daprd.appHealth.enabled=true \
--set shared.daprd.appHealth.probeTimeout=1000
done
fi