This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dostart
executable file
·95 lines (76 loc) · 1.88 KB
/
dostart
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
#!/bin/bash
function print_help() {
echo \
'Usage: dostart [OPTION]
Options:
-b, --build: Build or rebuild services. Can be combined with --up to build while starting.
> docker-compose build
-u, --up: Create and start containers. Can be combined with --logs to view logs after starting.
> docker-compose up -d
> docker-compose up -d --build
> docker-compose up -d && docker-compose logs -f -t
-d, --down: Stop and remove containers, networks.
> docker-compose down
-l, --logs: View output from containers.
> docker-compose logs -f -t
-h, --help: Print this message.
Examples:
=> To start the containers while also viewing the logs :
$ ./dostart --up --logs
--> Equivalent to :
$ ./dostart -u -l
------
=> To build the containers without starting them :
$ ./dostart --build
--> Equivalent to :
$ ./dostart -b'
}
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
-b | --build)
BUILD="--build"
shift # past argument
;;
-u | --up)
UP=true
DOWN=false
shift # past argument
;;
-d | --down)
UP=false
DOWN=true
shift # past argument
;;
-l | --logs)
LOGS=true
shift # past argument
;;
-h | --help)
print_help
shift # past argument
;;
-* | --*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
# Process Arguments
if [[ $UP == true ]]; then
docker-compose up -d ${BUILD}
if [[ $LOGS == true ]]; then
docker-compose logs -f -t
fi
elif [[ $BUILD ]]; then
docker-compose build
elif [[ $DOWN == true ]]; then
docker-compose down
elif [[ $LOGS == true ]]; then
docker-compose logs -f -t
fi