-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpa_cf_gcs_event_deploy.sh
executable file
·58 lines (48 loc) · 1.91 KB
/
pa_cf_gcs_event_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
#!/bin/bash
# Check if gcloud command is available
if ! command -v gcloud &> /dev/null; then
echo "Error: gcloud command not found. Please install the Google Cloud SDK and ensure 'gcloud' is in your PATH."
exit 1
fi
# Check gcloud authentication
gcloud auth list &> /dev/null
if [ $? -ne 0 ]; then
echo "Error: Not authenticated to gcloud. Please authenticate using 'gcloud auth login' and ensure you have the necessary permissions."
exit 1
fi
# Prompt for the .env file to use
echo "Enter the path to the .env file to use (e.g. ./myenvfile.env):"
read ENV_FILE
# Check if the provided .env file exists and is readable
if [[ ! -f "$ENV_FILE" || ! -r "$ENV_FILE" ]]; then
echo "Error: .env file either does not exist or is not readable."
exit 1
fi
# Source the .env file
source $ENV_FILE
# Check if required variables are set
declare -a required_vars=("GEN2" "RUNTIME" "REGION" "SERVICE_ACCOUNT" "CLOUDFUNCTION" "SOURCE" "ENTRY_POINT" "TRIGGER_EVENT_FILTERS" "MEMORY" "TIMEOUT" "PROJECT_ID" "PUBLISH_TOPIC_NAME" "PUBLISH_SA" "TARGET_SCOPES" "SA_CREDENTIALS_SECRET_NAME" "CSV_PATTERN_REGEX")
unset_vars=()
for var in "${required_vars[@]}"; do
if [[ -z "${!var}" ]]; then
unset_vars+=("$var")
fi
done
if [ ${#unset_vars[@]} -ne 0 ]; then
echo "Error: Missing environment variables: ${unset_vars[@]}"
exit 1
fi
# Formulate the SET_ENV_VARS value
SET_ENV_VARS="PROJECT_ID=$PROJECT_ID,PUBLISH_TOPIC_NAME=$PUBLISH_TOPIC_NAME,PUBLISH_SA=$PUBLISH_SA,TARGET_SCOPES=$TARGET_SCOPES,SA_CREDENTIALS_SECRET_NAME=$SA_CREDENTIALS_SECRET_NAME,CSV_PATTERN_REGEX=$CSV_PATTERN_REGEX"
# Deploy the function
gcloud functions deploy $CLOUDFUNCTION \
--$GEN2 \
--runtime=$RUNTIME \
--region=$REGION \
--service-account=$SERVICE_ACCOUNT \
--source=$SOURCE \
--entry-point=$ENTRY_POINT \
--trigger-event-filters="$TRIGGER_EVENT_FILTERS" \
--memory=$MEMORY \
--timeout=$TIMEOUT \
--set-env-vars "$SET_ENV_VARS"