|
1 | 1 | # GitLab + GitLab CI with DTM Tools |
2 | 2 |
|
3 | | -TODO |
| 3 | +DevStream has two abstractions: [Tools](../../core-concepts/tools.md) and [Apps](../../core-concepts/apps.md). |
| 4 | + |
| 5 | +[The previous use case](./4-gitlab-dtm-apps.md) uses `Apps`. We can also achieve the same result with `Tools`, and here's how: |
| 6 | + |
| 7 | +## ENV Vars |
| 8 | + |
| 9 | +The following environment variables are required for this to work: |
| 10 | + |
| 11 | +```bash |
| 12 | +export GITLAB_TOKEN="YOUR_GITLAB_TOKEN" |
| 13 | +export IMAGE_REPO_PASSWORD="YOUR_DOCKERHUB_TOKEN_HERE" |
| 14 | +``` |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Config File |
| 19 | + |
| 20 | +```yaml |
| 21 | +config: |
| 22 | + state: |
| 23 | + backend: local |
| 24 | + options: |
| 25 | + stateFile: devstream.state |
| 26 | + |
| 27 | +vars: |
| 28 | + gitlabUser: YOUR_GITLAB_USERNAME |
| 29 | + dockerUser: YOUR_DOCKERHUB_USERNAME |
| 30 | + app: testapp |
| 31 | + |
| 32 | +tools: |
| 33 | +- name: helm-installer |
| 34 | + instanceID: argocd |
| 35 | +- name: repo-scaffolding |
| 36 | + instanceID: myapp |
| 37 | + options: |
| 38 | + destinationRepo: |
| 39 | + owner: [[ gitlabUser ]] |
| 40 | + name: [[ app ]] |
| 41 | + branch: master |
| 42 | + scmType: gitlab |
| 43 | + # set env GITLAB_TOKEN |
| 44 | + token: [[ env GITLAB_TOKEN ]] |
| 45 | + sourceRepo: |
| 46 | + org: devstream-io |
| 47 | + name: dtm-repo-scaffolding-python-flask |
| 48 | + scmType: github |
| 49 | +- name: gitlab-ci |
| 50 | + instanceID: flask |
| 51 | + dependsOn: [ "repo-scaffolding.myapp" ] |
| 52 | + options: |
| 53 | + scm: |
| 54 | + owner: [[ gitlabUser ]] |
| 55 | + name: [[ app ]] |
| 56 | + branch: master |
| 57 | + scmType: gitlab |
| 58 | + token: [[ env GITLAB_TOKEN ]] |
| 59 | + pipeline: |
| 60 | + language: |
| 61 | + framework: flask |
| 62 | + name: python |
| 63 | + imageRepo: |
| 64 | + user: [[ dockerUser ]] |
| 65 | + # set env IMAGE_REPO_PASSWORD |
| 66 | + password: [[ env IMAGE_REPO_PASSWORD ]] |
| 67 | +- name: argocdapp |
| 68 | + instanceID: default |
| 69 | + dependsOn: [ "helm-installer.argocd", "gitlab-ci.flask" ] |
| 70 | + options: |
| 71 | + app: |
| 72 | + name: [[ app ]] |
| 73 | + namespace: argocd |
| 74 | + destination: |
| 75 | + server: https://kubernetes.default.svc |
| 76 | + namespace: default |
| 77 | + source: |
| 78 | + valuefile: values.yaml |
| 79 | + path: helm/[[ app ]] |
| 80 | + repoURL: ${{repo-scaffolding.myapp.outputs.repoURL}} |
| 81 | + token: [[ env GITLAB_TOKEN ]] |
| 82 | + imageRepo: |
| 83 | + user: [[ dockerUser ]] |
| 84 | + password: [[ env IMAGE_REPO_PASSWORD ]] |
| 85 | +``` |
| 86 | +
|
| 87 | +Update the "YOUR_GITLAB_USERNAME" and "YOUR_DOCKERHUB_USERNAME" in the above file accordingly. |
| 88 | +
|
| 89 | +**Notes:** |
| 90 | +
|
| 91 | +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](../../plugins/gitlab-ci.md) about how to generate a runner by `DevStream`. |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## Run |
| 96 | + |
| 97 | +First, initialize: |
| 98 | + |
| 99 | +```bash |
| 100 | +# this downloads the required plugins, according to the config file, automatically. |
| 101 | +dtm init -f config.yaml |
| 102 | +``` |
| 103 | + |
| 104 | +Then we apply it by running: |
| 105 | + |
| 106 | +```bash |
| 107 | +dtm apply -f config.yaml -y |
| 108 | +``` |
| 109 | + |
| 110 | +Now we can see the repo has been created in `GitLab` and the image has been uploaded to `Dockerhub`. |
| 111 | + |
| 112 | +<figure markdown> |
| 113 | + { width="1000" } |
| 114 | + <figcaption>GitLab CI</figcaption> |
| 115 | +</figure> |
| 116 | + |
| 117 | +In your `Kubernetes` cluster, the app pod is created in the default namespace. |
| 118 | + |
| 119 | +```bash |
| 120 | +$ kubectl get application -n argocd |
| 121 | +NAME SYNC STATUS HEALTH STATUS |
| 122 | +testapp Synced Healthy |
| 123 | +$ kubectl get deploy -n default |
| 124 | +NAME READY UP-TO-DATE AVAILABLE AGE |
| 125 | +testapp 1/1 1 1 4m27s |
| 126 | +$ kubectl get pods -n default |
| 127 | +NAME READY STATUS RESTARTS AGE |
| 128 | +testapp-5f9c75b4f6-57d9p 1/1 Running 0 3m48s |
| 129 | +``` |
0 commit comments