-
Notifications
You must be signed in to change notification settings - Fork 111
/
backend_deployment.sh
64 lines (58 loc) · 1.58 KB
/
backend_deployment.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
#!/bin/bash
#
# Perform backend APIs deployment to Cloud Run
#
# Function to display usage and exit
usage() {
echo "Usage: $0 --project <your_project_id> --region <region> --sa <your_cloud_run_sa>"
exit 1 # Indicate an error
}
# Function to validate a parameter's value
validate_param() {
local param_name="$1"
local param_value="$2"
if [[ -z "$param_value" ]]; then
echo "Error: Parameter '$param_name' cannot be empty."
usage # Show usage and exit if the value is empty
fi
}
# Check if enough arguments are provided
if [[ $# -lt 6 ]]; then
echo "Error: Insufficient arguments."
usage
fi
# Parse and validate named parameters
while [[ $# -gt 0 ]]; do
case "$1" in
--project)
validate_param "$1" "$2"
project=$2
shift 2 # Move to the next parameter
;;
--region)
validate_param "$1" "$2"
region=$2
shift 2
;;
--sa)
validate_param "$1" "$2"
sa=$2
shift 2
;;
*)
echo "Error: Unknown parameter '$1'."
usage
;;
esac
done
# Deploys backend to Cloud Run using the provided region and service account
main(){
echo "Copying config.toml file"
cp output_config/config.toml ../backend_apis/app
cd ../backend_apis
echo "Deploying backend to cloud run"
gcloud run deploy genai-for-marketing-backend-apis --source . --project="$project" --region="$region" --service-account="$sa" --allow-unauthenticated
echo "Done"
}
# Deploy
main