-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·112 lines (97 loc) · 3.65 KB
/
deploy.sh
File metadata and controls
executable file
·112 lines (97 loc) · 3.65 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
#!/bin/bash
# Variables
PREFIX='local'
SUFFIX='test'
LOCATION='westeurope'
RESOURCE_GROUP_NAME="${PREFIX}-rg"
SERVICEBUS_NAMESPACE_NAME="${PREFIX}-sb-ns-${SUFFIX}"
SERVICEBUS_QUEUE_NAME="myqueue" # Queue name is hardcoded in the application properties
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Change the current directory to the script's directory
cd "$CURRENT_DIR" || exit
# Check if the resource group already exists
echo "Checking for resource group [$RESOURCE_GROUP_NAME]..."
az group show \
--name "$RESOURCE_GROUP_NAME" \
--only-show-errors &>/dev/null
if [[ $? != 0 ]]; then
echo "Resource group [$RESOURCE_GROUP_NAME] not found. Creating..."
az group create \
--name "$RESOURCE_GROUP_NAME" \
--location "$LOCATION" \
--only-show-errors 1>/dev/null
if [[ $? -eq 0 ]]; then
echo "Resource group [$RESOURCE_GROUP_NAME] created successfully."
else
echo "Failed to create resource group [$RESOURCE_GROUP_NAME]."
exit 1
fi
else
echo "Resource group [$RESOURCE_GROUP_NAME] already exists."
fi
# Check if the Service Bus namespace already exists
echo "Checking if [$SERVICEBUS_NAMESPACE_NAME] Service Bus namespace already exists in the [$RESOURCE_GROUP_NAME] resource group..."
az servicebus namespace show \
--name "$SERVICEBUS_NAMESPACE_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--only-show-errors &>/dev/null
if [[ $? != 0 ]]; then
echo "No [$SERVICEBUS_NAMESPACE_NAME] Service Bus namespace found. Creating..."
az servicebus namespace create \
--name "$SERVICEBUS_NAMESPACE_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--location "$LOCATION" \
--only-show-errors 1>/dev/null
if [[ $? -eq 0 ]]; then
echo "[$SERVICEBUS_NAMESPACE_NAME] Service Bus namespace created successfully."
else
echo "Failed to create [$SERVICEBUS_NAMESPACE_NAME] Service Bus namespace."
exit 1
fi
else
echo "[$SERVICEBUS_NAMESPACE_NAME] Service Bus namespace already exists."
fi
# Check if the Service Bus queue already exists
echo "Checking if [$SERVICEBUS_QUEUE_NAME] queue already exists in the [$SERVICEBUS_NAMESPACE_NAME] namespace..."
az servicebus queue show \
--resource-group "$RESOURCE_GROUP_NAME" \
--namespace-name "$SERVICEBUS_NAMESPACE_NAME" \
--name "$SERVICEBUS_QUEUE_NAME" \
--only-show-errors &>/dev/null
if [[ $? != 0 ]]; then
echo "No [$SERVICEBUS_QUEUE_NAME] queue found. Creating..."
az servicebus queue create \
--resource-group "$RESOURCE_GROUP_NAME" \
--namespace-name "$SERVICEBUS_NAMESPACE_NAME" \
--name "$SERVICEBUS_QUEUE_NAME" \
--only-show-errors 1>/dev/null
if [[ $? -eq 0 ]]; then
echo "[$SERVICEBUS_QUEUE_NAME] queue created successfully."
else
echo "Failed to create [$SERVICEBUS_QUEUE_NAME] queue."
exit 1
fi
else
echo "[$SERVICEBUS_QUEUE_NAME] queue already exists."
fi
# Retrieve the connection string for the Service Bus namespace
echo "Retrieving connection string for [$SERVICEBUS_NAMESPACE_NAME] Service Bus namespace..."
AZURE_SERVICEBUS_CONNECTION_STRING=$(az servicebus namespace authorization-rule keys list \
--resource-group "$RESOURCE_GROUP_NAME" \
--namespace-name "$SERVICEBUS_NAMESPACE_NAME" \
--name RootManageSharedAccessKey \
--query primaryConnectionString \
--output tsv)
if [[ $? -eq 0 ]] && [[ -n "$AZURE_SERVICEBUS_CONNECTION_STRING" ]]; then
export AZURE_SERVICEBUS_CONNECTION_STRING
echo "Connection string retrieved successfully."
else
echo "Failed to retrieve connection string."
exit 1
fi
# Start the Java application
echo "Starting Java application..."
cd "$CURRENT_DIR/../app" && mvn clean spring-boot:run
# Optionally tear down all resources (uncomment to enable)
# echo "Deleting resource group [$RESOURCE_GROUP_NAME]..."
# az group delete --name "$RESOURCE_GROUP_NAME" --yes