2022-02-20 13:27:51 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# only source if docker and docker_compose are installed
|
|
|
|
command -v docker >/dev/null 2>&1 || return
|
|
|
|
command -v docker-compose >/dev/null 2>&1 || return
|
|
|
|
|
|
|
|
function dkcmp () {
|
|
|
|
module_load path
|
|
|
|
local path
|
|
|
|
local dir
|
|
|
|
local ext
|
|
|
|
local cmd
|
|
|
|
local OPTIND
|
|
|
|
|
|
|
|
file="docker-compose"
|
|
|
|
dir=""
|
|
|
|
path=""
|
|
|
|
|
|
|
|
OPTIND=1
|
|
|
|
while getopts 'd:f:p:e:' OPTION; do
|
|
|
|
# echo $OPTION $OPTARG
|
|
|
|
case "$OPTION" in
|
|
|
|
f)
|
|
|
|
file=$OPTARG
|
|
|
|
;;
|
|
|
|
d)
|
|
|
|
dir=$OPTARG
|
|
|
|
echo setting directory
|
|
|
|
;;
|
|
|
|
e)
|
|
|
|
ext=$OPTARG
|
|
|
|
;;
|
|
|
|
p)
|
|
|
|
path=$OPTARG
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo unknown option $OPTION
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
echo directory $dir
|
|
|
|
[[ ! $path ]] && path=$dir/$file
|
|
|
|
echo $path
|
|
|
|
|
|
|
|
[[ $ext ]] && path=$path.$ext
|
|
|
|
if [[ ! -f $path ]];then
|
|
|
|
if [[ -f ${path}.yml ]];then
|
|
|
|
path=$path.yml
|
|
|
|
elif [[ -f ${path}.yaml ]];then
|
|
|
|
path=$path.yaml
|
|
|
|
else
|
|
|
|
echo no compose file at $path
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
2022-04-26 14:07:20 -07:00
|
|
|
path=$(abs_path $path)
|
2022-02-20 13:27:51 -08:00
|
|
|
echo compose: $path file exits, command to run $1
|
|
|
|
cmd="docker-compose -f $path"
|
|
|
|
case $1 in
|
|
|
|
s) ;&
|
|
|
|
start)
|
|
|
|
$cmd up -d
|
|
|
|
;;
|
|
|
|
stp) ;&
|
|
|
|
stop)
|
|
|
|
$cmd down
|
|
|
|
;;
|
|
|
|
rm) ;&
|
|
|
|
remove )
|
|
|
|
$cmd docker-compose rm -s -v
|
|
|
|
;;
|
|
|
|
rst) ;&
|
|
|
|
restart)
|
|
|
|
$cmd restart
|
|
|
|
;;
|
|
|
|
mk) ;&
|
|
|
|
make)
|
|
|
|
$cmd down
|
|
|
|
$cmd up -d --force-recreate
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "no command supplied (i.e. start,stop,remove restart,make)"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
return 0
|
|
|
|
}
|