mirror of
https://github.com/142vip/408CSFamily.git
synced 2026-04-14 02:09:56 +08:00
refactor(docs):添加自动化脚本,打通发版流程
- 建立底稿文件,移动异常md文档 - 新增脚本,打通发版流程 - 优化docker镜像源
This commit is contained in:
4
scripts/aliyun_hub_login.sh
Normal file
4
scripts/aliyun_hub_login.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
## 登录阿里云hub
|
||||
docker login --username=mmdapl registry.cn-hangzhou.aliyuncs.com
|
||||
59
scripts/build_image.sh
Normal file
59
scripts/build_image.sh
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
## 功能:本地前后端项目构建、打包镜像,上传docker仓库
|
||||
## 参考:https://blog.csdn.net/Dontla/article/details/125210694
|
||||
## 作者:Rong姐姐好可爱
|
||||
## 使用示例:bash xxx.sh 容器名称 版本号
|
||||
## - bash build_image.sh oauth_login 0.0.1
|
||||
##
|
||||
|
||||
|
||||
## 日志颜色定义
|
||||
readonly successLogger="\033[36m"
|
||||
readonly errorLogger="\033[1;31m"
|
||||
readonly warnLogger="\033[1;33m"
|
||||
## 定义时间
|
||||
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
## 项目名称
|
||||
readonly projectName="408CSFamily"
|
||||
## 版本号
|
||||
version=${1}
|
||||
|
||||
|
||||
prepare_check(){
|
||||
if test -z "${version}";then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 版本号不能为空。参考版本: 0.0.x"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
run(){
|
||||
echo -e "${successLogger}---------------- shell doc_book start ---------------- "
|
||||
docker build -t registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:"${projectName}_${version}" .
|
||||
echo -e "${successLogger}---------------- shell doc_book end ---------------- "
|
||||
push_docker_image
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
push_docker_image(){
|
||||
if [[ "$(docker images -q registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:"${projectName}_${version}" 2> /dev/null)" != "" ]];
|
||||
then
|
||||
## 推送
|
||||
docker push registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:"${projectName}_${version}"
|
||||
echo -e "${successLogger}---------------- 上传镜像成功,删除本地镜像 ---------------- "
|
||||
docker rmi registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:"${projectName}_${version}"
|
||||
else
|
||||
echo -e "${errorLogger}${currentTime}:镜像:registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:${projectName}_${version}不存在"
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
prepare_check
|
||||
|
||||
run
|
||||
|
||||
|
||||
108
scripts/docker_network.sh
Normal file
108
scripts/docker_network.sh
Normal file
@@ -0,0 +1,108 @@
|
||||
#!/bin/bash
|
||||
|
||||
## 功能:设置docker自定义network,并指定网关、IP范围
|
||||
## 参考:https://blog.csdn.net/Dontla/article/details/125210694
|
||||
## 作者:Rong姐姐好可爱
|
||||
## 使用示例:bash xxx.sh 容器名称 镜像地址
|
||||
##
|
||||
|
||||
|
||||
## 日志颜色定义
|
||||
readonly successLogger="\033[36m"
|
||||
readonly errorLogger="\033[1;31m"
|
||||
readonly warnLogger="\033[1;33m"
|
||||
## 定义时间
|
||||
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
operationName=${1}
|
||||
networkName=${2}
|
||||
|
||||
## 网络名称
|
||||
readonly defaultNetworkName="service_env_net"
|
||||
## 子网范围 [/24 子网掩码]
|
||||
readonly subnet="172.30.0.0/24"
|
||||
## 网关
|
||||
readonly gateway="172.30.0.1"
|
||||
|
||||
|
||||
prepare_check(){
|
||||
if test -z "$operationName"
|
||||
then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 操作类型不能为空。脚本执行eg: bash xxx.sh [ls/init/rm]"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
run(){
|
||||
if [ "$operationName" == "ls" ];then
|
||||
## 查看所有
|
||||
echo -e "${successLogger}---------------- shell ls start ---------------- "
|
||||
docker network ls
|
||||
echo -e "${successLogger}---------------- shell ls end ------------------ "
|
||||
exit 0;
|
||||
elif [ "$operationName" == "init" ]; then
|
||||
echo -e "${successLogger}---------------- shell init start ---------------- "
|
||||
## 初始化
|
||||
init_network
|
||||
echo -e "${successLogger}---------------- shell init start ---------------- "
|
||||
exit 0;
|
||||
elif [ "$operationName" == "rm" ]; then
|
||||
## 移除
|
||||
echo -e "${successLogger}---------------- shell rm start ---------------- "
|
||||
remove_network
|
||||
echo -e "${successLogger}---------------- shell rm start ---------------- "
|
||||
exit 0;
|
||||
else
|
||||
echo -e "${errorLogger}当前操作不支持,目前只支持:ls/init/rm"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
## 创建网络
|
||||
init_network(){
|
||||
## 查询network -w【全匹配】
|
||||
docker network ls | grep -w "${defaultNetworkName}"
|
||||
if [ $? -eq 0 ] ;then
|
||||
echo -e "${warnLogger}---------------- 容器:${defaultNetworkName} 已存在,无需创建 ---------------- "
|
||||
docker network ls
|
||||
exit ;
|
||||
else
|
||||
echo -e "${successLogger}---------------- 网络${networdefaultNetworkNamekName},现进行初始化 ---------------- "
|
||||
docker network ls
|
||||
docker network create \
|
||||
--subnet="${subnet}" \
|
||||
--gateway="${gateway}" \
|
||||
"${defaultNetworkName}"
|
||||
echo -e "${successLogger}---------------- 创建后 ---------------------"
|
||||
docker network ls
|
||||
docker netwrok inspect "${networkName}"
|
||||
fi
|
||||
}
|
||||
|
||||
## 删除网络
|
||||
remove_network(){
|
||||
if test -z "$networkName";then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 网络名称不能为空。脚本执行eg: bash xxx.sh rm 网络名称"
|
||||
exit 0
|
||||
fi
|
||||
## 判断是否存在 -w【全匹配】
|
||||
docker network ls | grep -w "${networkName}"
|
||||
if [ $? -eq 1 ] ;then
|
||||
echo -e "${errorLogger}${currentTime}:容器网络:${networkName} 不存在,删除无效 "
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
echo -e "${successLogger}----------------删除前---------------------"
|
||||
docker network ls
|
||||
docker network rm "${networkName}"
|
||||
echo -e "${successLogger}----------------删除后---------------------"
|
||||
docker network ls
|
||||
}
|
||||
|
||||
|
||||
prepare_check
|
||||
|
||||
run
|
||||
125
scripts/quick_deploy.bash
Normal file
125
scripts/quick_deploy.bash
Normal file
@@ -0,0 +1,125 @@
|
||||
#!/bin/bash
|
||||
|
||||
## 功能:清除容器,删除旧镜像,创建新的容器
|
||||
## 参考:https://blog.csdn.net/Dontla/article/details/125210694
|
||||
## 作者:Rong姐姐好可爱
|
||||
## 使用示例:bash xxx.sh 容器名称 镜像地址
|
||||
##
|
||||
|
||||
## 日志颜色定义
|
||||
readonly successLogger="\033[36m"
|
||||
readonly errorLogger="\033[1;31m"
|
||||
readonly warnLogger="\033[1;33m"
|
||||
## 定义时间
|
||||
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
## 定义参数
|
||||
containerName=${1}
|
||||
imageName=${2}
|
||||
|
||||
|
||||
|
||||
|
||||
## 参数检查
|
||||
prepare_check(){
|
||||
if test -z "${containerName}"
|
||||
then
|
||||
echo -e "${errorLogger}${currentTime}参数错误 容器名称不能为空。脚本执行eg: bash xxx.sh 容器名称 镜像地址"
|
||||
exit 0
|
||||
fi
|
||||
if test -z "${imageName}";then
|
||||
echo -e "${errorLogger}${currentTime}参数错误 镜像地址不能为空。脚本执行eg: bash xxx.sh 容器名称 镜像地址"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
## 判断容器存在即删除
|
||||
delete_container(){
|
||||
docker inspect "${containerName}" -f '{{.Name}}' > /dev/null
|
||||
if [ $? -eq 0 ] ;then
|
||||
echo -e "${warnLogger}${currentTime}容器:${containerName} 存在,现进行删除"
|
||||
docker rm -f "${containerName}"
|
||||
fi
|
||||
}
|
||||
|
||||
## 判断镜像存在,即删除
|
||||
delete_image(){
|
||||
if [[ "$(docker images -q "${imageName}" 2> /dev/null)" != "" ]];
|
||||
then
|
||||
echo -e "${warnLogger}${currentTime}镜像:${imageName}存在,现进行删除"
|
||||
docker rmi "${imageName}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
## 环境初始成功
|
||||
run(){
|
||||
if [ "$operationName" == "client_web" ];then
|
||||
## 查看所有
|
||||
deploy_client_web
|
||||
exit 0;
|
||||
elif [ "$operationName" == "oauth_login" ]; then
|
||||
deploy_oauth_login
|
||||
exit 0;
|
||||
elif [ "$operationName" == "server_api" ]; then
|
||||
deploy_server_api
|
||||
exit 0;
|
||||
else
|
||||
echo -e "${errorLogger}当前操作不支持,目前只支持:ls/init/rm"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
## 创建容器,进行部署
|
||||
deploy(){
|
||||
## 执行docker容器创建
|
||||
docker run -d --name="${containerName}" \
|
||||
-p 4000:4000 \
|
||||
--restart=always \
|
||||
"${imageName}"
|
||||
}
|
||||
|
||||
deploy_client_web(){
|
||||
echo -e "${successLogger}---------------- deploy client_web start ---------------- "
|
||||
|
||||
docker run -d --name oauth2-client \
|
||||
-p 8080:80 --network=tencent-net \
|
||||
--ip=172.22.0.10 \
|
||||
--restart=unless-stopped
|
||||
|
||||
echo -e "${successLogger}---------------- deploy client_web end ------------------ "
|
||||
}
|
||||
|
||||
deploy_oauth_login(){
|
||||
echo -e "${successLogger}---------------- deploy oauth_login start ---------------- "
|
||||
|
||||
docker run -d --name="${containerName}" \
|
||||
-p 4000:4000 \
|
||||
--restart=always \
|
||||
"${imageName}"
|
||||
|
||||
echo -e "${successLogger}---------------- deploy oauth_login end ------------------ "
|
||||
}
|
||||
|
||||
|
||||
deploy_server_api(){
|
||||
echo -e "${successLogger}---------------- deploy server_api start ---------------- "
|
||||
|
||||
docker run -d --name="${containerName}" \
|
||||
-p 4000:4000 \
|
||||
--restart=always \
|
||||
"${imageName}"
|
||||
|
||||
echo -e "${successLogger}---------------- deploy server_api end ------------------ "
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
prepare_check
|
||||
### 处理容器和镜像,更新初始化
|
||||
delete_container
|
||||
delete_image
|
||||
### 运行,镜像更新
|
||||
run
|
||||
|
||||
|
||||
Reference in New Issue
Block a user