用 DTM Tools 实现基于 GitHub,Argo CD 和 GitHub Actions 的 CICD 流程

DevStream 抽象了2个概念:ToolsApps

前一个用户场景 里介绍了 “Apps”,你可以用 “Tools” 实现一样的效果。具体方法如下:

环境变量

你需要先设置如下环境变量:

Bash

  1. export GITHUB_TOKEN="YOUR_GITHUB_TOKEN_HERE"
  2. export IMAGE_REPO_PASSWORD="YOUR_DOCKERHUB_TOKEN_HERE"

配置文件

YAML

  1. config:
  2. state:
  3. backend: local
  4. options:
  5. stateFile: devstream.state
  6. vars:
  7. GITHUB_USER: YOUR_GITHUB_USER
  8. DOCKERHUB_USER: YOUR_DOCKERHUB_USER
  9. tools:
  10. - name: repo-scaffolding
  11. instanceID: myapp1
  12. options:
  13. destinationRepo:
  14. owner: [[ GITHUB_USER ]]
  15. name: myapp1
  16. branch: main
  17. scmType: github
  18. token: [[ env GITHUB_TOKEN ]]
  19. sourceRepo:
  20. org: devstream-io
  21. name: dtm-repo-scaffolding-python-flask
  22. scmType: github
  23. - name: github-actions
  24. instanceID: flask
  25. dependsOn: [ repo-scaffolding.myapp1 ]
  26. options:
  27. scm:
  28. owner: [[ GITHUB_USER ]]
  29. name: myapp1
  30. scmType: github
  31. token: [[ env GITHUB_TOKEN ]]
  32. pipeline:
  33. configLocation: https://raw.githubusercontent.com/devstream-io/dtm-pipeline-templates/main/github-actions/workflows/main.yml
  34. language:
  35. name: python
  36. framework: flask
  37. imageRepo:
  38. user: [[ DOCKERHUB_USER ]]
  39. password: [[ env IMAGE_REPO_PASSWORD ]]
  40. - name: helm-installer
  41. instanceID: argocd
  42. - name: argocdapp
  43. instanceID: default
  44. dependsOn: [ "helm-installer.argocd", "github-actions.flask" ]
  45. options:
  46. app:
  47. name: myapp1
  48. namespace: argocd
  49. destination:
  50. server: https://kubernetes.default.svc
  51. namespace: default
  52. source:
  53. valuefile: values.yaml
  54. path: helm/myapp1
  55. repoURL: ${{repo-scaffolding.myapp1.outputs.repoURL}}
  56. token: [[ env GITHUB_TOKEN ]]
  57. imageRepo:
  58. user: [[ DOCKERHUB_USER ]]

你需要相应更新上述配置文件里的 “YOUR_GITHUB_USER” 和 “YOUR_DOCKERHUB_USER”。


运行

首先需要初始化:

Bash

  1. # this downloads the required plugins, according to the config file, automatically.
  2. dtm init -f config.yaml

然后运行如下命令让配置生效:

Bash

  1. dtm apply -f config.yaml -y

(省略了动图和视频等)