-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·66 lines (53 loc) · 1.87 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
#!/bin/bash
STAGE=$1
if [ $STAGE == "staging" ]
then
PROJECT="japan-grid-carbon-api-staging"
ENDPOINT="apitest.denkicarbon.jp"
SPECPATH="openapi-functions-staging.yaml"
elif [ $STAGE == "production" ]
then
PROJECT="japan-grid-carbon-api"
ENDPOINT="data.denkicarbon.jp"
SPECPATH="openapi-functions-production.yaml"
else
echo "No Stage Given"
exit 1
fi
echo ">> Deploying All to $STAGE with project: $PROJECT"
cd cloud_functions/
# Set Policy for Main API to Unauthenticated
gcloud functions set-iam-policy --region=us-central1 api policy.json
echo ">> Deploying Cloud Function"
sls deploy --stage $STAGE --id $PROJECT
echo ">> Deploying API Spec"
gcloud endpoints services deploy $SPECPATH --project $PROJECT
CONFIG_ID=$(gcloud endpoints configs list --service $ENDPOINT --project $PROJECT | grep -oP -m 1 '^\d\d\d\d-\d\d-\S+')
echo ">> Building ESP-v2 Image"
../gcloud_build_image -s $ENDPOINT -c $CONFIG_ID -p $PROJECT
BASE_IMAGE_NAME="gcr.io/endpoints-release/endpoints-runtime-serverless"
ESP_TAG="2"
echo "Determining fully-qualified ESP version for tag: ${ESP_TAG}"
ALL_TAGS=$(gcloud container images list-tags "${BASE_IMAGE_NAME}" \
--filter="tags~^${ESP_TAG}$" \
--format="value(tags)")
IFS=',' read -ra TAGS_ARRAY <<< "${ALL_TAGS}"
if [ ${#TAGS_ARRAY[@]} -eq 0 ]; then
error_exit "Did not find ESP version: ${ESP_TAG}"
fi;
# Find the tag with the longest length.
ESP_FULL_VERSION=""
for tag in "${TAGS_ARRAY[@]}"; do
if [ ${#tag} -gt ${#ESP_FULL_VERSION} ]; then
ESP_FULL_VERSION=${tag}
fi
done
echo "Building image for ESP version: ${ESP_FULL_VERSION}"
echo ">> Deploying ESP-v2 Image"
gcloud run deploy api \
--image="gcr.io/$PROJECT/endpoints-runtime-serverless:${ESP_FULL_VERSION}-$ENDPOINT-$CONFIG_ID" \
--set-env-vars=ESPv2_ARGS=--cors_preset=basic \
--allow-unauthenticated \
--platform managed \
--project=$PROJECT \
--region=us-central1