microservices/docker-gitlink/deploy.sh

149 lines
3.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
server_name=$3
# 使用说明,用来提示输入参数
usage() {
echo -e "\e[91m错误必须传入环境和方法两个参数 \e[0m"
echo "Usage: sh deploy.sh [test|prod] [port|build_base|mysql|base|build_modules|modules|build_nginx|nginx|stop|rm]"
exit 1
}
# 开启所需端口
port(){
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=8080/tcp --permanent
firewall-cmd --add-port=8848/tcp --permanent
firewall-cmd --add-port=9848/tcp --permanent
firewall-cmd --add-port=9849/tcp --permanent
firewall-cmd --add-port=6379/tcp --permanent
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --add-port=9110/tcp --permanent
firewall-cmd --add-port=9112/tcp --permanent
firewall-cmd --add-port=9113/tcp --permanent
firewall-cmd --add-port=9114/tcp --permanent
firewall-cmd --add-port=9115/tcp --permanent
firewall-cmd --add-port=9116/tcp --permanent
service firewalld restart
}
mysql(){
docker-compose --compatibility up -d gitlink-mysql
}
# 编译基础环境(必须)
build_base(){
docker-compose build --no-cache gitlink-redis gitlink-nacos
}
# 启动基础环境(必须)
base(){
docker-compose --compatibility up -d gitlink-redis gitlink-nacos
}
# 编译程序模块(必须)
build_modules(){
if [ -z "$server_name" ]; then
docker-compose build --no-cache gitlink-gateway gitlink-auth gitlink-modules-system gitlink-modules-cms gitlink-modules-pms gitlink-modules-zone gitlink-modules-file
else
docker-compose build --no-cache "$server_name"
fi
}
# 启动程序模块(必须)
modules(){
if [ -z "$server_name" ]; then
docker-compose --compatibility up -d gitlink-gateway gitlink-auth gitlink-modules-system gitlink-modules-cms gitlink-modules-pms gitlink-modules-zone gitlink-modules-file
else
docker-compose --compatibility up -d "$server_name"
fi
}
# 编译前端运行环境(必须)
build_nginx(){
docker-compose build --no-cache gitlink-nginx
}
# 启动前端运行环境(必须)
nginx(){
docker-compose --compatibility up -d gitlink-nginx
}
# 关闭所有环境/模块
stop(){
docker-compose stop
}
# 关闭所有环境/模块
stop_modules(){
if [ -z "$server_name" ]; then
docker-compose stop gitlink-gateway gitlink-auth gitlink-modules-system gitlink-modules-cms gitlink-modules-pms gitlink-modules-zone gitlink-modules-file
else
docker-compose stop "$server_name"
fi
}
# 删除所有环境/模块
rm(){
if [ -z "$server_name" ]; then
docker-compose rm
else
docker-compose rm -f "$server_name"
fi
}
# 根据输入参数,使用不同环境的配置文件
case "$1" in
"test")
# 获取测试环境配置文件中的安装信息
. ./test_config.profile
;;
"prod")
. ./prod_config.profile
;;
*)
usage
;;
esac
# 根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$2" in
"port")
port
;;
"mysql")
mysql
;;
"base")
base
;;
"build_base")
build_base
;;
"build_modules")
build_modules
;;
"modules")
modules
;;
"build_nginx")
build_nginx
;;
"nginx")
nginx
;;
"stop_modules")
stop_modules
;;
"stop")
stop
;;
"rm")
rm
;;
*)
usage
;;
esac