Skip to content

Commit d5dab95

Browse files
authored
Merge pull request #1343 from aFlyBird0/docs-cn
docs: update core-concepts
2 parents 834ca8c + aaabdde commit d5dab95

File tree

16 files changed

+427
-190
lines changed

16 files changed

+427
-190
lines changed

docs/core-concepts/apps.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Apps

docs/core-concepts/apps.zh.md

Lines changed: 126 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,109 @@
1-
# 应用
1+
# 应用(Apps)
22

3-
## 概念
3+
## 1 概念
44

5-
应用在 devstream 中表示对一个服务的生命周期配置,包括对服务的项目脚手架,CI 流程以及 CD 流程的配置,在 devstream 中使用应用可以使用少数几行配置就构建出服务的整条 CI/CD 流水线配置。
5+
应用在 DevStream 中表示对一个服务的生命周期配置,包括对服务的项目脚手架,CI 流程以及 CD 流程的配置,在 devstream 中使用应用可以使用少数几行配置就构建出服务的整条 CI/CD 流水线配置。
66

7-
## 应用配置
7+
### 1.1 应用(Apps)
88

9-
应用的示例配置如下:
9+
有时候,你需要为一个应用/微服务定义多个 工具。例如,对于一个 web 应用程序,你可能需要指定以下工具:
10+
11+
- 仓库脚手架
12+
- 持续集成
13+
- 持续部署
14+
15+
如果你有多个应用需要管理,你需要在配置中创建多个 工具,这可能会很繁琐,而且配置文件难以阅读。
16+
17+
为了更容易地管理多个应用/微服务,DevStream 提供了另一层抽象,称为 应用。你可以在一个应用中定义所有内容(例如,上面提到的仓库脚手架、持续集成、持续部署等),只需要几行配置,就可以使配置文件更容易阅读和管理。
18+
19+
在底层,DevStream 仍然会将你的 应用 配置转换为 工具 的定义,但你不需要关心它。
20+
21+
## 1.2 流水线模板(pipelineTemplates)
22+
23+
一个 DevStream 应用 可以引用一个或多个 流水线模板,这些模板主要是 CI/CD 定义,这样 应用 的定义可以更短,以在多个微服务之间共享公共的 CI/CD 流水线。
24+
25+
## 2 配置方式
26+
27+
### 2.1 应用
28+
29+
应用在配置中由 `apps` 来定义,它是一个数组,每个元素的字段如下:
30+
31+
- name: 应用的名称,必须是唯一的
32+
- spec: 配置应用特定的信息
33+
- repo: 代码仓库信息
34+
- repoTemplate: 可选。结构和 repo 一致。若非空,DevStream 将使用项目脚手架来创建仓库。
35+
- ci: 可选,一个 CI 流水线的数组,每个元素包含以下字段:
36+
- type: 类型。值为 `template` 或某个插件的名称。
37+
- templateName: 可选。当 type 为 `template` 时,指定使用的模板名称。
38+
- vars: 可选。传入模板的变量,仅当 type 为 `template` 时有效。
39+
- options: 可选。
40+
- 当 type 是某个插件名时,就是该插件的 Options
41+
- 当 type 为 `template` 时,覆盖模板中的 Options。你需要写清想要覆盖的选项的完整路径,例如 `options.docker.registry.type`
42+
- cd: 与 `ci` 类似,是 CD 流水线列表。dtm 会先执行 ci 流水线,再执行 cd 流水线。
43+
44+
### 2.2 流水线模板
45+
46+
流水线模板在配置中由 `pipelineTemplates` 来定义,它是一个数组,每个元素的字段如下:
47+
48+
- name: 流水线模板的名称,必须是唯一的
49+
- type: 对应插件的名称
50+
- options: 插件的 Options (可能和原始的插件 Options 不同)
51+
52+
### 2.3 局部变量
53+
54+
DevStream 已经有了全局变量,所有的 工具 和 应用 都可以直接引用。
55+
56+
但有时,我们想多次引用某个 DevOps 工具,但他们只有一些细微的差别。例如,除了项目名称不同,其他的都相同。
57+
58+
在这种情况下,我们可以定义一个流水线模板,在其中定义一个局部变量,然后在 应用 引用该流水线模板时,传入不同的值。
59+
60+
```yaml hl_lines="13 15 23 30" title="流水线模板的使用与局部变量"
61+
apps:
62+
- name: my-app
63+
spec:
64+
language: java
65+
framework: springboot
66+
repo:
67+
url: https://github.com/testUser/testApp.git
68+
branch: main
69+
ci:
70+
- type: github-actions # 不定义 pipelineTemplates,直接使用插件
71+
cd:
72+
- type: template # 使用流水线模板
73+
templateName: my-cd-template # 对应 pipelineTemplates 中的 name
74+
vars:
75+
appName: my-app # 传入模板的变量
76+
77+
pipelineTemplates:
78+
cd:
79+
- name: my-cd-template
80+
type: argocdapp
81+
options:
82+
app:
83+
name: [[ appName ]] # 定义一个局部变量,在引用使用模板时传入
84+
namespace: argocd # argocd 的命名空间
85+
destination:
86+
server: https://kubernetes.default.svc # 部署的 kubernetes 服务地址
87+
namespace: default # 应用要部署的命名空间
88+
source:
89+
valuefile: values.yaml # 项目中的 helm 变量文件名
90+
path: charts/[[ appName ]] # 项目中的 helm 配置路径
91+
```
92+
93+
## 3 完整配置示例
94+
95+
应用 的真实示例配置如下:
1096
1197
```yaml
1298
apps:
13-
- name: testApp #应用名称
99+
- name: testApp # 应用名称
14100
spec: # 该配置项用于配置应用特定的信息
15101
language: java #应用所使用的编程语言
16102
framework: springboot #应用所使用的编程框架
17103
repo: # 该配置项用于应用的代码仓库信息
18104
url: https://github.com/testUser/testApp.git
19105
branch: main
20-
repoTemplate: # 该配置用于创建应用的脚手架
106+
repoTemplate: # 可选,用于创建应用的脚手架。不为空时,会使用该脚手架创建应用的代码仓库
21107
url: https://github.com/devstream-io/dtm-repo-scaffolding-java-springboot.git
22108
vars:
23109
imageRepoOwner: repoOwner # 用于渲染脚手架模版的变量
@@ -39,45 +125,49 @@ apps:
39125
- type: github-actions
40126
options:
41127
imageRepo:
42-
owner: repoOwner
128+
owner: repoOwner # 覆盖 插件/模板 原有的 Options,YAML 路径要写完全
43129
cd: # 配置应用的 cd,如果为使用 argocdapp 运行应用的 cd 流程
44130
- type: argocdapp
45131
```
46132
47-
使用该配置就会在 `gitlab` 仓库中创建两个应用,项目的脚手架均为 devstream 官方提供的 [springboot](https://github.com/devstream-io/dtm-repo-scaffolding-java-springboot.git) 项目。应用 `testApp` 会在每次代码提交后使用 `github-actions` 运行测试。应用 `testApp2` 会在每次代码提交后使用 `github-actions` 运行测试并构建镜像推送到 `repoOwner` 的镜像仓库中,最后使用 argocd 将应用部署到集群中。
133+
使用该配置就会在 `gitlab` 仓库中创建两个应用,项目的脚手架均为 DevStream 官方提供的 [SpringBoot](https://github.com/devstream-io/dtm-repo-scaffolding-java-springboot.git) 项目。应用 `testApp` 会在每次代码提交后使用 `github-actions` 运行测试。应用 `testApp2` 会在每次代码提交后使用 `github-actions` 运行测试并构建镜像推送到 `repoOwner` 的镜像仓库中,最后使用 Argo CD 将应用部署到集群中。
48134

49135
### repo/repoTemplate 配置
50136

51-
应用配置中的 `repo` 和 `repoTemplate` 均表示一个代码仓库,支持以下两种配置代码仓库的方式
137+
应用配置中的 `repo` 和 `repoTemplate` 均表示一个代码仓库,支持通过 url 或 详细字段来配置
52138

53-
#### 使用 url 来配置代码仓库:
139+
!!! note "两种配置代码仓库的方式"
54140

55-
```yaml
56-
repo:
57-
url: [email protected]:root/myapps.git # url 表示仓库的地址,支持 git 地址和 http 地址
58-
apiURL: https://gitlab.example.com # 非必填,如果使用 gitlab 而且 url 使用的是 git 地址,则需要配置该字段用于表示 gitlab 的 api 请求地址
59-
branch: "" #非必填,github 默认为 main 分支,gitlab 默认为 master 分支
60-
```
61-
62-
该配置表示使用的仓库为 `gitlab`, 要使用 `[email protected]:root/myapps.git` 来克隆代码,devstream 会使用使用 `https://gitlab.example.com` 和 gitlab 进行交互,仓库的主分支为 `master` 分支。
63-
64-
#### 使用仓库的详细字段来配置仓库:
65-
66-
```yaml
67-
repo:
68-
org: "" # 非必填,仓库的拥有组织名称,如果使用 github 的组织则需要填写此字段
69-
owner:"test_user" # 如果仓库是非组织的,则需要填写该字段表示仓库拥有者
70-
name: "" # 非必填,默认为应用名
71-
baseURL: https://gitlab.example.com # 非必填,如果使用 gitlab 则需要填写该字段表示 gitlab 的域名
72-
branch: master #非必填,github 默认为 main 分支,gitlab 默认为 master 分支
73-
type: gitlab #必填,表示该仓库的类型,目前支持 gitlab/github
74-
```
75-
76-
该配置表示代码仓库使用的是 `gitlab` 且其地址为 `https://gitlab.example.com`,仓库名称为应用名,仓库的所有者为 `test_user`,主分支为 `master` 分支。
141+
=== "使用 url 来配置"
142+
143+
```yaml title=""
144+
repo:
145+
url: [email protected]:root/myapps.git # url 表示仓库的地址,支持 git 地址和 http 地址
146+
apiURL: https://gitlab.example.com # 非必填,如果使用 gitlab 而且 url 使用的是 git 地址,则需要配置该字段用于表示 gitlab 的 api 请求地址
147+
branch: "" # 非必填,github 默认为 main 分支,gitlab 默认为 master 分支
148+
```
149+
150+
该配置表示使用的仓库为 `gitlab`, 要使用 `[email protected]:root/myapps.git` 来克隆代码,devstream 会使用使用 `https://gitlab.example.com` 和 gitlab 进行交互,仓库的主分支为 `master` 分支。
151+
152+
=== "使用仓库的详细字段来配置"
153+
154+
```yaml title=""
155+
repo:
156+
org: "" # 非必填,仓库的拥有组织名称,如果使用 github 的组织则需要填写此字段
157+
owner:"test_user" # 如果仓库是非组织的,则需要填写该字段表示仓库拥有者
158+
name: "" # 非必填,默认为应用名
159+
baseURL: https://gitlab.example.com # 非必填,如果使用 gitlab 则需要填写该字段表示 gitlab 的域名
160+
branch: master #非必填,github 默认为 main 分支,gitlab 默认为 master 分支
161+
type: gitlab #必填,表示该仓库的类型,目前支持 gitlab/github
162+
```
163+
164+
该配置表示代码仓库使用的是 `gitlab` 且其地址为 `https://gitlab.example.com`,仓库名称为应用名,仓库的所有者为 `test_user`,主分支为 `master` 分支。
77165

78166
### ci 配置
79167

80-
应用配置中的 `ci` 目前支持 `github-actions`/`gitlab-ci`/`jenkins-pipeline`/`template` 4 种类型,前 3 种类型分别对应了 `github` 中的 actions 流水线,`gitlab` 中 ci 流水线和 `jenkins` 中的 pipeline,它们的具体配置如下:
168+
应用配置中的 `ci` 目前支持 `github-actions`/`gitlab-ci`/`jenkins-pipeline`/`template` 4 种类型。
169+
170+
其中 `template` 类型表示使用 流水线模板 来运行流水线,前 3 种类型分别对应了 `github` 中的 actions 流水线,`gitlab` 中 ci 流水线和 `jenkins` 中的 pipeline,它们的具体配置如下:
81171

82172
```yaml
83173
ci:
@@ -132,7 +222,7 @@ apps:
132222
- type: template # 表示该 ci 流程使用模版
133223
templateName: ci-pipeline # ci 使用的模版名称
134224
vars:
135-
dingdingAccessToken: tokenForProject2 #用于渲染 ci 模版的变量
225+
dingdingAccessToken: tokenForProject2 # 设置传入模版 "ci-pipeline" 的变量
136226
dingdingSecretValue: secretValProject2
137227
138228
pipelineTemplates: # 即配置的 ci/cd 模版
@@ -149,7 +239,7 @@ pipelineTemplates: # 即配置的 ci/cd 模版
149239
name: dingTalk
150240
webhook: https://oapi.dingtalk.com/robot/send?access_token=[[ dingdingAccessToken ]] # 用于被 app 渲染的模版,这样就可以实现不同应用使用同一个模版发送通知到不同的钉钉群
151241
securityType: SECRET
152-
securityValue: [[ dingdingSecretValue ]]
242+
securityValue: [[ dingdingSecretValue ]] # 局部变量,应用 在引用此模板时通过 vars 来传入
153243
sonarqube:
154244
url: http://sonar.example.com
155245
token: sonar_token

docs/core-concepts/config.zh.md

Lines changed: 35 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,65 @@
1-
# DevStream配置
1+
# 配置(Config)
22

3-
TODO: 需要跟英文文档同步。请暂且阅读英文文档
3+
DevStream使用 YAML 文件来声明 DevOps 工具链的配置
44

5-
DevStream使用YAML文件来描述你的DevOps工具链配置。
5+
## 配置内容
66

7-
## 主配置文件
7+
正如概述中所提到的,配置包含了以下几个部分:
88

9-
默认情况下,`dtm` 会使用当前目录下的`config.yaml`来作为主配置。
9+
- `config`
10+
- `vars`
11+
- `tools`
12+
- `apps`
13+
- `pipelineTemplates`
1014

11-
主配置包含三个部分:
15+
其中,`config` 必选,`tools``apps` 至少有一个不为空,其余部分可选。
1216

13-
- `state`: 指定DevStream状态存储位置
17+
## 组织方式
1418

15-
### 主配置文件示例
19+
DevStream 支持两种组织配置的方式:
1620

17-
`config.yaml` 的结构通常如下:
21+
- 单文件:你可以把这些部分写到一个 YAML 文件中
22+
- 目录:也可以把它们分开放到同一个文件夹下的多个 YAML 文件中,只要这些文件的名字以 `.yaml``.yml` 结尾,且内容拼接后包含了 DevStream 所需的各个部分即可。
1823

19-
```yaml
20-
varFile: variables.yaml
21-
toolFile: tools.yaml
22-
state:
23-
backend: local
24-
options:
25-
stateFile: devstream.state
26-
```
24+
然后在执行 `init` 等命令时,加上 `-f``--config-file` 参数指定配置文件/目录的路径。
2725

28-
### varFile
26+
如:
2927

30-
变量文件是一个用`key: value`格式来定义变量的YAML文件。
28+
- 单文件:`dtm init -f config.yaml`
29+
- 目录:`dtm init -f dirname`
3130

32-
_At the moment, nested/composite values (for example, the value is a list/dictionary) are not supported yet._
31+
## 主配置
3332

34-
`variables.yaml` 的结构通常如下:
35-
36-
```yaml
37-
githubUsername: daniel-hutao
38-
repoName: dtm-test-go
39-
defaultBranch: main
40-
dockerhubUsername: exploitht
41-
```
33+
指 DevStream 本身的配置,即 `config` 部分,比如状态存储的方式等。详见 [这里](./state.zh.md)
4234

43-
### toolFile
35+
## 变量语法
4436

45-
插件文件是一个包含多种插件的Yaml文件
37+
DevStream 提供了变量语法。使用 `vars` 用来定义变量的值,而后可以在 `tools``apps``pipelineTemplates` 中使用,语法是 `[[ varName ]]`
4638

47-
- 插件文件只包含一个`tools`
48-
- `tools`是一个定义多个插件的列表
49-
- 列表中的每个对象都定义了一个由DevStream插件管理的工具
50-
- `name`: 是一个不带下划线的字符串,用来定义插件的名称
51-
- `instanceID`: 插件id
52-
- 你可以在一个插件文件中重复定义`name`,也可以在一个插件文件中重复定义`instanceID`,但是`name + instanceID`组合在一个插件文件中必须是唯一的
53-
- 每个插件都有一个可选字段,即“选项”,它又是一个包含该特定插件参数的字典。关于插件的参数,请参见本文档的“插件”部分
54-
- 每个插件都有一个可选字段,即“dependsOn”。继续阅读有关依赖项的详细信息。
55-
56-
`tools.yaml` 的结构通常如下:
39+
示例:
5740

5841
```yaml
42+
vars:
43+
githubUsername: daniel-hutao # 定义变量
44+
repoName: dtm-test-go
45+
defaultBranch: main
46+
5947
tools:
6048
- name: repo-scaffolding
61-
instanceID: golang-github
49+
instanceID: default
6250
options:
6351
destinationRepo:
64-
owner: [[ githubUsername ]]
52+
owner: [[ githubUsername ]] # 使用变量
6553
name: [[ repoName ]]
6654
branch: [[ defaultBranch ]]
6755
scmType: github
68-
vars:
69-
ImageRepo: "[[ dockerhubUsername ]]/[[ repoName ]]"
70-
sourceRepo:
71-
org: devstream-io
72-
name: dtm-scaffolding-golang
73-
scmType: github
74-
- name: jira-github-integ
75-
instanceID: default
76-
dependsOn: [ "repo-scaffolding.golang-github" ]
77-
options:
78-
owner: [[ githubUsername ]]
79-
repo: [[ repoName ]]
80-
jiraBaseUrl: https://xxx.atlassian.net
81-
jiraUserEmail: [email protected]
82-
jiraProjectKey: zzz
83-
branch: main
84-
```
85-
86-
### state
87-
88-
`state`用来指定DevStream状态存储的位置,v0.5.0以前,DevStream仅支持状态记录存放在本地。
89-
90-
从v0.6.0开始,我们将支持`local`和`s3`两种存储。
91-
92-
更多状态存储细节请参见[DevStream状态存储](./state.zh.md)
93-
94-
## 默认值
95-
96-
默认,`dtm` 使用 `config.yaml` 来作为主配置文件
97-
98-
### 指定主配置文件
99-
100-
你可以通过`dtm -f` or `dtm --config-file`来指定主配置文件。例如:
101-
102-
```shell
103-
dtm apply -f path/to/your/config.yaml
104-
dtm apply --config-file path/to/your/config.yaml
56+
# <后面略...>
10557
```
10658

107-
### varFile和toolFile默认没有值
59+
## 工具的配置
10860

109-
对于`varFile`和`toolFile`, 默认没有任何值。
61+
`tools` 部分声明了工具链中的工具,详见 [这里](./tools.zh.md)
11062

111-
如果主配置中没有指定`varFile`,`dtm`将不会使用任何var文件,即使当前目录下已经有一个名为`variables.yaml`的文件。
63+
## 应用与流水线模板的配置
11264

113-
同样,如果主配置中没有指定`toolFile`,即使当前目录下有`tools.yaml`文件,`dtm`也会抛出错误。
65+
`apps` 部分声明了 应用 的配置,`pipelineTemplates` 声明了 流水线模板,详见 [这里](./apps.zh.md)

0 commit comments

Comments
 (0)