Apps

1 Concept

An app in DevStream corresponds to a real-world application, and the app represents the whole software development lifecycle of that app, including source code management, code scaffolding, CI/CD (and their pipelines).

Using “App”, you can easily create these for an application.

1.1 Apps

There are situations where you need to define multiple DevOps tools for an application/microservice. For example, for a web-app typed microservice, you might need the following:

  • source code management, code repo scaffolding
  • continuous integration (the installation of the DevOps tool, the creation of the CI pipeline)
  • continuous deployment (the installation of the DevOps tool, the creation of the CD pipeline)

If you are managing more than one application/microservice (chances are, you will be managing more than one application in the real world), the configuration of DevStream can be quite long, hard to read and hard to manage if you are only using “Tools”.

In order to solve this problem, DevStream provides another concept that is “App”. You can easily define all DevOps tools and pipelines for an App with a couple of lines of YAML config, making the config file much easier to read and manage.

In essence, “App” will be converted to “Tool”, which you do not have to worry about at all; let DevStream handle that.

1.2 pipelineTemplates

pipelineTemplates define CI/CD pipelines, so that they can be referred to and shared by different DevStream Apps, reducing the length of the config file to the next level.

2 Config

2.1 App

In the config, there is a apps section, which is a list, with each element having the following keys:

  • name: the name of the app, unique
  • spec: application-specific information
  • repo: info about the code repository
  • repoTemplate: optional, same structure as “repo”. If empty, DevStream will create/scaffold a repository from scratch.
  • ci: optional, a list of CI pipelines, each element can have the following keys:
    • type: the value can be a template or the name of a plugin
    • templateName: optional, if type is template, it defines which pipelineTemplate to use
    • vars: optional, variables to be passed to the template. Only works when type is template, apparently
    • options: optional
      • if type is the name of a plugin, the options are the options of that plugin
      • if type is template, the options here will override the ones in the template. Use full path to override, for example, options.docker.registry.type
  • cd: like ci, but stands for the list of CD pipelines. DevStream will execute CI first before CD

2.2 pipelineTemplate

Defined in the pipelineTemplates of the config, it’s a list, with each element having the following keys:

  • name: unique name of the pipelineTemplate, unique
  • type: corresponds to a plugin’s name
  • options: options for that plugin

2.3 Local Variables

DevStream has a “var” section in the config, serving as global variables that can be referred to by all Tools and Apps.

Sometimes, however, we’d like to use the same DevOps tool with minor differences. For example, except the name of the project, everything else is different.

In this case, we can define a pipelineTemplate with a local variable, and when referring to it, we can pass different values to it:

pipelineTemplate and local variables

  1. apps:
  2. - name: my-app
  3. spec:
  4. language: java
  5. framework: springboot
  6. repo:
  7. url: https://github.com/testUser/testApp.git
  8. branch: main
  9. ci:
  10. - type: github-actions # use a plugin directly without defining pipelineTemplates
  11. cd:
  12. - type: template # use a pipelineTemplate
  13. templateName: my-cd-template # corresponds to the name of the pipelineTemplate
  14. vars:
  15. appName: my-app # a local variable passed to the pipelineTemplate
  16. pipelineTemplates:
  17. cd:
  18. - name: my-cd-template
  19. type: argocdapp
  20. options:
  21. app:
  22. name: [[ appName ]] # a local variable, passed to when referring to the template
  23. namespace: argocd
  24. destination:
  25. server: https://kubernetes.default.svc
  26. namespace: default
  27. source:
  28. valuefile: values.yaml
  29. path: charts/[[ appName ]]

3 A Demo of the Whole Config

A whole config for an App:

YAML

  1. apps:
  2. - name: testApp # name of the app
  3. spec: # app-specific info
  4. language: java # programming language of the app
  5. framework: springboot # framework of the app
  6. repo: # repository-related info for the app
  7. url: https://github.com/testUser/testApp.git
  8. branch: main
  9. repoTemplate: # optional, used for repository bootstrapping/scaffolding. If not empty, a repo will be created with scaffolding code
  10. url: https://github.com/devstream-io/dtm-repo-scaffolding-java-springboot.git
  11. vars:
  12. imageRepoOwner: repoOwner # variables used for repoTemplate
  13. ci: # CI pipelines, here we use github-actions
  14. - type: github-actions
  15. - name: testApp2
  16. spec:
  17. language: go
  18. framework: gin
  19. repo: # repository-related info for the app
  20. owner: test_user
  21. type: github
  22. branch: main
  23. repoTemplate: # optional, used for repository bootstrapping/scaffolding. If not empty, a repo will be created with scaffolding code
  24. org: devstream-io
  25. name: dtm-repo-scaffolding-java-springboot
  26. type: github
  27. ci: # CI pipelines, here we use github-actions
  28. - type: github-actions
  29. options:
  30. imageRepo:
  31. owner: repoOwner # override the plugin's options. Must use full YAML path.
  32. cd: # CD pipelines, here we use argocd
  33. - type: argocdapp

If we apply this config, DevStream will create two repositories in GitHub, with scaffolding code provided by DevStream SpringBoot. App testApp will trigger CI in GitHub Actions upon each commit, and App testApp2 will trigger build/push in GitHub Actions upon commit, and deploy using Argo CD.

repo/repoTemplate Config

The repo and repoTemplate in the Config represent a code repository. You can define it with a single URL or a few key/values:

two ways to configure code repo

using a single URLusing detailed key/value config for the repo

  1. repo:
  2. url: git@gitlab.example.com:root/myapps.git # repo URL, supports both git and https
  3. apiURL: https://gitlab.example.com # not mandatory, if using gitlab and the URL protocol is git, here can be the GitLab API URL
  4. branch: "" # not mandatory, defaults to main for GitHub and master for GitLab

This example shows that we use GitLab git@gitlab.example.com:root/myapps.git for code clone, and DevStream uses https://gitlab.example.com to access GitLab API. Default branch is master.

  1. repo:
  2. org: "" # only mandatory for GitHub organization
  3. owner"test_user" # if the repo belongs to a person. If the repo belongs to an org, use the org above.
  4. name: "" # optional, defaults to the name of the app
  5. baseURL: https://gitlab.example.com # optional. If GitLab, here we can put the GitLab domain.
  6. branch: master # not mandatory, defaults to main for GitHub and master for GitLab
  7. type: gitlab # mandatory, either gitlab or github

This example shows that we use GitLab https://gitlab.example.com, repo name is the app name, belongs to owner test_user, with the default branch being “master”.

CI Config

The CI section in the config supports 4 types at the moment: github-actions/gitlab-ci/jenkins-pipeline/template.

template means to use a pipelineTemplate; and the other three types correspond to GitHub Actions, GitLab CI, and Jenkins, respectively.

Detailed config:

YAML

  1. ci:
  2. - type: jenkins-pipieline # type of the CI
  3. options: # options for CI. If empty, CI will only run unit test.
  4. jenkins: # config for jenkins
  5. url: jenkins.exmaple.com # jenkins URL
  6. user: admin # jenkins user
  7. imageRepo: # docker image repo to be pushed to. If set, Ci will push the image after build.
  8. url: http://harbor.example.com # image repo URL. Defaults to dockerhub.
  9. owner: admin # image repo owner
  10. dingTalk: # dingtalk notification settings. If set, CI result will be pushed to dingtalk.
  11. name: dingTalk
  12. webhook: https://oapi.dingtalk.com/robot/send?access_token=changemeByConfig # callback URL for dingtalk.
  13. securityType: SECRET # use secret to encrypt dingtalk message
  14. securityValue: SECRETDATA # dingtalk secret encryption data
  15. sonarqube: # sonarqube config. If set, CI will test and execute sonarqube scan.
  16. url: http://sonar.example.com # sonarqube URL
  17. token: YOUR_SONAR_TOKEN # soanrqube token
  18. name: sonar_test

The config above will trigger unit test and sonarqube code scan upon commit, then a Docker image will be built and pushed to dockerhub, and the result of the CI will be pushed to dingtalk.

If the same pipeline is required for multiple apps, the config can be long and redundant. So, DevStream provides the template type to share similar settings for diffrent Apps. Detailed example:

YAML

  1. apps:
  2. - name: javaProject1
  3. spec:
  4. language: java
  5. framework: springboot
  6. repo:
  7. owner: testUser
  8. type: github
  9. repoTemplate:
  10. url: https://github.com/devstream-io/dtm-repo-scaffolding-java-springboot.git
  11. ci:
  12. - type: template # use a pipelineTemplate
  13. templateName: ci-pipeline # name of the pipelineTemplate
  14. vars:
  15. dingdingAccessToken: tokenForProject1 # variables for the pipelineTemplate
  16. dingdingSecretValue: secretValProject1
  17. - name: javaProject2
  18. spec:
  19. language: java
  20. framework: springboot
  21. repo:
  22. owner: testUser
  23. type: github
  24. repoTemplate:
  25. url: https://github.com/devstream-io/dtm-repo-scaffolding-java-springboot.git
  26. ci:
  27. - type: template # use a pipelineTemplate
  28. templateName: ci-pipeline # name of the pipelineTemplate
  29. vars:
  30. dingdingAccessToken: tokenForProject2 # variables for the pipelineTemplate
  31. dingdingSecretValue: secretValProject2
  32. pipelineTemplates: # CI/CD pipeline templates
  33. - name: ci-pipeline # name of the pipelineTemplate
  34. type: jenkins-pipeline # type, supports jenkins-pipeline,github-actions and gitlab-ci at the moment
  35. options: # options, same as CI options
  36. jenkins:
  37. url: jenkins.exmaple.com
  38. user: admin
  39. imageRepo:
  40. url: http://harbor.example.com
  41. owner: admin
  42. dingTalk:
  43. name: dingTalk
  44. webhook: https://oapi.dingtalk.com/robot/send?access_token=[[ dingdingAccessToken ]] # local variable, passed to when referring to this template
  45. securityType: SECRET
  46. securityValue: [[ dingdingSecretValue ]] # local variable, passed to when referring to this template
  47. sonarqube:
  48. url: http://sonar.example.com
  49. token: sonar_token
  50. name: sonar_test

If we apply the above config, we will create two Jenkins pipelines for two apps, with the only difference being that the dingtalk notification will be sent to different groups.

CD Config

At the moment, CD only supports argocdapp. Argo CD itself can be deployed with a Tool, and argocdapp is responsible for deploying the app in a Kubernetes cluster.

Detailed config example:

YAML

  1. cd:
  2. - type: argocdapp
  3. options:
  4. app:
  5. name: hello # argocd app name
  6. namespace: argocd # argocd namespace
  7. destination:
  8. server: https://kubernetes.default.svc # Kubernetes cluster
  9. namespace: default # which namespace to deploy the app
  10. source:
  11. valuefile: values.yaml # helm values file
  12. path: charts/go-hello-http # helm chart path