# 持续集成

# SSH 协议文件传输

# ssh 自动认证密码登录远程服务器配置

添加一下配置到电脑目录/.ssh/config

Host myremote            # any name for the host

HostName 192.168.178.05  # IP, .local, or hostname if defined

User username            # your username

Port 22                  # port to listen
1
2
3
4
5
6
7

设置完成后删除#开头的注释,不然回报 /Users/username/.ssh/config line 10: garbage at end of line; "#". 的错误,具体原因不是很清楚,只能先这样设置。

# 使用

ssh myremote
1

# SCP 两台服务器无密码传输文件配置

  1. 将 主机 A .ssh 目录中的 id_rsa.pub 文件复制到 主机 B 的 ~/.ssh/ 目录中,并改名为 authorized_keys

scp .ssh/id_rsa.pub 192.168.10.2:/root/.ssh/authorized_keys

以后从 A 主机 scp 到 B 主机就不需要密码了

  1. 测试主机 A 文件 复制到主机 B
scp <dir>|<file> IP:/dirname

EXP. scp <dir> 192.168.1.1:/var/www
1
2
3

复制成功

# 项目持续集成方案

# github actions

  1. 在项目根目录新建.github/workflows/目录结构,在workflows目录新建一个以yml为扩展名的文件,文件可以自由命名

  2. 搜索github官方的actions市场,选择一个适合自己的持续集成方案action,目前以actions-gh-pages为例配置文件如下

 - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          personal_token: ${{ secrets.PERSONAL_TOKEN }}
          publish_dir: dist
          allow_empty_commit: true

1
2
3
4
5
6
7

文件中的secrets.PERSONAL_TOKEN是个人github账号的生产的personal access token,需要为这个加密字段配置 repo访问的权限才能生效。

参考: 持续集成利器,GitHub Actions (opens new window)

# Git hooks

  1. 下载yorkie (opens new window)模块
npm install yorkie --save-dev

1
2
  1. 配置package.json文件中的gitHooks字段
{
  "gitHooks": {
    "pre-push": "npm run deploy"
  }
}
1
2
3
4
5

配置完成后,每次项目提交到远程仓库之前都会执行pre-push的命令