-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdozzle.sh
executable file
·70 lines (58 loc) · 1.56 KB
/
dozzle.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
#!/bin/bash
# Help
help() {
cat << EOF
Use: dozzle.sh [options]
Options:
-h Display this help dialog
-o Start Dozzle and open it in browser
-O Open Dozzle in browser
-s Stop dozzle
-w Watch log file
EOF
}
open_dozzle() {
# Check Dozzle
if [ -z "$(docker ps -q --filter name=dozzle)" ]; then
echo Dozzle is down
exit 1
fi
# TODO: open by OS
if [ $(uname) = "Darwin" ]; then
open $url
else
echo OS not yet supported, please manually open this url:
echo $url
fi
}
# Constants
url=http://localhost:9999
# SCRIPT EXECUTION
# Options
while getopts "hoOsw:" opt; do
case ${opt} in
h ) help; exit 2 ;;
o ) open=true ;;
O ) open_dozzle; exit 0 ;;
# Stop
s ) cd $(dirname "$0")
docker compose down dozzle
exit 0
;;
# Watch - alpine container tailing specified file
w ) basename=$(basename "$OPTARG")
echo "Enter a name for the container watching $OPTARG (Default: $basename)"
read container
[ -z $container ] && container=$basename
echo Starting container $container to watch $OPTARG
docker run -dth "$container" --name "$container" \
-v "$OPTARG:/log:ro" alpine \
sh -c "cat /log; tail -f /log"
;;
? ) help; exit 1 ;; # Wrong input
esac
done
shift "$((OPTIND-1))"
cd "$(dirname "$0")"
docker compose up -d dozzle
[ -z $open ] || open_dozzle