forked from HariSekhon/DevOps-Python-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·56 lines (49 loc) · 2.38 KB
/
deploy.sh
File metadata and controls
executable file
·56 lines (49 loc) · 2.38 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
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2020-10-16 10:12:26 +0100 (Fri, 16 Oct 2020)
#
# https://github.com/HariSekhon/DevOps-Python-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$srcdir"
# needed to define the $service_account further down
project="${CLOUDSDK_CORE_PROJECT:-$(gcloud config list --format="value(core.project)")}"
# Cloud Functions not available in all regions yet:
#
# https://cloud.google.com/functions/docs/locations
#
# gcloud functions deploy doesn't seem to infer CLOUDSDK_COMPUTE_REGION from environment
region="$(gcloud config list --format="value(compute.region)" 2>&1 || :)"
region="${CLOUDSDK_COMPUTE_REGION:-${region:-europe-west1}}"
name="cloud-sql-backups"
topic="cloud-sql-backups"
service_account="cloud-function-sql-backup@$project.iam.gserviceaccount.com"
# https://console.cloud.google.com/marketplace/product/google/vpcaccess.googleapis.com
# for serverless VPC access to resources using their Private IPs
# since we're only accessing the SQL Admin API we don't need this
#vpc_connector="cloud-sql-backups"
gcloud functions deploy "$name" --trigger-topic "$topic" \
--runtime python37 \
--entry-point main \
--service-account "$service_account" \
--region "$region" \
--memory 128MB \
--timeout 60
# may want multiple concurrent calls to different SQL instances at the same time
#
# also doesn't prevent:
#
# "Operation failed because another operation was already in progress."
#
#--max-instances 1 # this isn't good enough because it sets off an async API call, so successive calls can fail if called before that SQL Admin API export has finished
# --vpc-connector "$vpc_connector"