|
1 | | -# GitHub + GitHub Actions with DTM Tools |
| 1 | +# 用 DTM Tools 实现基于 GitHub,Argo CD 和 GitHub Actions 的 CICD 流程 |
2 | 2 |
|
3 | | -TODO |
| 3 | +DevStream 抽象了2个概念:[Tools](../../core-concepts/tools.md) 和 [Apps](../../core-concepts/apps.md)。 |
| 4 | + |
| 5 | +在[前一个用户场景](./2-github-dtm-apps.md) 里介绍了 "Apps",你可以用 "Tools" 实现一样的效果。具体方法如下: |
| 6 | + |
| 7 | +## 环境变量 |
| 8 | + |
| 9 | +你需要先设置如下环境变量: |
| 10 | + |
| 11 | +```bash |
| 12 | +export GITHUB_TOKEN="YOUR_GITHUB_TOKEN_HERE" |
| 13 | +export IMAGE_REPO_PASSWORD="YOUR_DOCKERHUB_TOKEN_HERE" |
| 14 | +``` |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## 配置文件 |
| 19 | + |
| 20 | +```yaml |
| 21 | +config: |
| 22 | + state: |
| 23 | + backend: local |
| 24 | + options: |
| 25 | + stateFile: devstream.state |
| 26 | + |
| 27 | +vars: |
| 28 | + GITHUB_USER: YOUR_GITHUB_USER |
| 29 | + DOCKERHUB_USER: YOUR_DOCKERHUB_USER |
| 30 | + |
| 31 | +tools: |
| 32 | +- name: repo-scaffolding |
| 33 | + instanceID: myapp1 |
| 34 | + options: |
| 35 | + destinationRepo: |
| 36 | + owner: [[ GITHUB_USER ]] |
| 37 | + name: myapp1 |
| 38 | + branch: main |
| 39 | + scmType: github |
| 40 | + token: [[ env GITHUB_TOKEN ]] |
| 41 | + sourceRepo: |
| 42 | + org: devstream-io |
| 43 | + name: dtm-repo-scaffolding-python-flask |
| 44 | + scmType: github |
| 45 | +- name: github-actions |
| 46 | + instanceID: flask |
| 47 | + dependsOn: [ repo-scaffolding.myapp1 ] |
| 48 | + options: |
| 49 | + scm: |
| 50 | + owner: [[ GITHUB_USER ]] |
| 51 | + name: myapp1 |
| 52 | + scmType: github |
| 53 | + token: [[ env GITHUB_TOKEN ]] |
| 54 | + pipeline: |
| 55 | + configLocation: https://raw.githubusercontent.com/devstream-io/dtm-pipeline-templates/main/github-actions/workflows/main.yml |
| 56 | + language: |
| 57 | + name: python |
| 58 | + framework: flask |
| 59 | + imageRepo: |
| 60 | + user: [[ DOCKERHUB_USER ]] |
| 61 | + password: [[ env IMAGE_REPO_PASSWORD ]] |
| 62 | +- name: helm-installer |
| 63 | + instanceID: argocd |
| 64 | +- name: argocdapp |
| 65 | + instanceID: default |
| 66 | + dependsOn: [ "helm-installer.argocd", "github-actions.flask" ] |
| 67 | + options: |
| 68 | + app: |
| 69 | + name: myapp1 |
| 70 | + namespace: argocd |
| 71 | + destination: |
| 72 | + server: https://kubernetes.default.svc |
| 73 | + namespace: default |
| 74 | + source: |
| 75 | + valuefile: values.yaml |
| 76 | + path: helm/myapp1 |
| 77 | + repoURL: ${{repo-scaffolding.myapp1.outputs.repoURL}} |
| 78 | + token: [[ env GITHUB_TOKEN ]] |
| 79 | + imageRepo: |
| 80 | + user: [[ DOCKERHUB_USER ]] |
| 81 | +``` |
| 82 | +
|
| 83 | +你需要相应更新上述配置文件里的 "YOUR_GITHUB_USER" 和 "YOUR_DOCKERHUB_USER"。 |
| 84 | +
|
| 85 | +--- |
| 86 | +
|
| 87 | +## 运行 |
| 88 | +
|
| 89 | +首先需要初始化: |
| 90 | +
|
| 91 | +```bash |
| 92 | +# this downloads the required plugins, according to the config file, automatically. |
| 93 | +dtm init -f config.yaml |
| 94 | +``` |
| 95 | + |
| 96 | +<script id="asciicast-EMzx8lzZq5AJpAMoJY23fh8A3" src="https://asciinema.org/a/EMzx8lzZq5AJpAMoJY23fh8A3.js" async></script> |
| 97 | + |
| 98 | +然后运行如下命令让配置生效: |
| 99 | + |
| 100 | +```bash |
| 101 | +dtm apply -f config.yaml -y |
| 102 | +``` |
| 103 | + |
| 104 | +(省略了动图和视频等) |
0 commit comments