前端自动打包部署上线记录

思路:

1、从github上拉取代码到服务器指定目录(git clone 代码仓库地址),

2、进入到 服务器指定目录/仓库目录 执行依赖安装(例 npm install),

3、根据安装依赖的结果,成功则执行打包编译(例 npm run build),

4、根据编译结果,执行部署的操作(例 scp myfile username@192.168.1.100:/home

开坑:

在危险边缘试探~

一开始为了测试远程执行命令,做了比较简单的试探

直接把仓库先拷到服务器了,然后调接口用nodejs的exec去执行命令

这里踩了一个坑,就是exec()无法执行‘cd 目录名’的命令,原因如下

Yes, cd is not supported by exec. This is because exec spawns a child-process, and child-processes cannot change their parent's cwd. For example, exec('cd baz; myCommand'); would change the cwd for myCommand, but not for node.

然后找到了解决办法,要去看nodejs关于进程的文档

Each command is executed in a separate shell, so the first cd only affects that shell process which then terminates. If you want to run git in a particular directory, just have Node set the path for you:

exec('git status', {cwd: '/home/ubuntu/distro'}, /* ... */);

cwd (current working directory) is one of many options available for exec.


目前为止,已经弄明白如何进行代码拉取、打包编译、自动部署

但想要做一个完整的构建部署系统,还需要支持可查看的打包编译以及部署记录,需要可以回滚到之前的打包版本的功能云云

为了支持快速回滚,那么系统盘里应适当保存最近的打包(比如说三天以内),所以也要考虑压缩问题,解/压缩的过程中,也需要考虑到负责打包的机子内存的问题


原文地址:https://www.cnblogs.com/cheeseCatMiao/p/9856669.html