Skip to content

Commit 5474059

Browse files
author
爱吃抹茶不吃茶
committed
feat: 修改部署脚本及配置
1 parent 38f214a commit 5474059

File tree

4 files changed

+56
-81
lines changed

4 files changed

+56
-81
lines changed

Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ LABEL author="【Github&公众号】:Rong姐姐好可爱" email="fairy@2925.co
55
RUN mkdir -p /apps
66
## 确定工作空间 /apps
77
WORKDIR /apps
8-
COPY . /apps
8+
COPY . .
99

1010
## 安装依赖
11-
RUN npm i pnpm@6 -g && pnpm i -D && npm run build
11+
RUN npm i pnpm@6 -g && pnpm i -D && pnpm build
1212

1313
# 设置部署镜像
14-
FROM registry.cn-hangzhou.aliyuncs.com/142vip/nginx:latest
14+
FROM registry.cn-hangzhou.aliyuncs.com/142vip/nginx:1.23.0-alpine
1515

1616
# 将dist文件中的内容复制到 /usr/share/nginx/html/ 这个目录下面 注意:--from参数
1717
COPY --from=build_base /apps/docs/.vuepress/dist/ /usr/share/nginx/html/
1818
## 配置文件
1919
COPY nginx.conf /etc/nginx/
20-
EXPOSE 7100
20+
21+
## 采用默认80端口
22+
#EXPOSE 7100
2123
#CMD ["nginx", "-g", "daemon off;"]

nginx.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ http {
1212
access_log off;
1313
keepalive_timeout 3000;
1414
server {
15-
listen 7100;
15+
listen 80;
1616
server_name localhost;
17-
# access_log /var/log/nginx/access.log main;
1817
error_log /var/log/nginx/error.log error;
1918
## 静态资源代理
2019
location / {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "0.0.1",
44
"description": "一本有趣的JavaScript合集",
55
"scripts": {
6-
"clean": "rm -rf node_modules",
6+
"clean": "find . -name \"node_modules\" -type d -exec rm -rf '{}' +",
77
"dev": "vuepress dev docs",
88
"build": "vuepress build docs",
9-
"ali": "bash scripts/build_image.sh $npm_package_version",
9+
"build-image": "bash scripts/build_image.sh $npm_package_version",
1010
"github": "bash scripts/deploy.bash github"
1111
},
1212
"devDependencies": {

scripts/deploy.bash

Lines changed: 47 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
## 定义时间
1414
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
1515
readonly repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book"
16-
readonly containerName="JavaScriptCollection"
1716
readonly networkName="service_env_net"
17+
1818
## 定义参数
19+
containerName="JavaScriptCollection"
1920
operationName=${1}
2021
version=${2}
2122

@@ -24,7 +25,7 @@ version=${2}
2425

2526
## 参数检查
2627
prepare_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
## - 一个参数,容器名称
3738
delete_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-
## - 一个参数,镜像地址
4747
delete_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
## 环境初始成功
6362
run(){
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-
140114
prepare_check
141115

142116
run

0 commit comments

Comments
 (0)