用脚手架快速部署前端项目
# 背景
- 最近做的
wdp-web
项目,一个git项目对应多个子项目(ambari-admin/ambari-web),跟之前的react项目部署方式有点不同,就暂时没用原来的过来的jks构建方式;现在考虑用脚手架实现一键部署临时过渡方案;其他相关项目类似操作; - 还有最近做的
ranger
项目;由于ranger管理端是jsp老项目,不能本地启动调试,每修改一次要通过其他第三方文件工具或者scp,进入服务器后还有做二次拷贝到docker容器中指定目录;期间拷贝效率有点低,还有再拷贝到容器中很麻烦啦;
# 特性
- 配置好json文件,直接通过命令行终端部署和下载服务器资源,支持执行本地和服务器远程shell命令,灵活配置;【推荐】
- 除了支持上传功能,还支持下载服务器资源功能;可代替
FileZilla
等第三方文件传输工具;
# 安装
sudo npm i -g bdp-cli --registry=http://172.21.64.25:7373 # bdp deploy 内网版本
# sudo npm i -g @samyzh/rat-cli # rat deploy 外网版本
1
2
2
# 配置文件
初始化配置:运行bdp init deploy
; 生成默认配置zdeploy.json
scp ./dist.zip root@10.45.xxx:/usr/lib/wdp-server/
[
{
"type": "upload",
"name": "开发环境",
"host": "127.0.0.1",
"port": "22",
"username": "",
"password": "",
"localCmd": "npm run build && zip -r dist.zip dist/",
"serverCmd": "cd /home/deploy/fe-deploy/ && mv dist/ dist-bak/",
"localScp": "dist.zip",
"serverScp": "/home/deploy/fe-deploy/dist.zip",
"serverHookCmd": "cd /home/deploy/fe-deploy/ && unzip dist.zip",
"localHookCmd": ""
},
{
"type": "download",
"name": "生产环境",
"host": "127.0.0.2",
"port": "2222",
"username": "deploy",
"password": "xxx",
"localCmd": "zip -r dist.zip dist/ && mv dist.zip dist-bak.zip",
"serverCmd": "cd /home/deploy/fe-deploy/ && zip -r dist.zip dist/",
"localScp": "./",
"serverScp": "/home/deploy/fe-deploy/dist.zip",
"serverHookCmd": "",
"localHookCmd": "unzip dist.zip"
}
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
说明
- type :上传和下载两类;upload download;【默认upload】
- name :测试或者正式环境等;一定要唯一;
- host :主机ip;
- port :主机端口;【默认22】
- username :用户名; 可以不用填写,就会在终端提示输入;
- password : 密码; 可以不用填写,就会在终端提示输入;
- localCmd :本机操作命令;
- serverCmd : 服务器操作命令;
- localScp : 本机拷贝的资源地址;可以是目录或者直接文件;【默认dist目录】
- serverScp : 服务器拷贝的资源地址;可以是目录或者直接文件;
- serverHookCmd : 回调本机操作命令,type为upload时再执行scp后执行;
- localHookCmd :回调服务器操作命令,type为download时再执行scp后执行;
# 部署
# 原有传统的jks部署方案
参考用脚手架快速搭建现场文档及部署中的jks部署设置;
# 脚手架部署方案
# 普通部署
ranger项目老系统:jsp前后端没有分离的项目;
由于ranger管理端是jsp老项目,不能本地启动调试,每修改一次要通过其他第三方文件工具或者scp拷贝效率有点低,进入服务器后还有做二次拷贝到容器中; 现在优化了下bdp-cli脚手架,配置好json文件,直接通过脚手架可直接部署和下载服务器资源
1:进入待部署的项目;运行`bdp init deploy,再修改配置;
cd ranger/security-admin/src/main
bdp init deploy
✔ 部署配置zdeploy.json生成完成, 请修改正确的配置信息,再通过运行 bdp deploy 部署操作
1
2
3
2
3
2:修改配置,运行部署命令bdp deploy
[
{
"type": "upload",
"name": "开发环境",
"host": "10.45.47.xx",
"port": "11",
"username": "",
"password": "",
"localCmd": "rm -rf webapp.zip && zip -r webapp.zip webapp/",
"serverCmd": "cd /home/xx/fe-deploy/ && mv webapp.zip webapp-bak.zip/",
"localScp": "webapp.zip",
"serverScp": "/home/xx/fe-deploy/webapp.zip",
"serverHookCmd": "cd /home/xx/fe-deploy/ && rm -rf webapp/ && unzip webapp.zip && docker cp webapp/ install-wdp-server-test-2:/usr/wdp/1.0/ranger-admin/ews/",
"localHookCmd": ""
},
{
"type": "download",
"name": "生产环境",
"host": "10.45.47.xx",
"port": "11",
"username": "",
"password": "",
"localCmd": "zip -r webapp.zip webapp/ && mv -f webapp.zip webapp-bak.zip",
"serverCmd": "cd /home/xx/fe-deploy/ && zip -r webapp.zip webapp/",
"localScp": "./",
"serverScp": "/home/xx/fe-deploy/webapp.zip",
"serverHookCmd": "",
"localHookCmd": "ls"
}
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
datameta老系统:fish前后端没有分离的项目; 替换库中jar文件前端资源
本地前置优化处理脚本:
{
"type": "upload",
"name": "开发环境",
"host": "10.45.46.x x x",
"port": "22",
"username": "xx",
"password": "xxx",
"localCmd": "rm -rf dist.zip dist && mkdir -p dist/META-INF/resources && cp -R ZBDPWeb/src/main/webapp/* dist/META-INF/resources && zip -r dist.zip dist/META-INF/resources/",
"serverCmd": "cd /home/bdp/dm/ && mv dist/ dist-bak/",
"localScp": "dist.zip",
"serverScp": "/home/bdp/dm/dist.zip",
"serverHookCmd": "cd /home/bdp/dm/ && rm -rf dist/ META-INF/ && unzip dist.zip && cp -R dist/* ./ && jar uvf ZBDPWeb-5.0.jar META-INF/resources ",
"localHookCmd": "sudo sh restart.sh"
},
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 多目录部署(wdp项目)
在要部署的项目; 现在只需通过运行ambari-admin
,ambari-web
中创建zdeploy.js
, 并修改服务器相关配置;bdp init deploy
即可生成部署配置信息zdeploy.json
,再修改配置信息即可;项目目录下:
wdp-web/ambari-admin/main/resources/ui/admin-web
,wdp-web/ambari-web
; 可以优化的;const server = [ { id: "dev", name: "开发环境", host: "xxx", username: "xxx", password: "xxx", serverDir: "deploy/dev/", port: "22", localDir: "dist", }, ] module.exports = server
1
2
3
4
5
6
7
8
9
10
11
12
13修改.gitignore
文件,添加zdeploy.js
或者zdeploy.json
设置为忽略;node_modules .tmp dist zdeploy.js
1
2
3
4运行
bdp deploy
部署,或者添加到package.json
,快速启动npm run deploy
;"deploy": "gulp build && bdp deploy", "deploy": "brunch build && bdp deploy",
1
2
# 效果及演示
上次更新: 2023/11/17, 05:08:20