shell-host/docker/files/docker-compose.func

89 lines
1.4 KiB
Bash

#!/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
path=$(abs_path $path)
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
}