- 购买和配置云服务器
- 基于push tag 触发
- This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
- https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages">For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
- https://docs.github.com/cn/actions/getting-started-with-github-actions">github actions 中文文档 https://docs.github.com/cn/actions/getting-started-with-github-actions
- 回滚
- 用release-it 改造
- 查看发布是否成功
测试环境下,基于push dev 分支触发部署,这样简单方便,也不需要回滚。 线上环境,有上线,就要有回滚,否则无法闭环。
购买和配置云服务器
- 测试环境要求配置灵活,集成性高、一键部署,数据安全性要求不高,适合用Docker
- 线上环境要求稳定、高效、数据安全性高、适合用独立的数据库服务。
- 线上环境必须由Nginx来统一配置流量,记录日志。
所以线上和测试环境要分开,需要购买的服务:
- 域名
- 备案
- https
- 两台服务器:B端和C端
- 数据库
- mysql:需要配置允许访问IP白名单,由于本地IP地址经常变化,每次本地IP变化时,需要去更改下。
- monodb
- redis
-
基于push tag 触发
master分支可能会被频繁合并,但不能频繁上线,push tag可以作为上线正式的仪式
- 回滚时使用tag更加方便,否则就得在master分支去rever commit记录
```shell
This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
github actions 中文文档 https://docs.github.com/cn/actions/getting-started-with-github-actions
name: deploy production
on: push: tags:
- 'v*.*.*'
jobs: deploy: runs-on: ubuntu-latest
steps:- uses: actions/checkout@v2- name: Use Node.jsuses: actions/setup-node@v1with:node-version: 12 # 尽量和线上机 node 版本保持一直- name: lint and test # 测试run: |npm inpm run lintnpm run test:remote- name: set ssh key # 临时设置 ssh keyrun: |mkdir -p ~/.ssh/echo "${{secrets.WFP_ID_RSA}}" > ~/.ssh/id_rsa # secret 在这里配置 https://github.com/imooc-lego/biz-editor-server/settings/secretschmod 600 ~/.ssh/id_rsassh-keyscan "${{secrets.IP165}}" >> ~/.ssh/known_hosts- name: deploy # 部署run: ssh work@${{secrets.IP165}} "bash -s" < bin/deploy.sh ${{secrets.WFP_PASSWORD}} ${{github.ref}}- name: delete ssh key # 删除 ssh keyrun: rm -rf ~/.ssh/id_rsa
<a name="FoOXI"></a># 一键生成tag手动操作容易失误,必须被切换到master, 再push tag,所以要整合成一个命令,一键执行。<br />如下:`[npm version patch/minor/patch](https://docs.npmjs.com/cli/v8/commands/npm-version)`会自动帮我们进行版本升级还有推送tag<br />`.bak`后缀就是备份的意思,不用的代码,又不想删掉,就加这个后缀。```shell#!/bin/bash# 【说明】,手写 shell 升级版本提交 tag ,后来被 release-it 代替 - 2020.11.16# 切换到 master 分支git checkout master# 获取最新的 master 分支代码git pull origin master# npm version xxx 最后的类型,patch|minor|major 三选一version_type="patch" ## 默认为 patch# 执行命令传入了参数(参数数量 >= 1),如 `sh ./build/up-version.sh patch`if [ $# -eq 1 -o $# -gt 1 ]then## 参数值必须 patch|minor|major 三选一if [ $1 != "patch" -a $1 != "minor" -a $1 != "major" ]thenecho "参数值错误,必须 patch|minor|major 三选一"exit 1fiversion_type=$1## 对 major 和 minor 进行再次确认if [ $version_type = 'minor' -o $version_type = 'major' ]thenread -r -p "你确定要执行 npm version $version_type ? [Y/n] " inputcase $input in[yY][eE][sS]|[yY])echo "确认,继续执行";;[nN][oO]|[nN])echo "取消执行"exit 1;;*)echo "非法输出,取消执行"exit 1;;esacfifiecho "version_type: $version_type"# 升级 npm 版本并自动生成 git tagnpm version $version_type# push tags ,以触发 github actions 发布到 npmgit push origin --tags
回滚
重新执行对应relase版本的github actionss
用release-it 改造
查看发布是否成功
- 确认github actios 执行成功
- 登录服务器
- 查看代码文件和git tag
- 检查服务是否启动:
pm2 list、curl http://127.0.0.1:3000/api/db-check
