GitOps with “Apps”

0 Goal

In this tutorial, we will try to use DevStream’s new feature “Apps” to achieve similar result to the GitOps, but using much less configuration, to show the power of “Apps” in the config. If you haven’t read the original GitOps best practice, click the above link first.

Two applications will be created (one Python, one Golang), CI/CD pipelines will be set up for both, and both apps will be deployed via Argo CD, just like the GitOps best practice.


1 Overview

DevStream will use the “Apps” concept to create repositories with scaffolding code, GitHub Actions CI pipelines, install Argo CD, and deploy the apps via Argo CD.


2 Create the Config File

Create a temporary working directory for this tutorial:

Bash

  1. mkdir test
  2. cd test/

Download dtm (see the GitOps best practice if you haven’t).

Then generate the config file by running:

Bash

  1. ./dtm show config --template=apps > config.yaml

Then set the following environment variables by running (replace values within the double quotes):

Bash

  1. export GITHUB_USER="<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN_HERE>"
  2. export DOCKERHUB_USERNAME="<YOUR_DOCKER_HUB_USER_NAME_HERE>"

Then we run the following commands to update our config file with those env vars:

macOS or FreeBSD based systemsGNU Linux users

Bash

  1. sed -i.bak "s@YOUR_GITHUB_USER@${GITHUB_USER}@g" config.yaml
  2. sed -i.bak "s@YOUR_DOCKERHUB_USER@${DOCKERHUB_USERNAME}@g" config.yaml

Bash

  1. sed -i "s@YOUR_GITHUB_USERNAME_CASE_SENSITIVE@${GITHUB_USER}@g" config.yaml
  2. sed -i "s@YOUR_DOCKER_USERNAME@${DOCKERHUB_USERNAME}@g" config.yaml

3 Init and Apply

Run:

Bash

  1. ./dtm init -f config.yaml

This downloads the required plugins, according to the config file, automatically.

Then we apply it by running:

Bash

  1. ./dtm apply -f config.yaml -y

You will see similar outputs as the following:

Bash

  1. tiexin@mbp ~/work/devstream-io/test $ ./dtm apply -f config.yaml -y
  2. 2022-12-16 14:30:27 [INFO] Apply started.
  3. 2022-12-16 14:30:28 [INFO] Using local backend. State file: devstream.state.
  4. 2022-12-16 14:30:28 [INFO] Tool (helm-installer/argocd) found in config but doesn't exist in the state, will be created.
  5. 2022-12-16 14:30:28 ℹ [INFO] Tool (repo-scaffolding/myapp1) found in config but doesn't exist in the state, will be created.
  6. 2022-12-16 14:30:28 [INFO] Tool (repo-scaffolding/myapp2) found in config but doesn't exist in the state, will be created.
  7. 2022-12-16 14:30:28 ℹ [INFO] Tool (github-actions/myapp1) found in config but doesn't exist in the state, will be created.
  8. 2022-12-16 14:30:28 [INFO] Tool (argocdapp/myapp1) found in config but doesn't exist in the state, will be created.
  9. 2022-12-16 14:30:28 ℹ [INFO] Tool (github-actions/myapp2) found in config but doesn't exist in the state, will be created.
  10. 2022-12-16 14:30:28 [INFO] Tool (argocdapp/myapp2) found in config but doesn't exist in the state, will be created.
  11. 2022-12-16 14:30:28 ℹ [INFO] Start executing the plan.
  12. 2022-12-16 14:30:28 ℹ [INFO] Changes count: 7.
  13. 2022-12-16 14:30:28 ℹ [INFO] -------------------- [ Processing progress: 1/7. ] --------------------
  14. 2022-12-16 14:30:28 ℹ [INFO] Processing: (helm-installer/argocd) -> Create ...
  15. 2022-12-16 14:30:29 ℹ [INFO] Filling default config with instance: argocd.
  16. 2022-12-16 14:30:29 ℹ [INFO] Creating or updating helm chart ...
  17. ... (omitted)
  18. ... (omitted)
  19. 2022-12-16 14:32:09 ℹ [INFO] -------------------- [ Processing progress: 7/7. ] --------------------
  20. 2022-12-16 14:32:09 ℹ [INFO] Processing: (argocdapp/myapp2) -> Create ...
  21. 2022-12-16 14:32:19 ℹ [INFO] application.argoproj.io/myapp2 created
  22. 2022-12-16 14:32:19 ✔ [SUCCESS] Tool (argocdapp/myapp2) Create done.
  23. 2022-12-16 14:32:19 ℹ [INFO] -------------------- [ Processing done. ] --------------------
  24. 2022-12-16 14:32:19 ✔ [SUCCESS] All plugins applied successfully.
  25. 2022-12-16 14:32:19 ✔ [SUCCESS] Apply finished.

4 Check the Results

Let’s continue to look at the results of the apply command.

Similar to what we did in the GitOps best practice, we can check that repositories for two applications are created, CI pipelins are created for both apps too, Argo CD is installed, and both apps are deployed by Argo CD into our Kubernetes cluster.


5 Clean Up

Run:

Bash

  1. ./dtm delete -f config.yaml -y

And you will get similar outputs to the following:

Bash

  1. 2022-12-16 14:34:30 [INFO] Delete started.
  2. 2022-12-16 14:34:31 [INFO] Using local backend. State file: devstream.state.
  3. 2022-12-16 14:34:31 [INFO] Tool (github-actions/myapp1) will be deleted.
  4. 2022-12-16 14:34:31 [INFO] Tool (argocdapp/myapp1) will be deleted.
  5. 2022-12-16 14:34:31 [INFO] Tool (github-actions/myapp2) will be deleted.
  6. 2022-12-16 14:34:31 [INFO] Tool (argocdapp/myapp2) will be deleted.
  7. 2022-12-16 14:34:31 [INFO] Tool (repo-scaffolding/myapp1) will be deleted.
  8. 2022-12-16 14:34:31 [INFO] Tool (repo-scaffolding/myapp2) will be deleted.
  9. 2022-12-16 14:34:31 [INFO] Tool (helm-installer/argocd) will be deleted.
  10. 2022-12-16 14:34:31 [INFO] Start executing the plan.
  11. 2022-12-16 14:34:31 [INFO] Changes count: 7.
  12. 2022-12-16 14:34:31 [INFO] -------------------- [ Processing progress: 1/7. ] --------------------
  13. 2022-12-16 14:34:31 [INFO] Processing: (github-actions/myapp1) -> Delete ...
  14. 2022-12-16 14:34:33 [INFO] Prepare to delete 'github-actions_myapp1' from States.
  15. 2022-12-16 14:34:33 [SUCCESS] Tool (github-actions/myapp1) delete done.
  16. ... (omitted)
  17. ... (omitted)
  18. 2022-12-16 14:34:40 [SUCCESS] Tool (helm-installer/argocd) delete done.
  19. 2022-12-16 14:34:40 [INFO] -------------------- [ Processing done. ] --------------------
  20. 2022-12-16 14:34:40 [SUCCESS] All plugins deleted successfully.
  21. 2022-12-16 14:34:40 [SUCCESS] Delete finished.

Then you can delete what we created:

Bash

  1. cd ../
  2. rm -rf test/
  3. rm -rf ~/.devstream/