22
33# # 功能:清除容器,删除旧镜像,创建新的容器
44# # 参考:https://blog.csdn.net/Dontla/article/details/125210694
5- # # 作者:Rong姐姐好可爱
5+ # # 作者:储凡
66# # 使用示例:bash xxx.sh 容器名称 镜像地址
77# #
88
@@ -13,9 +13,10 @@ readonly warnLogger="\033[1;33m"
1313# # 定义时间
1414readonly currentTime=$( date " +%Y-%m-%d %H:%M:%S" )
1515readonly repoAddress=" registry.cn-hangzhou.aliyuncs.com/142vip/doc_book"
16- readonly containerName=" JavaScriptCollection"
1716readonly networkName=" service_env_net"
17+
1818# # 定义参数
19+ containerName=" JavaScriptCollection"
1920operationName=${1}
2021version=${2}
2122
@@ -24,7 +25,7 @@ version=${2}
2425
2526# # 参数检查
2627prepare_check (){
27- if test -z " ${containerName } "
28+ if test -z " ${operationName } "
2829 then
2930 echo -e " ${errorLogger}${currentTime} :参数错误 部署平台不能为空."
3031 exit 0
@@ -35,108 +36,81 @@ prepare_check(){
3536# # 判断容器存在即删除
3637# # - 一个参数,容器名称
3738delete_container (){
38- docker inspect " ${1 } " -f ' {{.Name}}' > /dev/null
39+ docker inspect " ${containerName } " -f ' {{.Name}}' > /dev/null
3940 if [ $? -eq 0 ] ; then
40- echo -e " ${warnLogger}${currentTime} 容器:${1 } 存在,现进行删除"
41- docker rm -f " ${1 } "
41+ echo -e " ${warnLogger}${currentTime} 容器:${containerName } 存在,现进行删除"
42+ docker rm -f " ${containerName } "
4243 fi
4344}
4445
4546# # 判断镜像存在,即删除
46- # # - 一个参数,镜像地址
4747delete_image (){
4848 # # 判断版本号
4949 if test -z " ${version} " ; then
5050 echo -e " ${errorLogger}${currentTime} :参数错误 镜像版本号不能为空."
5151 exit 0
5252 fi
5353
54- if [[ " $( docker images -q " ${1 } " 2> /dev/null) " != " " ]];
54+ if [[ " $( docker images -q " ${repoAddress} : ${containerName} - ${version }" 2> /dev/null) " != " " ]];
5555 then
56- echo -e " ${warnLogger}${currentTime} 镜像:${1 } 存在,现进行删除"
57- docker rmi " ${1 } "
56+ echo -e " ${warnLogger}${currentTime} 镜像:${repoAddress} : ${containerName} - ${version } 存在,现进行删除"
57+ docker rmi " ${repoAddress} : ${containerName} - ${version }"
5858 fi
5959}
6060
61-
6261# # 环境初始成功
6362run (){
64- if [ " ${operationName} " == " gitee" ]; then
65- # # 查看所有
66- deploy_to_gitee
67- exit 0;
68- elif [ " ${operationName} " == " github" ]; then
69- deploy_to_github
70- exit 0;
71- elif [ " ${operationName} " == " ali" ]; then
72- # # 删除容器
73- delete_container " ${containerName} "
74- # # 删除镜像
75- delete_image " ${repoAddress} :${containerName} _${version} "
76- # # 部署
77- deploy_to_ali
78- exit 0;
63+ if [ " ${operationName} " == " 408" ]; then
64+ containerName=" 408CSFamily"
65+ delete_container
66+ delete_image
67+ deploy_408CSFamily
68+ exit 0
69+ elif [ " ${operationName} " == " jsc" ]; then
70+ delete_container
71+ delete_image
72+ deploy_JavaScriptCollection
73+ exit 0
7974 else
80- echo -e " ${errorLogger}${currentTime} 当前操作不支持,目前只支持:ali/gitee/github "
75+ echo -e " ${errorLogger}${currentTime} 当前操作不支持,目前只支持:408/jsc "
8176 exit 0
8277 fi
78+ exit 0
8379}
8480
81+ # # 部署408CSFamily
82+ deploy_408CSFamily (){
83+ echo -e " ${successLogger} ---------------- deploy ${containerName} ali start ---------------- "
8584
86- # # 部署到阿里服务器
87- deploy_to_ali (){
88- echo -e " ${successLogger} ---------------- deploy ${containerName} ali start ---------------- "
89-
90- docker run -d --name " ${containerName} " \
91- -p 7100:7100 \
92- --network=" ${networkName} " \
93- --restart=unless-stopped \
94- --ip=172.30.0.100 \
95- " ${repoAddress} :${containerName} _${version} "
85+ docker run -d --name " ${containerName} " \
86+ -p 0.0.0.0:7000:80 \
87+ --network=" ${networkName} " \
88+ --restart=unless-stopped \
89+ --ip=172.30.0.100 \
90+ " ${repoAddress} :${containerName} -${version} "
9691
97- echo -e " ${successLogger} ---------------- deploy ${containerName} ali end ------------------ "
98- docker ps
92+ echo -e " ${successLogger} ---------------- deploy ${containerName} ali end ------------------ "
93+ docker ps
94+ exit 0
9995}
10096
101- # # 部署到github静态资源托管
102- deploy_to_github (){
103- echo -e " ${successLogger} ---------------- deploy ${containerName} github start ---------------- "
104-
105- # 当命令以非零状态退出时,则退出shell
106- set -e
97+ # # 部署JavaScriptCollection
98+ deploy_JavaScriptCollection (){
99+ echo -e " ${successLogger} ---------------- deploy ${containerName} start ---------------- "
107100
108- # # 配置网站base
101+ docker run -d --name " ${containerName} " \
102+ -p 0.0.0.0:7200:80 \
103+ --network=" ${networkName} " \
104+ --restart=unless-stopped \
105+ --ip=172.30.0.200 \
106+ " ${repoAddress} :${containerName} -${version} "
109107
110- # 进入上级目录,并编译
111- npm run build && cd docs/.vuepress/dist
112- git init && git add --all
113- # # 如果没有输入commit信息,则采用默认
114- if [ " ${commitInfo} " -eq " " ]; then
115- commitInfo=" JavaScriptCollection Init"
116- fi
117- git commit -m " refactor:${commitInfo} "
118-
119- # # 配置个人信息
120- git config user.name " 喜欢吃芝士葡萄的妹妹"
121- git config user.email " fairy0115@2925.com"
122-
123- # if you are deploying to https://<USERNAME>.github.io
124- # git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master
125- # if you are deploying to https://<USERNAME>.github.io/<REPO>
126- git push -f https://github.com/mmdapl/JavaScriptCollection.git master:pages/github
127- cd -
128- echo -e " ${successLogger} ---------------- deploy ${containerName} github end ------------------ "
129- }
130-
131-
132- # # 部署到gitee静态资源托管
133- deploy_to_gitee (){
134- exit 0
108+ echo -e " ${successLogger} ---------------- deploy ${containerName} end ------------------ "
109+ docker ps
110+ exit 0
135111}
136112
137113
138-
139-
140114prepare_check
141115
142116run
0 commit comments