-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
100 lines (82 loc) · 2.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
95
96
97
98
99
100
gcloud functions deploy test-ip \
--gen2 \
--runtime=python311 \
--region=asia-southeast1 \
--source=./ \
--entry-point=test_ip \
--trigger-http \
--allow-unauthenticated
gcloud functions deploy test-ip-2 \
--gen2 \
--runtime=python311 \
--region=asia-southeast1 \
--source=./ \
--entry-point=test_ip_2 \
--trigger-http \
--allow-unauthenticated
# Create VPC
gcloud services enable compute.googleapis.com
gcloud compute networks create my-vpc \
--subnet-mode=custom \
--bgp-routing-mode=regional
# Create a Serverless VPC Access connectors
gcloud services enable vpcaccess.googleapis.com
gcloud compute networks vpc-access connectors create functions-connector \
--network my-vpc \
--region asia-southeast1 \
--range 10.8.0.0/28
# Waiting for few minutes...
# Grant Permissions
export PROJECT_ID=$(gcloud config list --format 'value(core.project)')
export PROJECT_NUMBER=$(gcloud projects list --filter="$PROJECT_ID" --format="value(PROJECT_NUMBER)")
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:[email protected] \
--role=roles/viewer
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:[email protected] \
--role=roles/compute.networkUser
# Reserve static IP
gcloud compute addresses create two-functions-static-ip \
--region=asia-southeast1
gcloud compute addresses list
# NAME ADDRESS/RANGE TYPE PURPOSE NETWORK REGION SUBNET STATUS
# functions-static-ip 34.87.144.47 EXTERNAL asia-southeast1 RESERVED
# Creating the Cloud Router
gcloud compute routers create my-router \
--network my-vpc \
--region asia-southeast1
# Creating Cloud Nat
gcloud compute routers nats create my-cloud-nat-config \
--router=my-router \
--nat-external-ip-pool=functions-static-ip \
--nat-all-subnet-ip-ranges \
--enable-logging \
--router-region=asia-southeast1
# Update (In case that you want to update the Cloud Nat)
gcloud compute routers nats update my-cloud-nat-config \
--router=my-router \
--nat-external-ip-pool=functions-static-ip,two-functions-static-ip \
--nat-all-subnet-ip-ranges \
--enable-logging \
--router-region=asia-southeast1
# Test deploy
gcloud functions deploy test-ip \
--gen2 \
--runtime=python311 \
--region=asia-southeast1 \
--source=./ \
--entry-point=test_ip \
--trigger-http \
--allow-unauthenticated \
--vpc-connector functions-connector \
--egress-settings all
gcloud functions deploy test-ip-2 \
--gen2 \
--runtime=python311 \
--region=asia-southeast1 \
--source=./ \
--entry-point=test_ip_2 \
--trigger-http \
--allow-unauthenticated \
--vpc-connector functions-connector \
--egress-settings all