Skip to content

Commit 2598522

Browse files
never112zhouxiaoliang
andauthored
doc: update deploy (#272)
* update doc * update doc --------- Co-authored-by: zhouxiaoliang <zhouxiaoliang@qiniu.com>
1 parent 8ad8b65 commit 2598522

File tree

5 files changed

+27498
-11237
lines changed

5 files changed

+27498
-11237
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ reviewbot
33
.idea
44
.DS_Store
55
*.jar
6+
7+
# Local Netlify folder
8+
.netlify
157 KB
Loading
314 KB
Loading
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
title: 快速部署
3+
sidebar_position: 3
4+
---
5+
6+
Reviewbot 提供以下两种方式访问GitHub:
7+
8+
* GitHub App 方式 (推荐)
9+
* Access Token 方式
10+
11+
Reviewbot推荐使用GitHub App的方式进行集成,这样能更加方便的无缝代码管理流程中。本文按照GitHub App的方式进行集成
12+
13+
### 准备
14+
15+
16+
17+
在集成部署之前,我们要先了解Reviewbot需要用到的一些参数变量。
18+
| **名称** | **是否必须** | **用途** | **获取方式** |
19+
|:------:|:----------:|:---------:|:------:|
20+
| ssh-secret | 必须 | 用来 拉取待检查代码 |本地生成ssh_key私钥,公钥添加到对应GitHub账号 |
21+
| access-token | 必须 | 用来触发使用相关GitHub API |GitHub账号setting中获取 |
22+
| githubappid | 必须 | GitHub API使用 |GitHub App中获取 |
23+
| githubappperm | 必须 | GitHub API使用 |创建GitHub App时设置 |
24+
| webhook-secret | 非必须 | 验证Webhook请求的有效性 |保持跟GitHub Webhook的设置保持一致,如果GitHub上没有设置就不用配置 |
25+
26+
其他:
27+
| 名称 | 是否必须 | 用户| 获取方式 |
28+
|:------:|:-------:|:------:|:------:|
29+
| config | 非必须 | Reviewbot配置文件|在没有配置的情况下,会使用系统默认配置。配置方式参看 |
30+
| golangci-config | 非必须 | golang语言静态检查配置|在没有配置的情况下,会使用系统默认配置。配置方式参看 |
31+
| javapmdruleconfig | 非必须 | java pmd 检查规则|在没有配置的情况下,会使用系统默认配置。配置方式参看 |
32+
| javastylecheckruleconfig | 非必须 | java style check 规制|在没有配置的情况下,会使用系统默认配置。配置方式参看 |
33+
34+
35+
### 安装Reviewbot服务
36+
Reviewbot的安装是支持多种方式的,支持在物理机,虚拟机,容器上安装,因为其中还会涉及到运行环境的安装,推荐使用工程中的`Dockerfile`进行容器化的安装,步骤如下。
37+
#### 构建镜像
38+
1. 使编译Reviewbot文件,使用 `make all` 或者 `CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build .`
39+
2. 构建镜像:`docker build -t reviewbot-customimageid . `
40+
3. tag镜像:`docker tag reviewbot-customimageid:latest your_dockerimage_repo/reviewbot-customimageid:latest`
41+
4. 推送镜像:`docker push your_dockerimage_repo/reviewbot-customimageid:latest`
42+
43+
#### 部署镜像
44+
Docker 部署可以使用k8s进行部署,也可以在一台安装了docker的机器上进行部署。
45+
- k8s部署(推荐):
46+
在k8s 上创建configmap,将对应的配置设置到configmap中。
47+
1. 创建config
48+
``` shell
49+
kubectl create configmap cm-reviewbot --from-file=config=/Users/mac/Documents/project/reviewbot/deploy/config -n reviewbot
50+
```
51+
2. 设置 access-token 和 webhook-secret:
52+
``` shell
53+
kubectl create secret generic github --from-literal=access-token=ghp_5vV5DueLdf0HyS9KlB4usWRJvcziK2eFFMS --from-literal=webhook-secret=910399965ee2cbb8fddad085dfda6c1cc263 -n reviewbot
54+
```
55+
2. 创建 ssh_sercret:
56+
``` shell
57+
kubectl create secret generic ssh-secret --from-file=ssh-secret=/Users/mac/.ssh/id_rsa -n reviewbot
58+
```
59+
3. 创建 app-id和app-installation-id:
60+
``` shell
61+
kubectl create secret generic github-app --from-literal=app-id=957941 --from-literal=app-installation-id=53342102 -n reviewbot
62+
```
63+
3. 通过工程中提供的`reviewbot.yaml` 在K8S上通过命令行 `kubectl apply -f reviewbot.yaml` 进行初始化的部署 。
64+
4. 如果镜像重新编译了,可以同通过下面命令重新设置镜像:
65+
``` shell
66+
kubectl set image deployment/reviewbot reviewbot=镜像上传地址/reviewbot-新镜像:latest -n reviewbot
67+
```
68+
5. 启动镜像,镜像文件从configmap中读取配置。
69+
70+
:::tip
71+
如果想对Reviewbot进行其他的配置设置,根据`reviewbot.yaml`的配置要求创建对应的configmap。
72+
:::
73+
74+
- 本地机器部署
75+
使用docker 命令启动 编译好的docker 镜像,通过参数的方式传入必须的变量信息,ssh_key文件通过mount的方式挂载到docker。
76+
``` shell
77+
docker run -p 8888:8888 --mount type=bind,target=/secrets/github_key,source=/Users/mac/.ssh/id_rsa reviewbot-customimageid -access-token=ghp_5vV5DueL4mx0HdddyS9KsWRJvcziK2eMS -webhook-secret=9bc cf10399965ee2cbb8fddad085dfda6c1cc263 -log-level 1
78+
```
79+
80+
#### 设置外网映射
81+
如果是通过GitHub App的方式进行集成,需要将部署好的Reviewbot服务,映射到外网ip或者域名上面,使GitHub能访问到。
82+
83+
### 创建GitHub App
84+
1. 创建GitHub App,在Settings 》 Developer settings》 创建一个GitHub App,记录GitHub App ID。
85+
2. 设置权限
86+
* Repository permissions
87+
* Checks: Read & write
88+
* Commit statuses: Read & write
89+
* Pull requests: Read & write
90+
3. 订阅事件
91+
订阅需要的事件
92+
* Pull Request
93+
* Pull Request Review
94+
* Pull Request Review Comment
95+
* Pull Request Review Thread
96+
* Push
97+
* Release
98+
* Commit Comment
99+
4. 设置Webook地址,将设置好的外网映射地址配置在GitHub App的Webhook地址中。
100+
5. 安装GitHub App,在Settings>Developer Settings>Install App 安装创建的GitHub App。
101+
102+
### 触发检查
103+
1. 在GitHub中 提交PR, 就能触发Reviebot运行,看到本次合并的增量代码代码检查结果和合并建议。
104+
![comments.png](images/comments.png)![detail.png](images/detail.png)
105+
106+
107+
108+

0 commit comments

Comments
 (0)