-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathnginx-dapi.sh
More file actions
executable file
·152 lines (133 loc) · 3.58 KB
/
nginx-dapi.sh
File metadata and controls
executable file
·152 lines (133 loc) · 3.58 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
#
# Usage
#
usage() {
BANNER="NGINX Declarative API - https://github.com/f5devcentral/NGINX-Declarative-API/\n\n
This script is used to deploy/undeploy NGINX Declarative API using docker-compose\n\n
=== Usage:\n\n
$0 [options]\n\n
=== Options:\n\n
-h\t\t\t\t- This help\n
-c [start|stop|build]\t\t- Deployment command\n
-m [full|dev]\t\t\t- Deployment mode: full (with webui container) or dev (backend only for local webui development) (default: full)\n
-a <port>\t\t\t- Custom port for NGINX Declarative API (default: 5000)\n
-w <port>\t\t\t- Custom port for Web UI (default: 3000, only for full mode)\n
-d <port>\t\t\t- Custom port for Developer Portal (default: 5001)\n
-r <port>\t\t\t- Custom port for Redis (default: 6379)\n\n
=== Examples:\n\n
Deploy NGINX Declarative API (full):\t\t$0 -c start\n
Deploy in dev mode (no webui container):\t$0 -c start -m dev\n
Deploy with custom Declarative API port:\t$0 -c start -a 8080\n
Deploy dev mode with custom ports:\t\t$0 -c start -m dev -a 8080 -d 8081 -r 6380\n
Deploy with custom Web UI port:\t\t$0 -c start -w 8080\n
Deploy with custom DevPortal port:\t\t$0 -c start -d 8081\n
Deploy with all custom ports:\t\t\t$0 -c start -a 8080 -w 8081 -d 8082 -r 6380\n
Remove NGINX Declarative API:\t\t\t$0 -c stop\n
Build docker images:\t\t\t\t$0 -c build\n
"
echo -e $BANNER 2>&1
exit 1
}
#
# NGINX Declarative API deployment
#
nginx_dapi_start() {
# Docker compose variables
USERNAME=`whoami`
export USERID=`id -u $USERNAME`
export USERGROUP=`id -g $USERNAME`
export DAPI_PORT=${DAPI_PORT:-5000}
export WEBUI_PORT=${WEBUI_PORT:-3000}
export DEVPORTAL_PORT=${DEVPORTAL_PORT:-5001}
export REDIS_PORT=${REDIS_PORT:-6379}
echo "-> Deploying NGINX Declarative API ($DEPLOY_MODE mode)"
echo " NGINX Declarative API port: $DAPI_PORT"
if [ "$DEPLOY_MODE" = "full" ]; then
echo " Web UI port: $WEBUI_PORT"
else
echo " Web UI: Run locally with 'cd ../../webui && npm run dev'"
fi
echo " Developer Portal port: $DEVPORTAL_PORT"
echo " Redis port: $REDIS_PORT"
COMPOSE_HTTP_TIMEOUT=240 docker-compose -p $PROJECT_NAME -f $DOCKER_COMPOSE_YAML up -d --remove-orphans
}
#
# NGINX Declarative API removal
#
nginx_dapi_stop() {
# Docker compose variables
USERNAME=`whoami`
export USERID=`id -u $USERNAME`
export USERGROUP=`id -g $USERNAME`
echo "-> Undeploying NGINX Declarative API"
COMPOSE_HTTP_TIMEOUT=240 docker-compose -p $PROJECT_NAME -f $DOCKER_COMPOSE_YAML down
}
#
# NGINX Declarative API image build
#
nginx_dapi_build() {
# Docker compose variables
USERNAME=`whoami`
export USERID=`id -u $USERNAME`
export USERGROUP=`id -g $USERNAME`
echo "-> Building NGINX Declarative API Docker images"
COMPOSE_HTTP_TIMEOUT=240 docker-compose -p $PROJECT_NAME -f $DOCKER_COMPOSE_YAML build
}
#
# Main
#
PROJECT_NAME="nginx-dapi"
DEPLOY_MODE="full"
while getopts 'hc:m:a:w:d:r:' OPTION
do
case "$OPTION" in
h)
usage
;;
c)
ACTION=$OPTARG
;;
m)
DEPLOY_MODE=$OPTARG
;;
a)
DAPI_PORT=$OPTARG
;;
w)
WEBUI_PORT=$OPTARG
;;
d)
DEVPORTAL_PORT=$OPTARG
;;
r)
REDIS_PORT=$OPTARG
;;
esac
done
# Set docker-compose file based on mode
if [ "$DEPLOY_MODE" = "dev" ]; then
DOCKER_COMPOSE_YAML="docker-compose.dev.yaml"
else
DOCKER_COMPOSE_YAML="docker-compose.yaml"
fi
if [ -z "${ACTION}" ] || [[ ! "${ACTION}" =~ ^(start|stop|build)$ ]]
then
usage
fi
if [[ ! "${DEPLOY_MODE}" =~ ^(full|dev)$ ]]
then
echo "Error: Invalid mode '${DEPLOY_MODE}'. Must be 'full' or 'dev'"
usage
fi
case "$ACTION" in
start)
nginx_dapi_start
;;
stop)
nginx_dapi_stop
;;
build)
nginx_dapi_build
;;
esac