GitLab + GitLab CI with DTM Tools

DevStream has two abstractions: Tools and Apps.

The previous use case uses Apps. We can also achieve the same result with Tools, and here’s how:

ENV Vars

The following environment variables are required for this to work:

Bash

  1. export GITLAB_TOKEN="YOUR_GITLAB_TOKEN"
  2. export IMAGE_REPO_PASSWORD="YOUR_DOCKERHUB_TOKEN_HERE"

Config File

YAML

  1. config:
  2. state:
  3. backend: local
  4. options:
  5. stateFile: devstream.state
  6. vars:
  7. gitlabUser: YOUR_GITLAB_USERNAME
  8. dockerUser: YOUR_DOCKERHUB_USERNAME
  9. app: testapp
  10. tools:
  11. - name: helm-installer
  12. instanceID: argocd
  13. - name: repo-scaffolding
  14. instanceID: myapp
  15. options:
  16. destinationRepo:
  17. owner: [[ gitlabUser ]]
  18. name: [[ app ]]
  19. branch: master
  20. scmType: gitlab
  21. # set env GITLAB_TOKEN
  22. token: [[ env GITLAB_TOKEN ]]
  23. sourceRepo:
  24. org: devstream-io
  25. name: dtm-repo-scaffolding-python-flask
  26. scmType: github
  27. - name: gitlab-ci
  28. instanceID: flask
  29. dependsOn: [ "repo-scaffolding.myapp" ]
  30. options:
  31. scm:
  32. owner: [[ gitlabUser ]]
  33. name: [[ app ]]
  34. branch: master
  35. scmType: gitlab
  36. token: [[ env GITLAB_TOKEN ]]
  37. pipeline:
  38. language:
  39. framework: flask
  40. name: python
  41. imageRepo:
  42. user: [[ dockerUser ]]
  43. # set env IMAGE_REPO_PASSWORD
  44. password: [[ env IMAGE_REPO_PASSWORD ]]
  45. - name: argocdapp
  46. instanceID: default
  47. dependsOn: [ "helm-installer.argocd", "gitlab-ci.flask" ]
  48. options:
  49. app:
  50. name: [[ app ]]
  51. namespace: argocd
  52. destination:
  53. server: https://kubernetes.default.svc
  54. namespace: default
  55. source:
  56. valuefile: values.yaml
  57. path: helm/[[ app ]]
  58. repoURL: ${{repo-scaffolding.myapp.outputs.repoURL}}
  59. token: [[ env GITLAB_TOKEN ]]
  60. imageRepo:
  61. user: [[ dockerUser ]]
  62. password: [[ env IMAGE_REPO_PASSWORD ]]

Update the “YOUR_GITLAB_USERNAME” and “YOUR_DOCKERHUB_USERNAME” in the above file accordingly.

Notes:

Your GitLab must have shared runners to run gitlab-ci, If you want to create a runner automatically, you can refer to gitlab-ci plugin docs about how to generate a runner by DevStream.


Run

First, initialize:

Bash

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

Then we apply it by running:

Bash

  1. dtm apply -f config.yaml -y

Now we can see the repo has been created in GitLab and the image has been uploaded to Dockerhub.

GitLab CI

GitLab CI

In your Kubernetes cluster, the app pod is created in the default namespace.

Bash

  1. $ kubectl get application -n argocd
  2. NAME SYNC STATUS HEALTH STATUS
  3. testapp Synced Healthy
  4. $ kubectl get deploy -n default
  5. NAME READY UP-TO-DATE AVAILABLE AGE
  6. testapp 1/1 1 1 4m27s
  7. $ kubectl get pods -n default
  8. NAME READY STATUS RESTARTS AGE
  9. testapp-5f9c75b4f6-57d9p 1/1 Running 0 3m48s