forked from vmware-archive/spring-boot-cities
-
Notifications
You must be signed in to change notification settings - Fork 5
/
firstTimeDeployToCloudRun.sh
executable file
·57 lines (47 loc) · 1.4 KB
/
firstTimeDeployToCloudRun.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
#!/bin/bash
set -e
PROJECTID=$(gcloud config get-value project)
#APIS="iam compute"
APIS="cloudbuild run"
REGION="europe-west1"
#Get app name - assume it is current directory name
APPNAME=${PWD##*/}
main() {
enableAPIS
gcloud config set run/platform managed
gcloud config set run/region $REGION
## Make sure code builds and tests pass
./gradlew build
#Build the container using Cloud Build
gcloud builds submit --tag gcr.io/${PROJECTID}/${APPNAME}
#Deploy it to Cloud Run
gcloud run deploy ${APPNAME}-service --image gcr.io/${PROJECTID}/${APPNAME} --platform managed --memory 512M --allow-unauthenticated
}
## Enable GCloud APIS
# This functions does the following
# - Grab the list of currently enabled API's in the project
# - Loop through the list of API's required in vars.txt
# - For each API
# - Check if it has been enabled already
# - Assuming it hasn't, then enable it
#
enableAPIS() {
ENABLED_APIS=$(gcloud services list --enabled | grep -v NAME | sort | cut -d " " -f1)
#echo "Current APIs enabled are: ${ENABLED_APIS}"
declare -a REQ_APIS=(${APIS})
for api in "${REQ_APIS[@]}"
do
EXISTS=$(echo ${ENABLED_APIS} | grep ${api} | wc -l)
if [ ${EXISTS} -eq 0 ]
then
echo "*** Enabling ${api} API"
gcloud services enable "${api}.googleapis.com"
sleep 2
fi
done
}
trap 'abort' 0
SECONDS=0
main
trap : 0
printf "\nComplete in ${SECONDS} seconds.\n"