GitOps Toolchain

If you are interested in watching a video demo, see the youtube video below:

https://www.youtube.com/watch?v=q7TK3vFr1kg

For Chinese readers, watch this one instead:

https://www.bilibili.com/video/BV1W3411P7oW/

Plugins needed

  1. github-repo-scaffolding-golang
  2. jira-github
  3. githubactions-golang
  4. argocd
  5. argocdapp

The dependencies of these plugins are(a -> b means for a depends on b):

  • jira-github -> github-repo-scaffolding-golang
  • githubactions-golang -> github-repo-scaffolding-golang
  • argocdapp -> argocd and github-repo-scaffolding-golang

Note: These dependencies are not consistent, such as when the repo operated by jira-github and github-repo-scaffolding-golang are not the same, the dependencies disappear.

We should use the dependency according to the actual usage situation.

Download DevStream (dtm)

Download the appropriate dtm version for your platform from DevStream Releases.

Remember to rename the binary file to dtm so that it’s easier to use. For example: mv dtm-darwin-arm64 dtm.

Once downloaded, you can run the binary from anywhere. Ideally, you want to put it in a place that is in your PATH (e.g., /usr/local/bin).

Prepare the Config File

Download the gitops.yaml, tools-gitops.yaml and variables-gitops.yaml to your working directory:

  1. curl -o config-gitops.yaml https://raw.githubusercontent.com/devstream-io/devstream/main/examples/gitops.yaml
  2. curl -o variables-gitops.yaml https://raw.githubusercontent.com/devstream-io/devstream/main/examples/variables-gitops.yaml
  3. curl -o tools-gitops.yaml https://raw.githubusercontent.com/devstream-io/devstream/main/examples/tools-gitops.yaml

Then modify the variables-gitops.yaml file accordingly.

For me I can set these variables like:

VariableExampleNote
defaultBranchmainThe branch name you want to use
githubUsernamedaniel-hutaoIt should be case-sensitive here; strictly use your GitHub username
repoNamego-webappAs long as it doesn’t exist in your GitHub account and the name is legal
dockerhubUsernameexploithtIt should be case-sensitive here; strictly use your DockerHub username
jiraIDmericoThis is a domain name prefix like merico in https://merico.atlassian.net
jiraProjectKeyDTA descriptive prefix for your project’s issue keys to recognize work from this project
jiraUserEmailtao.hu@merico.devThe email you use to log in to Jira
argocdNameSpaceargocdThe namespace used by ArgoCD
argocdDeployTimeout10mHow long does ArgoCD deployment timeout

These plugins require some environment variables to work, so let’s set them:

  1. export GITHUB_TOKEN="YOUR_GITHUB_TOKEN_HERE"
  2. export JIRA_API_TOKEN="YOUR_JIRA_API_TOKEN_HERE"
  3. export DOCKERHUB_TOKEN="YOUR_DOCKERHUB_TOKEN_HERE"

If you don’t know how to create these three tokens, check out:

3. Initialize

Run:

  1. dtm init -f config-gitops.yaml

4. Apply

Run:

  1. dtm apply -f config-gitops.yaml

and confirm to continue, then you should see similar output to:

  1. ...
  2. 2022-03-11 13:36:11 [SUCCESS] All plugins applied successfully.
  3. 2022-03-11 13:36:11 [SUCCESS] Apply finished.

5. Check the Results

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

5.1 Repository Scaffolding

  • The repository scaffolding we got looks like this:

GitOps Toolchain - 图1

5.2 Jira-Github Integration

  • How do Jira and Github integrate? Let’s create a new issue:

GitOps Toolchain - 图2

  • The issue will be renamed automatically like this:

GitOps Toolchain - 图3

  • We can find this auto-synced Story in Jira:

GitOps Toolchain - 图4

  • If we continue to leave a comment on this issue:

GitOps Toolchain - 图5

  • The comment will also be automatically synced to Jira:

GitOps Toolchain - 图6

5.3 GitHub Actions CI for Golang

  • What does CI do here?

GitOps Toolchain - 图7

  • The CI processes also build an image, and this image is automatically pushed to DockerHub:

GitOps Toolchain - 图8

5.4 ArgoCD Deployment

  • Of course, the ArgoCD must have been installed as expected.

GitOps Toolchain - 图9

5.5 ArgoCD Application Deployment

  • Our code has just been built into an image, at this time the image is automatically deployed to our k8s as a Pod:

GitOps Toolchain - 图10

6. Clean Up

Run:

  1. dtm destroy

and you should see similar output:

  1. 2022-03-11 13:39:11 [SUCCESS] All plugins destroyed successfully.
  2. 2022-03-11 13:39:11 [SUCCESS] Destroy finished.