2018-05-10 11:08:49 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-05-11 23:49:02 +08:00
|
|
|
cd $(dirname $0)
|
2018-05-10 11:08:49 +08:00
|
|
|
cmd="$1"
|
|
|
|
[[ x$cmd == x ]] && cmd=start
|
|
|
|
|
|
|
|
eprint(){
|
|
|
|
echo -e "\033[0;37;41m $* \033[0m"
|
|
|
|
}
|
|
|
|
|
|
|
|
iprint(){
|
|
|
|
echo -e "\033[0;37;42m $* \033[0m"
|
|
|
|
}
|
|
|
|
|
|
|
|
check::dependency(){
|
|
|
|
which docker &> /dev/null || {
|
|
|
|
eprint 'Not found docker command!'
|
2018-05-18 12:22:53 +08:00
|
|
|
|
|
|
|
install::docker || {
|
|
|
|
eprint 'Failed to install docker!'
|
|
|
|
return 11
|
|
|
|
}
|
|
|
|
|
|
|
|
iprint 'successful install docker!'
|
|
|
|
return 0
|
2018-05-10 11:08:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
which docker-compose &> /dev/null || {
|
|
|
|
eprint 'Not found docker-compose command!'
|
2018-05-18 12:22:53 +08:00
|
|
|
|
|
|
|
install::docker-compose || {
|
|
|
|
eprint 'Failed to install docker-compose!'
|
|
|
|
return 13
|
|
|
|
}
|
|
|
|
|
|
|
|
iprint 'successful install docker-compose!'
|
|
|
|
return 0
|
2018-05-10 11:08:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:22:53 +08:00
|
|
|
install::docker(){
|
|
|
|
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo &&
|
|
|
|
yum install -y docker-ce &&
|
|
|
|
which docker &>/dev/null &&
|
|
|
|
systemctl start docker &&
|
|
|
|
systemctl enable docker
|
|
|
|
}
|
|
|
|
|
|
|
|
install::docker-compose(){
|
|
|
|
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
|
|
|
|
chmod +x /usr/local/bin/docker-compose
|
|
|
|
which docker-compose &>/dev/null
|
|
|
|
}
|
|
|
|
|
2018-05-11 23:49:02 +08:00
|
|
|
import::image(){
|
|
|
|
find . -name '*.image.tar' | xargs -I LOADIMAGES docker load -i LOADIMAGES
|
|
|
|
}
|
|
|
|
|
|
|
|
gen::config(){
|
|
|
|
sed -i 's/""//g' docker-compose.yaml
|
|
|
|
sed -i "s|__GROUP_DIR__|$(pwd)|g" docker-compose.yaml
|
2018-05-17 16:10:44 +08:00
|
|
|
sed -i "s/\*\*None\*\*/$(uuidgen | tr -d -)/g" docker-compose.yaml
|
2018-05-11 23:49:02 +08:00
|
|
|
}
|
|
|
|
|
2018-05-10 11:08:49 +08:00
|
|
|
start(){
|
2018-05-11 23:49:02 +08:00
|
|
|
import::image
|
2018-05-10 11:08:49 +08:00
|
|
|
docker-compose -f docker-compose.yaml up -d
|
|
|
|
}
|
|
|
|
|
|
|
|
stop(){
|
2018-05-11 23:49:02 +08:00
|
|
|
docker-compose -f docker-compose.yaml down
|
2018-05-10 11:08:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
main(){
|
|
|
|
check::dependency || exit $?
|
2018-05-11 23:49:02 +08:00
|
|
|
gen::config
|
2018-05-10 11:08:49 +08:00
|
|
|
|
|
|
|
eval "$cmd"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main
|