Skip to content

Commit f1c6127

Browse files
authored
Merge pull request #1147 from merico-dev/docs-ht
Docs: Some Documents Enhancement
2 parents 824490d + 86681d9 commit f1c6127

4 files changed

Lines changed: 109 additions & 65 deletions

File tree

docs/best-practices/gitlab-jenkins-harbor.zh.md

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030

3131
!!! hint "提示"
3232

33-
上述插件不是必选集,你可以根据实际情况灵活调整。比如你本地已经有 GitLab 环境了,那么你可以果断 `gitlab-ce-docker` 插件。
33+
上述插件不是必选集,你可以根据实际情况灵活调整。比如你本地已经有 GitLab 环境了,那么你可以果断忽略 `gitlab-ce-docker` 插件。
3434

3535
上述插件的依赖关系为:
3636

3737
- jenkins-pipeline -> jenkins, gitlab-ce-docker, repo-scaffolding, harbor
3838
- repo-scaffolding -> gitlab-ce-docker
3939

40-
!!! note "注意"
40+
!!! note "说明"
4141

4242
A -> B 表示的是 A 依赖 B。
4343

@@ -96,7 +96,7 @@
9696

9797
=== "gitlab-ce-docker 插件"
9898

99-
gitlab-ce-docker 插件的配置如下:
99+
gitlab-ce-docker 插件的配置如下(该插件的详细文档参见[ gitlab-ce-docker 插件文档](../plugins/gitlab-ce-docker.zh.md))
100100

101101
```yaml title="Plugin Config with gitlab-ce-docker"
102102
- name: gitlab-ce-docker
@@ -111,12 +111,10 @@
111111
rmDataAfterDelete: false
112112
imageTag: "rc"
113113
```
114-
115-
关于 gitlab-ce-docker 插件的详细文档可以看[ gitlab-ce-docker 插件文档](../plugins/gitlab-ce-docker.zh.md)。
116114

117115
=== "jenkins 插件"
118116

119-
jenkins 插件的配置如下:
117+
jenkins 插件的配置如下(该插件的详细文档参见[ jenkins 插件文档](../plugins/jenkins.zh.md))
120118

121119
```yaml title="Plugin Config with jenkins"
122120
- name: jenkins
@@ -160,12 +158,10 @@
160158
JCasC:
161159
defaultConfig: true
162160
```
163-
164-
关于 jenkins 插件的详细文档可以看[ jenkins 插件文档](../plugins/jenkins.zh.md)。
165161

166162
=== "harbor 插件"
167163

168-
harbor 插件的配置如下:
164+
harbor 插件的配置如下(该插件的详细文档参见[ harbor 插件文档](../plugins/harbor.zh.md))
169165

170166
```yaml title="Plugin Config with harbor"
171167
- name: harbor
@@ -207,8 +203,6 @@
207203
accessMode: ReadWriteOnce
208204
size: 1Gi
209205
```
210-
211-
关于 harbor 插件的详细文档可以看[ harbor 插件文档](../plugins/harbor.zh.md)。
212206

213207
## 5、开始部署 GitLab + Jenkins + Harbor 工具链
214208

@@ -401,42 +395,44 @@ Stdout: 53e30ad85faf7e9d6d18764450bb8458db46b388b690b7c8b7a7cc6d0deb283a
401395
1. 执行命令:`kubectl edit cm coredns -n kube-system`;
402396
2. 在 hosts(第20行左右) 部分添加和 /etc/hosts 一样的记录。
403397

404-
由于演示环境是 minikube 方式部署的 k8s 单节点集群,所以 DNS 问题相对复杂一些。首先你需要获取 minikube ip:
398+
??? tip "minikube 环境额外配置内容"
405399

406-
```shell
407-
$ minikube ip
408-
192.168.49.2
409-
```
400+
如果你的环境是 docker-in-docker 的方式部署的 k8s 集群,比如用了 minikube,这时候 DNS 问题就会相对复杂一些。首先你需要获取 minikube ip:
410401

411-
如果你执行 `kubectl get ingress -A` 命令,可以看到 Ingress 用的 IP 地址就是这个:
412-
413-
```shell
414-
NAMESPACE NAME CLASS HOSTS ADDRESS PORTS AGE
415-
harbor harbor-ingress nginx harbor.example.com 192.168.49.2 80 129m
416-
jenkins jenkins nginx jenkins.example.com 192.168.49.2 80 130m
417-
```
402+
```shell
403+
$ minikube ip
404+
192.168.49.2
405+
```
418406

419-
然而主机 IP 并不是192.168.49.2,比如演示环境里是 44.33.22.11。因此想要访问到 GitLab、Jenkins、Harbor 几个服务并不是太容易。
407+
如果你执行 `kubectl get ingress -A` 命令,可以看到 Ingress 用的 IP 地址就是这个:
408+
409+
```shell
410+
NAMESPACE NAME CLASS HOSTS ADDRESS PORTS AGE
411+
harbor harbor-ingress nginx harbor.example.com 192.168.49.2 80 129m
412+
jenkins jenkins nginx jenkins.example.com 192.168.49.2 80 130m
413+
```
420414

421-
你需要在 `/etc/hosts` 里添加如下配置:
415+
然而主机 IP 并不是192.168.49.2,比如是 44.33.22.11。因此想要访问到 GitLab、Jenkins、Harbor 几个服务并不是太容易。
422416

423-
```shell title="dns records"
424-
44.33.22.11 gitlab.example.com
425-
192.168.49.2 jenkins.example.com harbor.example.com
426-
```
417+
你需要在 `/etc/hosts` 里添加如下配置:
418+
419+
```shell title="dns records"
420+
44.33.22.11 gitlab.example.com
421+
192.168.49.2 jenkins.example.com harbor.example.com
422+
```
427423

428-
因为 GitLab 是使用 docker 方式部署的,而 Jenkins 和 Harbor 是通过 k8s 方式部署,然后通过 Ingress 方式暴露服务,所以这里的 IP 并不一样。
424+
因为 GitLab 是使用 docker 方式部署的,而 Jenkins 和 Harbor 是通过 k8s 方式部署,然后通过 Ingress 方式暴露服务,所以这里的 IP 并不一样。
429425

430-
这时候在当前主机上,就可以分别通过如下地址访问到 GitLab、Jenkins 和 Harbor 了:
426+
这时候在当前主机上,就可以分别通过如下地址访问到 GitLab、Jenkins 和 Harbor 了:
431427

432-
- `GitLab`: http://gitlab.example.com:30080
433-
- `Jenkins`: http://jenkins.example.com
434-
- `Harbor`: http://harbor.example.com
428+
- `GitLab`: http://gitlab.example.com:30080
429+
- `Jenkins`: http://jenkins.example.com
430+
- `Harbor`: http://harbor.example.com
435431

436-
接着你还需要修改 `CoreDNS` 的配置,在 ConfigMap `kube-system/coredns` 中添加静态解析记录:
432+
接着你还需要修改 `CoreDNS` 的配置,在 ConfigMap `kube-system/coredns` 中添加静态解析记录:
437433

438-
1. 执行命令:`kubectl edit cm coredns -n kube-system`;
439-
2. 在 hosts(第20行左右) 部分添加 `44.33.22.11 gitlab.example.com` 和 `192.168.49.2 harbor.example.com` 这两条静态域名解析记录。这样 Jenkins 才能顺利通过域名访问到 GitLab 和 Harbor。
434+
1. 执行命令:`kubectl edit cm coredns -n kube-system`;
435+
2. 在 hosts(第20行左右) 部分添加 `44.33.22.11 gitlab.example.com` 和 `192.168.49.2 harbor.example.com` 这两条静态域名解析记录。这样 Jenkins 才能顺利通过域名访问到 GitLab 和 Harbor。
440436

441437
这样 Jenkins 才能通过域名访问到 GitLab。
442438

@@ -466,13 +462,17 @@ docker exec gitlab cat /etc/gitlab/initial_root_password | grep Password:
466462

467463
### 6.3、访问 Jenkins
468464

469-
前面你可能已经通过 `curl http://jenkins.example.com` 在主机内验证了 Jenkins 的网络连通性,但是远程想通过域名访问 Jenkins 并不容易。这时候你可以通过执行如下命令暴露 Jenkins 服务:
465+
前面你可能已经通过 `curl http://jenkins.example.com` 在主机内验证了 Jenkins 的网络连通性,想要远程通过域名访问 Jenkins,你需要在自己的 PC 里配置 `44.33.22.11 jenkins.example.com` 静态域名解析记录。
470466

471-
```shell title="Port Forward"
472-
kubectl port-forward service/jenkins --address 0.0.0.0 -n jenkins 32000:8080
473-
```
467+
??? tip "minikube 环境额外配置内容"
474468

475-
然后在自己的 PC 里配置 `44.33.22.11 jenkins.example.com` 静态域名解析记录,接着在浏览器里通过 `http://jenkins.example.com:32000` 访问到 Jenkins:
469+
minikube 环境想要远程通过域名访问 Jenkins 并不容易。这时候你可以通过执行如下命令暴露 Jenkins 服务:
470+
471+
```shell title="Port Forward"
472+
kubectl port-forward service/jenkins --address 0.0.0.0 -n jenkins 32000:8080
473+
```
474+
475+
接着在浏览器里通过 `http://jenkins.example.com:32000` 就可以访问到 Jenkins 了:
476476

477477
<figure markdown>
478478
![Jenkins login](./gitlab-jenkins-harbor/jenkins-login.png){ width="1000" }
@@ -488,13 +488,18 @@ Jenkins 的 admin 用户初始登录密码是 `changeme`,如果你仔细看了
488488

489489
### 6.4、访问 Harbor
490490

491-
前面你可能已经通过 `curl http://harbor.example.com` 在主机内验证了 Harbor 的网络连通性,同样你可以通过 `docker login harbor.example.com:80` 命令来尝试登录 Harbor。不过远程通过域名访问 Harbor 同样不容易。这时候你可以通过执行如下命令暴露 Harbor 服务:
491+
前面你可能已经通过 `curl http://harbor.example.com` 在主机内验证了 Harbor 的网络连通性,同样你可以通过 `docker login harbor.example.com:80` 命令来尝试登录 Harbor。
492+
然后在自己的 PC 里配置 `44.33.22.11 harbor.example.com` 静态域名解析记录。
492493

493-
```shell title="Port Forward"
494-
kubectl port-forward service/harbor-portal --address 0.0.0.0 -n harbor 30180:80
495-
```
494+
??? tip "minikube 环境额外配置内容"
496495

497-
然后在自己的 PC 里配置 `44.33.22.11 harbor.example.com` 静态域名解析记录,接着在浏览器里通过 `http://harbor.example.com:30180` 访问到 Harbor:
496+
minikube 环境想要远程通过域名访问 Harbor 同样不容易。这时候你可以通过执行如下命令暴露 Harbor 服务:
497+
498+
```shell title="Port Forward"
499+
kubectl port-forward service/harbor-portal --address 0.0.0.0 -n harbor 30180:80
500+
```
501+
502+
接着你可以在浏览器里通过 `http://harbor.example.com:30180` 访问到 Harbor:
498503

499504
<figure markdown>
500505
![Harbor login](./gitlab-jenkins-harbor/harbor-login.png){ width="1000" }
@@ -503,15 +508,18 @@ kubectl port-forward service/harbor-portal --address 0.0.0.0 -n harbor 30180:80
503508

504509
Harbor 的 admin 用户初始登录密码是 `Harbor12345`,你可以尝试用 `admin/Harbor12345` 登录 Harbor 检查功能是否正常,不过你同样不需要在 Harbor 上进行任何额外的操作。
505510

506-
// TODO(daniel-hutao): Harbor dashboard 截图
511+
<figure markdown>
512+
![Harbor dashboard](./gitlab-jenkins-harbor/harbor-dashboard.png){ width="1000" }
513+
<figcaption>Harbor dashboard</figcaption>
514+
</figure>
507515

508516
## 7、准备流水线相关插件的配置(plugin config)
509517

510518
本节继续介绍 repo-scaffolding 和 jenkins-pipeline 两个插件对应的 plugin configs。你可以点击下方 tag 按钮进行切换:
511519

512520
=== "repo-scaffolding 插件"
513521

514-
repo-scaffolding 插件的配置如下:
522+
repo-scaffolding 插件的配置如下(该插件的详细文档参见[ repo-scaffolding 插件文档](../plugins/repo-scaffolding.zh.md))
515523

516524
```yaml
517525
- name: repo-scaffolding
@@ -529,11 +537,11 @@ Harbor 的 admin 用户初始登录密码是 `Harbor12345`,你可以尝试用
529537
repo: dtm-repo-scaffolding-java-springboot
530538
repoType: github
531539
```
532-
533-
关于 repo-scaffolding 插件的详细文档可以看[ repo-scaffolding 插件文档](../plugins/repo-scaffolding.zh.md)。
534540

535541
=== "jenkins-pipeline 插件"
536542

543+
jenkins-pipeline 插件的配置如下(该插件的详细文档参见[ jenkins-pipeline 插件文档](../plugins/jenkins-pipeline.zh.md)):
544+
537545
```yaml
538546
- name: jenkins-pipeline
539547
instanceID: default
@@ -554,14 +562,18 @@ Harbor 的 admin 用户初始登录密码是 `Harbor12345`,你可以尝试用
554562
user: admin
555563
```
556564

565+
!!! Warning "注意"
566+
557567
这里需要注意的是 Jenkins 的访问地址需要使用 `http://44.33.22.11:32000`,而不能用域名,因为当前部署架构下 GitLab 并不能解析到 `jenkins.example.com` 这个域名。
558-
而且 GitLab 也无法直接访问到 `http://44.33.22.11:32000` 这个地址,这里还需要通过 kubectl port-forward 的访问转发一次流量。
559-
568+
另外 minikube 环境里 GitLab 也无法直接访问到 `http://44.33.22.11:32000` 这个地址,这里还需要通过 kubectl port-forward 的访问转发一次流量。
569+
560570
在正式的企业环境里,只需要保证 GitLab 能够访问到 Jenkins 即可,如果你的企业里可以通过配置 DNS 等方式让 GitLab 能够完成 jenkins.example.com 域名的解析,
561571
而且对应的 IP (和端口)可以从 GitLab 访问到,那就可以在这里配置域名。
572+
573+
??? tip "minikube 环境额外配置内容"
562574

563-
接着我们执行如下命令保证 Jenkins 可以从 `http://44.33.22.11:32000` 访问到:
564-
575+
你可以执行如下命令保证 Jenkins 可以从 `http://44.33.22.11:32000` 访问到:
576+
565577
```shell title="Port Forward"
566578
kubectl port-forward service/jenkins --address 0.0.0.0 -n jenkins 32000:8080
567579
```
234 KB
Loading

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## What is DevStream?
44

5-
DevStream is an open-source DevOps toolchain manager that is of the develoeprs, by the develoeprs, for the develoeprs.
5+
DevStream is an open-source DevOps toolchain manager that is of the developers, by the developers, for the developers.
66

77
Discover the DevOps practice that suits you best. DevStream will take care of the rest.
88

docs/plugins/jenkins-pipeline.zh.md

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
`jenkins-pipeline` 插件用于打通 GitHub/GitLab 和 Jenkins,实现自动化创建 Jenkins Pipeline 的功能。
44

5-
*注意:当前只支持 GitLab,GitHub 将在近期被支持。*
6-
75
本文将演示:
86

97
1. 通过 [`repo-scaffolding`](../repo-scaffolding.zh) 插件在 GitLab 上创建一个 Java Sprint Boot 项目脚手架;
108
2. 通过 `jenkins-pipeline` 插件在 Jenkins 上创建一条 Java Spring Boot 的 CI 流水线;
119
3. 通过 `jenkins-pipeline` 插件实现在 GitLab 和 Jenkins 上分别配置相应参数,实现当 GitLab 上的代码库有 push 或者 merge 事件时,自动触发 Jenkins 上的流水线运行,同时流水线的执行结果自动回写到 GitLab 上。
1210

11+
!!! tip "提示"
12+
13+
GitHub 与 GitLab 的主要区别在于 DevStream tool config 的 options.scm.cloneURL 以及所需要的 token 等不同。
14+
1315
## 1、前置要求
1416

1517
**必须满足**
@@ -20,7 +22,9 @@
2022
- Jenkins 与 GitLab、Harbor 网络互通
2123
- 执行 dtm 的主机与 Jenkins、GitLab 网络互通
2224

23-
*注意:当前插件暂时只支持对接使用 dtm 部署的 Jenkins。*
25+
!!! warning "注意"
26+
27+
当前插件暂时只支持对接使用 dtm 部署的 Jenkins。
2428

2529
本文基于如下环境编写:
2630

@@ -38,6 +42,16 @@ export GITLAB_TOKEN=YOUR_GITLAB_TOKEN
3842
export GITLAB_SSHKEY=YOUR_REPO_PRIVATE_KEY
3943
```
4044

45+
!!! tip "提示"
46+
47+
如果是 GitHub,则这里的环境变量改成:
48+
49+
```shell
50+
export IMAGE_REPO_PASSWORD=YOUR_IMAGE_REPO_PASSWORD
51+
export GITHUB_TOKEN=YOUR_GITHUB_TOKEN
52+
export GITHUB_SSHKEY=YOUR_REPO_PRIVATE_KEY
53+
```
54+
4155
然后准备 DevStream 插件配置:
4256

4357
```yaml
@@ -123,35 +137,53 @@ tools:
123137

124138
首先你可以在 GitLab 上可以看 repo scaffolding 的效果,dtm 为你创建了一个 Java Spring Boot 项目脚手架:
125139

126-
![repo-scaffolding](./jenkins-pipeline/repo-scaffolding.png)
140+
<figure markdown>
141+
![Repo scaffolding](./jenkins-pipeline/repo-scaffolding.png){ width="1000" }
142+
<figcaption>Repo scaffolding</figcaption>
143+
</figure>
127144

128145
- **Pipeline**
129146

130147
接着你可以在 Jenkins 上看到刚才 dtm 为你创建的 Pipeline:
131148

132-
![pipeline](./jenkins-pipeline/pipeline.png)
149+
<figure markdown>
150+
![Pipeline](./jenkins-pipeline/pipeline.png){ width="1000" }
151+
<figcaption>Pipeline</figcaption>
152+
</figure>
133153

134154
如果你点开这个 test-job,就能看到它已经被触发了一次,执行结果如下:
135155

136-
![pipeline](./jenkins-pipeline/pipeline-console.png)
156+
<figure markdown>
157+
![Pipeline console](./jenkins-pipeline/pipeline-console.png){ width="1000" }
158+
<figcaption>Pipeline console</figcaption>
159+
</figure>
137160

138161
- **状态回写**
139162

140163
然后你可以回到 GitLab,看一下 Jenkins Pipeline 的执行结果有没有被成功回写:
141164

142-
![gitlab status](./jenkins-pipeline/gitlab-status.png)
165+
<figure markdown>
166+
![GitLab status](./jenkins-pipeline/gitlab-status.png){ width="1000" }
167+
<figcaption>GitLab status</figcaption>
168+
</figure>
143169

144170
- **检查镜像**
145171

146172
通过 Jenkins 的日志你可以找到刚才 push 的镜像地址为 `harbor.example.com:80/library/spring-demo:latest`:
147173

148-
![jenkins logs](./jenkins-pipeline/jenkins-logs.png)
174+
<figure markdown>
175+
![Jenkins' logs](./jenkins-pipeline/jenkins-logs.png){ width="1000" }
176+
<figcaption>Jenkins' logs</figcaption>
177+
</figure>
149178

150179
// TODO(daniel-hutao): 补充 Harbor 截图
151180

152181
最后你可以通过 `docker pull` 下载该镜像:
153182

154-
![docker pull](./jenkins-pipeline/docker-pull.png)
183+
<figure markdown>
184+
![Docker pulling](./jenkins-pipeline/docker-pull.png){ width="1000" }
185+
<figcaption>Docker pulling</figcaption>
186+
</figure>
155187

156188
## 配置详解
157189

0 commit comments

Comments
 (0)