Repository navigation
Expand file tree
/
Copy pathupdate-gateway.sh
More file actions
executable file
·75 lines (64 loc) · 1.81 KB
/
Copy pathupdate-gateway.sh
File metadata and controls
executable file
·75 lines (64 loc) · 1.81 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Exit if any command fails
set -e
# Locate swagger.yaml spec
SPEC_PATH="./rest/docs/swagger.yaml"
if [ ! -f "$SPEC_PATH" ]; then
if [ -f "./docs/swagger.yaml" ]; then
SPEC_PATH="./docs/swagger.yaml"
else
echo "ERROR! Could not find config file at path './rest/docs/swagger.yaml' or './docs/swagger.yaml'!"
exit 1
fi
fi
# Determine the current git branch
BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Set API, config, and gateway names based on the branch
if [ "$BRANCH" == "master" ]; then
API_NAME="nebula-api"
CONFIG_NAME="prod-config"
GATEWAY_NAME="api-gateway"
else
API_NAME="dev-nebula-api"
CONFIG_NAME="dev-config"
GATEWAY_NAME="dev-gateway"
fi
# Create temp config
echo "Creating temp config."
gcloud api-gateway api-configs create "${CONFIG_NAME}-temp" \
--api="${API_NAME}" \
--openapi-spec="${SPEC_PATH}" \
--display-name="${CONFIG_NAME}-temp" \
--quiet
# Migrate to temp config
echo "Migrating to temp config."
gcloud api-gateway gateways update "${GATEWAY_NAME}" \
--location=us-central1 \
--api="${API_NAME}" \
--api-config="${CONFIG_NAME}-temp" \
--quiet
# Delete old config
echo "Deleting old config."
gcloud api-gateway api-configs delete "${CONFIG_NAME}" \
--api="${API_NAME}" \
--quiet
# Create new config
echo "Creating new config."
gcloud api-gateway api-configs create "${CONFIG_NAME}" \
--api="${API_NAME}" \
--openapi-spec="${SPEC_PATH}" \
--display-name="${CONFIG_NAME}" \
--quiet
# Migrate to new config
echo "Migrating to new config."
gcloud api-gateway gateways update "${GATEWAY_NAME}" \
--location=us-central1 \
--api="${API_NAME}" \
--api-config="${CONFIG_NAME}" \
--quiet
# Delete temp config
echo "Deleting temp config."
gcloud api-gateway api-configs delete "${CONFIG_NAME}-temp" \
--api="${API_NAME}" \
--quiet
echo "Done!"