|
1 | | -# DevStream Configuration |
| 1 | +# Config |
2 | 2 |
|
3 | | -DevStream uses YAML files to describe your DevOps toolchain configuration. |
| 3 | +Now let's have a look at some config examples. |
4 | 4 |
|
5 | | -## Main Config File |
| 5 | +TL;DR: [see the complete config file examle at the end of this doc](#7-putting-it-all-together). |
6 | 6 |
|
7 | | -By default, `dtm` tries to use `./config.yaml` (under your current directory) as the main config. |
| 7 | +--- |
8 | 8 |
|
9 | | -The main config contains three sections: |
| 9 | +## 1 The Config File |
10 | 10 |
|
11 | | -- `varFile`: the path/to/your/variables file |
12 | | -- `toolFile`: the path/to/your/tools configuration file |
13 | | -- `pluginDir`: the path/to/your/plugins directory, default: `~/.devstream/plugins`, or use `-d` flag to specify a directory |
14 | | -- `state`: configuration of DevStream state. For example, |
| 11 | +As mentioned in the overview section, the main config contains many sections, like: |
15 | 12 |
|
16 | | -### Example Main Config File |
| 13 | +- `config` |
| 14 | +- `vars` |
| 15 | +- `tools` |
| 16 | +- `apps` |
| 17 | +- `pipelineTemplates` |
17 | 18 |
|
18 | | -See the `config.yaml` example below: |
| 19 | +By default, `dtm` tries to use `./config.yaml` (under your working directory) as the main config. |
| 20 | + |
| 21 | +You can override the default value with `-f` or `--config-file`. Examples: |
| 22 | + |
| 23 | +```shell |
| 24 | +dtm apply -f path/to/your/config.yaml |
| 25 | +dtm apply --config-file path/to/your/config.yaml |
| 26 | +``` |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## 2 State Config |
| 31 | + |
| 32 | +The `config` section specifies where to store the DevStream state. |
| 33 | + |
| 34 | +### 2.1 Local |
19 | 35 |
|
20 | 36 | ```yaml |
21 | | -varFile: "./variables.yaml" |
22 | | -toolFile: "./tools.yaml" |
23 | | -appFile: "./apps.yaml" |
24 | | -templateFile: "./templates.yaml" |
25 | | -state: # state config, backend can be "local", "s3", or "k8s" |
26 | | - backend: local |
27 | | - options: |
28 | | - stateFile: devstream.state |
| 37 | +config: |
| 38 | + state: |
| 39 | + backend: local |
| 40 | + options: |
| 41 | + stateFile: devstream.state |
| 42 | +``` |
| 43 | +
|
| 44 | +_Note: The `stateFile` under the `options` section is mandatory for the local backend._ |
| 45 | + |
| 46 | +### 2.2 Kubernetes |
| 47 | + |
| 48 | +```yaml |
| 49 | +config: |
| 50 | + state: |
| 51 | + backend: k8s |
| 52 | + options: |
| 53 | + namespace: devstream # optional, default is "devstream", will be created if not exists |
| 54 | + configmap: state # optional, default is "state", will be created if not exists |
| 55 | +``` |
| 56 | + |
| 57 | +### 2.3 S3 |
| 58 | + |
| 59 | +```yaml |
| 60 | +config: |
| 61 | + state: |
| 62 | + backend: s3 |
| 63 | + options: |
| 64 | + bucket: devstream-remote-state |
| 65 | + region: ap-southeast-1 |
| 66 | + key: devstream.state |
29 | 67 | ``` |
30 | 68 |
|
31 | | -### Variables File |
| 69 | +_Note: the `bucket`, `region`, and `key` under the `options` section are all mandatory fields for the s3 backend._ |
32 | 70 |
|
33 | | -The var file is a YAML file containing key-value pairs. |
| 71 | +--- |
34 | 72 |
|
35 | | -_At the moment, nested/composite values (for example, the value is a list/dictionary) are not supported yet._ |
| 73 | +## 3 Variables |
36 | 74 |
|
37 | | -See the `variables.yaml` example below: |
| 75 | +To not repeat yourself (Don't repeat yourself, DRY, see [here](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself),) we can define some variables in a var file and use the vars in the config file. |
| 76 | + |
| 77 | +The vars section is a YAML dict containing key-value pairs. Example: |
| 78 | + |
| 79 | +Example: |
38 | 80 |
|
39 | 81 | ```yaml |
40 | | -githubUsername: daniel-hutao |
41 | | -repoName: dtm-test-go |
42 | | -defaultBranch: main |
43 | | -dockerhubUsername: exploitht |
| 82 | +vars: |
| 83 | + repoOwner: RepoOwner |
| 84 | + repoTemplateBaseURL: github.com/devstream-io |
| 85 | + imageRepoOwner: ImageRepoOwner |
44 | 86 | ``` |
45 | 87 |
|
46 | | -### Tool File |
| 88 | +To use these variables in a config file, use the following syntax: |
47 | 89 |
|
48 | | -Tool file contains a list of tools. |
| 90 | +```yaml |
| 91 | +[[ varNameHere ]] |
| 92 | +``` |
49 | 93 |
|
50 | | -The tool file contains: |
| 94 | +--- |
51 | 95 |
|
52 | | -- Only one section (at the moment), which is `tools`. |
53 | | -- `tools` is a list of dictionaries. |
54 | | -- Each dictionary defines a DevOps "tool" which is managed by a DevStream plugin |
55 | | -- Each dictionary (tool) has the following mandatory fields: |
56 | | - - `name`: the name of the tool/plugin, string, without underscore |
57 | | - - `instanceID`: the id of this tool instance |
58 | | - - you can have duplicated `name` in one config file, and you can also have duplicated `instanceID` in one config file, but the `name + instanceID` combination must be unique in one config file |
59 | | -- Each dictionary (tool) has an optional field which is `options`, which in turn is a dictionary containing parameters for that specific plugin. For plugins' parameters, see the "plugins" section of this document. |
60 | | -- Each directory (tool) has an optional field which is `dependsOn`. Continue reading for detail about dependencies. |
| 96 | +## 4 Tools |
61 | 97 |
|
62 | | -See the `tools.yaml` example down below: |
| 98 | +The tools section contains a list of tools. |
63 | 99 |
|
64 | 100 | ```yaml |
65 | 101 | tools: |
66 | 102 | - name: repo-scaffolding |
67 | | - instanceID: golang-github |
| 103 | + instanceID: myapp |
68 | 104 | options: |
69 | 105 | destinationRepo: |
70 | | - owner: [[ githubUsername ]] |
71 | | - org: "" |
72 | | - repo: [[ repoName ]] |
73 | | - branch: [[ defaultBranch ]] |
| 106 | + owner: [[ githubUser ]] |
| 107 | + repo: [[ app ]] |
| 108 | + branch: main |
74 | 109 | repoType: github |
75 | | - vars: |
76 | | - ImageRepo: "[[ dockerhubUsername ]]/[[ repoName ]]" |
77 | 110 | sourceRepo: |
78 | 111 | org: devstream-io |
79 | | - repo: dtm-scaffolding-golang |
| 112 | + repo: dtm-scaffolding-python |
80 | 113 | repoType: github |
81 | | -- name: jira-github-integ |
| 114 | + vars: |
| 115 | + imageRepo: [[ dockerUser ]]/[[ app ]] |
| 116 | +- name: githubactions-python |
82 | 117 | instanceID: default |
83 | | - dependsOn: [ "repo-scaffolding.golang-github" ] |
| 118 | + dependsOn: [ repo-scaffolding.myapp ] |
84 | 119 | options: |
85 | | - owner: [[ githubUsername ]] |
86 | | - repo: [[ repoName ]] |
87 | | - jiraBaseUrl: https://xxx.atlassian.net |
88 | | - |
89 | | - jiraProjectKey: zzz |
| 120 | + owner: [[ githubUser ]] |
| 121 | + repo: [[ app ]] |
| 122 | + language: |
| 123 | + name: python |
90 | 124 | branch: main |
| 125 | + docker: |
| 126 | + registry: |
| 127 | + type: dockerhub |
| 128 | + username: [[ dockerUser ]] |
| 129 | + repository: [[ app ]] |
| 130 | +- name: helm-installer |
| 131 | + instanceID: argocd |
| 132 | +- name: argocdapp |
| 133 | + instanceID: default |
| 134 | + dependsOn: [ "helm-installer.argocd", "githubactions-python.default" ] |
| 135 | + options: |
| 136 | + app: |
| 137 | + name: [[ app ]] |
| 138 | + namespace: argocd |
| 139 | + destination: |
| 140 | + server: https://kubernetes.default.svc |
| 141 | + namespace: default |
| 142 | + source: |
| 143 | + valuefile: values.yaml |
| 144 | + path: helm/[[ app ]] |
| 145 | + repoURL: ${{repo-scaffolding.myapp.outputs.repoURL}} |
91 | 146 | ``` |
92 | 147 |
|
93 | | -### State |
| 148 | +If you want tool A to be installed before tool B, you can let tool B depend on tool A. |
94 | 149 |
|
95 | | -The `state` section specifies where to store DevStream state. As of now (v0.5.0), we only support local backend. |
| 150 | +The syntax for dependency is: |
96 | 151 |
|
97 | | -From v0.6.0 on, we will support both "local" and "s3" backend store the DevStream state. |
| 152 | +```yaml |
| 153 | +dependsOn: [ "ToolName.ToolInstanceID" ] |
| 154 | +``` |
98 | 155 |
|
99 | | -Read the section [The State Section in the Main Config](./stateconfig.md) for more details. |
| 156 | +Since `dependsOn` is a list, a tool can have multiple dependencies: |
100 | 157 |
|
101 | | -## Default Values |
| 158 | +``` |
| 159 | +dependsOn: [ "ToolName1.ToolInstanceID1", "ToolName2.ToolInstanceID2", "..." ] |
| 160 | +``` |
102 | 161 |
|
103 | | -By default, `dtm` uses `config.yaml` as the main config file. |
| 162 | +--- |
104 | 163 |
|
105 | | -### Specifying a Main Config File Explicitly |
| 164 | +## 5 Apps |
106 | 165 |
|
107 | | -You can override the default value with `-f` or `--config-file`. Examples: |
| 166 | +The Apps section looks like the following: |
108 | 167 |
|
109 | | -```shell |
110 | | -dtm apply -f path/to/your/config.yaml |
111 | | -dtm apply --config-file path/to/your/config.yaml |
| 168 | +```yaml |
| 169 | +apps: |
| 170 | +- name: service-A |
| 171 | + spec: |
| 172 | + language: python |
| 173 | + framework: django |
| 174 | + repo: |
| 175 | + scmType: github |
| 176 | + owner: devstream-io |
| 177 | + org: devstream-io # either owner or org must exist |
| 178 | + name: service-A # defaults to "app.name" |
| 179 | + url: github.com/devstream-io/repo-name # optional. if exists, no need for the scm/owner/org/name sections |
| 180 | + apiURL: gitlab.com/some/path/to/your/api # optional, in case of self-managed git |
| 181 | + repoTemplate: # optional. if repoTemplate isn't empty, create repo according to the template |
| 182 | + scmType: github |
| 183 | + owner: devstream-io |
| 184 | + org: devstream-io # either owner or org must exist |
| 185 | + name: dtm-scaffolding-golang |
| 186 | + url: github.com/devstream-io/repo-name # optional. if exists, no need for the scm/owner/org/name sections |
| 187 | + vars: # optional |
| 188 | + foo: bar # variables used for repoTemplate specifically |
| 189 | + ci: |
| 190 | + - type: template # type template means it's a reference to the pipeline template. read the next section. |
| 191 | + templateName: ci-pipeline-1 |
| 192 | + options: # optional, used to override defaults in the template |
| 193 | + vars: # optional, key/values to be passed to the template |
| 194 | + key: value |
| 195 | + cd: |
| 196 | + - type: template # type template means it's a reference to the pipeline template. read the next section. |
| 197 | + templateName: cd-pipeline-1 |
| 198 | + options: # optional, used to override defaults in the template |
| 199 | + vars: # optional, key/values to be passed to the template |
| 200 | + key: value |
| 201 | +``` |
| 202 | + |
| 203 | +Since many key/values have default values, it's possible to use the following minimum config for the apps section: |
| 204 | + |
| 205 | +```yaml |
| 206 | +apps: |
| 207 | +- name: myapp1 |
| 208 | + spec: |
| 209 | + language: python |
| 210 | + framework: django |
| 211 | + repo: |
| 212 | + url: github.com/ironcore864/myapp1 |
| 213 | + repoTemplate: |
| 214 | + url: github.com/devstream-io/dtm-scaffolding-python |
| 215 | + ci: |
| 216 | + - type: githubactions |
| 217 | + cd: |
| 218 | + - type: argocdapp |
| 219 | +``` |
| 220 | + |
| 221 | +--- |
| 222 | + |
| 223 | +## 6 Pipeline Templates |
| 224 | + |
| 225 | +You can define some pipeline templates in the pipelineTemplates section: |
| 226 | + |
| 227 | +```yaml |
| 228 | +pipelineTemplates: |
| 229 | +- name: ci-pipeline-1 |
| 230 | + type: githubactions # corresponds to a DevStream plugin |
| 231 | + options: |
| 232 | + branch: main # optional |
| 233 | + docker: |
| 234 | + registry: |
| 235 | + type: dockerhub |
| 236 | + username: [[ dockerUser ]] |
| 237 | + repository: [[ app ]] |
| 238 | +- name: cd-pipeline-1 |
| 239 | + type: argocdapp |
| 240 | + options: |
| 241 | + app: |
| 242 | + namespace: argocd |
| 243 | + destination: |
| 244 | + server: https://kubernetes.default.svc |
| 245 | + namespace: default |
| 246 | + source: |
| 247 | + valuefile: values.yaml |
| 248 | + path: helm/[[ app ]] |
| 249 | + repoURL: ${{repo-scaffolding.myapp.outputs.repoURL}} |
112 | 250 | ``` |
113 | 251 |
|
114 | | -### No Defaults for varFile and toolFile |
| 252 | +Then, you can refer to these pipeline templates in the apps file. |
| 253 | + |
| 254 | +--- |
115 | 255 |
|
116 | | -For `varFile` and `toolFile`, no default values are provided. |
| 256 | +## 7 Putting It All Together |
117 | 257 |
|
118 | | -If `varFile` isn't specified in the main config, `dtm` will not use any var files, even if there is already a file named `variables.yaml` under the current directory. |
| 258 | +Here's a complete example: |
119 | 259 |
|
120 | | -Similarly, if `toolFile` isn't specified in the main config, `dtm` will throw an error, even if there is a `tools.yaml` file under the current directory. |
| 260 | +```yaml |
| 261 | +config: |
| 262 | + state: |
| 263 | + backend: local |
| 264 | + options: |
| 265 | + stateFile: devstream.state |
| 266 | +
|
| 267 | +tools: |
| 268 | +- name: helm-installer |
| 269 | + instanceID: argocd |
| 270 | +
|
| 271 | +apps: |
| 272 | +- name: myapp1 |
| 273 | + spec: |
| 274 | + language: python |
| 275 | + framework: django |
| 276 | + repo: |
| 277 | + url: github.com/ironcore864/myapp1 |
| 278 | + repoTemplate: |
| 279 | + url: github.com/devstream-io/dtm-scaffolding-python |
| 280 | + ci: |
| 281 | + - type: githubactions |
| 282 | + cd: |
| 283 | + - type: argocdapp |
| 284 | +``` |
0 commit comments