forked from OpenMined/PySyft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev_tools.sh
executable file
·38 lines (35 loc) · 1.32 KB
/
dev_tools.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
#!/bin/bash
unameOut="$(uname -rs)"
case "${unameOut}" in
# WSL
Linux*Microsoft*WSL) command="echo";;
# Win Git Bash
CYGWIN*|MINGW*|MSYS*) command="start";;
# Linux + flavors
Linux*) command="xdg-open";;
# macOS
Darwin*) command="open";;
*) command="echo UNKNOWN OS: ${unameOut} | "
esac
function docker_list_exposed_ports() {
FILTER=$1
echo "-----------------------------"
echo "Containers | Exposed Ports"
echo "-----------------------------"
docker ps --format '{{.Names}}' | grep $FILTER | xargs docker inspect --format='{{.Name}} {{range $port, $portMap := .NetworkSettings.Ports}}{{if $portMap }}{{(index $portMap 0).HostPort}} {{end}}{{end}}'
}
if [[ -z "$1" ]]; then
# list db, redis, rabbitmq, and seaweedfs ports
docker_list_exposed_ports "db\|redis\|queue\|seaweedfs\|jaeger\|mongo"
else
PORT=$1
if docker ps | grep ":${PORT}" | grep -q 'redis'; then
${command} redis://127.0.0.1:${PORT}
elif docker ps | grep ":${PORT}" | grep -q 'postgres'; then
${command} postgresql://postgres:[email protected]:${PORT}/app
elif docker ps | grep ":${PORT}" | grep -q 'mongo'; then
${command} mongodb://root:[email protected]:${PORT}
else
${command} http://localhost:${PORT}
fi
fi