-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexpose.sh
executable file
·98 lines (85 loc) · 2.31 KB
/
expose.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
#!/bin/bash
######################################################################
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# SPDX-License-Identifier: MIT-0 #
######################################################################
source .env
function usage(){
echo ""
echo "Usage: $0 [service_name] [local_port_number] - expose a service locally through port forwarding"
echo ""
echo " service_name - name of service to expose (ui|grapdb), default: ui"
echo " local_port_number - local port number to forward to the service port, default: ${PM_UI_PORT_INT}"
echo ""
}
if [ "$1" == "--help" ]; then
usage
exit 0
fi
if [ "${QUIET}" == "true" ]; then
VERBOSE=false
fi
if [ "${DEBUG}" == "true" ]; then
set -x
fi
if [ ! "$TO" == "$PM_TO" ]; then
echo $PM_TO > wd/.to
source .env
fi
if [ "${VERBOSE}" == "true" ]; then
echo ""
echo "Executing command on orchestrator ${TO} ..."
fi
case "${TO}" in
"compose")
if [ "${COMPOSE_CONTEXT_TYPE}" == "moby" ]; then
echo ""
echo "Services are already exposed locally"
CMD="./status.sh"
elif [ "${COMPOSE_CONTEXT_TYPE}" == "ecs" ]; then
echo ""
echo "Expose of container running on ECS is not supported"
echo ""
else
echo ""
echo "Unrecognized COMPOSE_CONTEXT_TYPE ${COMPOSE_CONTEXT_TYPE}"
echo "Supported context types are moby | ecs"
fi
;;
"kubernetes")
SERVICE_NAME=$1
if [ "$1" == "" ]; then
SERVICE_NAME=ui
fi
SERVICE_PORT=$2
if [ "$2" == "" ]; then
SERVICE_PORT=$PM_UI_PORT_INT
fi
if [ "$SERVICE_NAME" == "graphdb" ]; then
SERVICE_PORT_INT=$PM_GRAPHDB_PORT_INT
elif [ "$SERVICE_NAME" == "ui" ]; then
SERVICE_PORT_INT=$PM_UI_PORT_INT
else
echo ""
echo "Unrecognized service name: $SERVICE_NAME"
echo ""
fi
CMD="kubectl port-forward $(kubectl get pods | grep ${SERVICE_NAME} | head -n 1 | tail -n 1 | cut -d ' ' -f 1 ) ${SERVICE_PORT}:${SERVICE_PORT_INT}"
;;
*)
echo ""
echo "Expose operation is not supported for target orchestrator ${TO}"
echo ""
usage
;;
esac
if [ "${VERBOSE}" == "true" ]; then
echo "${CMD}"
echo ""
fi
if [ "${DRY_RUN}" == "false" ]; then
eval "${CMD}"
fi
if [ "${DEBUG}" == "true" ]; then
set +x
fi