-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoby-compose.sh
executable file
·63 lines (58 loc) · 1.21 KB
/
moby-compose.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
#!/bin/bash
customPath=${!#}
# Check if the variable contains a directory path
if [ -d "$customPath" ]; then
dir=$customPath
else
dir="."
fi
function get_file(){
file=$(find $dir -maxdepth 1 -type f \( -name "docker-compose*.yml" -o -name "docker-compose*.json" -o -name "docker-compose*.yaml" \) | fzf)
if [ -z "$file" ]; then
echo "No docker-compose file found"
exit 1
fi
#check if docker-compose is installed
if ! [ -x "$(command -v docker-compose)" ]; then
echo "docker-compose is not installed"
exit 1
fi
}
if [ "$1" != "-h" ]; then
get_file
fi
flag=false
while getopts ":udbhl" opt; do
case $opt in
u)
docker-compose -f $file up -d
flag=true
;;
d)
docker-compose -f $file down
flag=true
;;
b)
docker-compose -f $file build
flag=true
;;
h)
echo "Usage: moby-compose.sh [-u] [-d] [-b]"
echo " -u: up"
echo " -d: down"
echo " -b: build"
flag=true
;;
l)
docker-compose -f $file logs --follow
flag=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
if [ "$flag" = false ]; then
docker-compose -f $file up -d
fi