Skip to content

Commit 6552570

Browse files
committed
docs: gitops usecase py flask gh actions dtm apps
Signed-off-by: Tiexin Guo <[email protected]>
1 parent 54016e8 commit 6552570

File tree

11 files changed

+137
-4
lines changed

11 files changed

+137
-4
lines changed

docs/images/gitops-workflow.png

565 KB
Loading
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Overview
2+
3+
## Is This for Me?
4+
5+
- Are you creating a web application/backend API microservice?
6+
- Are you using GitHub to store your source code?
7+
- Are you eager to deploy your service fast and automatically in your development/test environment to have your work up and running in no time?
8+
9+
If the answers to these questions are all "YES", the combo "GitHub Actions + Argo CD + Python + Flask" might just be the right tools for you.
10+
11+
To be more specific, read on.
12+
13+
---
14+
15+
## Is This Really for Me?
16+
17+
This combo, "GitHub + GitHub Actions + Argo CD + Python + Flask" (could also be GitLab + GitLab CI), if installed/managed/integrated properly, might form the best DevOps platform for you, if:
18+
19+
- You choose GitHub as your source code management (SCM) system. It can be either:
20+
- GitHub cloud, or
21+
- GitHub Enterprise (on-premise)
22+
- Since you are using GitHub as SCM and CI interacts a lot with code repositories, using GitHub Actions as your choice of CI is convenient.
23+
- You can, of course, choose other CI, such as Travis CI, CircleCI, etc., which require a little integration with GitHub; while using GitHub Actions, there is essentially little to no integration required.
24+
- Plus, many users are already using it, so if you meet some issues while using it, chances are others have already met them, and you can easily find the solution based on a simple Google search.
25+
- You want fast and automatic deployment in your development environment.
26+
- GitOps might be the best choice for you because it's fast and automatic.
27+
- You don't have many environments, which eliminates some tricky issues like version propagation you might have if you use GitOps with many environments.
28+
- You want to build some backend API-typed applications.
29+
- According to one popularity ranking, Python is now the most popular programming language in the world. Programming languages' popularity rises and falls over time, of course. But according to [TIOBE](https://www.tiobe.com/tiobe-index/), a Dutch software quality assurance company, which has been tracking the popularity of programming languages, notes that "for the first time in more than 20 years, we have a new leader of the pack: the Python programming language. The long-standing hegemony of Java and C is over." While Python might not be the perfect choice in every case, when you don't have all the necessary information and must make a guess, choosing the most popular language won't be the worst idea.
30+
- Flask is a small and lightweight Python web framework that provides valuable tools, including a fast debugger, a built-in development server, and features that make creating web applications in Python easy.
31+
32+
---
33+
34+
## The Big Picture (Literally)
35+
36+
We want to build a DevOps platform around these tools, and what this platform can do could be complicated.
37+
38+
A picture is worth a thousand words:
39+
40+
![](../../images/gitops-workflow.png)
41+
42+
If you still prefer words to pictures (I know some people do), here's the story we want to implement:
43+
44+
- A repository is created automatically in your GitHub account, with generated code (a Python Flask app, with Dockerfile and helm chart and stuff).
45+
- Continuous integration (CI) pipelines created, so that:
46+
- When a pull request is created, a job will be triggered to run unit test.
47+
- When a pull request is merged into the main branch, another job will be triggered to build the Docker image, push it to Dockerhub, and trigger the deployment process
48+
- Argo CD is installed for continuous deployment (CD).
49+
- CD is triggered in a GitOps fashion: when a pull request is merged into the main branch, it deploys the application into the Kubernetes cluster.
50+
51+
OK, then let's just build that.
52+
53+
---
54+
55+
## Prerequisites
56+
57+
1. A working Kubernetes cluster, serving as the infrastructure to deploy tools needed for GitOps, and as well as your development environment.
58+
2. A GitHub account & an access token for API access, and a Dockerhub account & an access token.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# GitHub + GitHub Actions with DTM Apps
2+
3+
## ENV Vars
4+
5+
The following environment variables are required for this to work:
6+
7+
```bash
8+
export GITHUB_TOKEN="YOUR_GITHUB_TOKEN_HERE"
9+
export IMAGE_REPO_PASSWORD="YOUR_DOCKERHUB_TOKEN_HERE"
10+
```
11+
12+
---
13+
14+
## Config File
15+
16+
```yaml
17+
config:
18+
state:
19+
backend: local
20+
options:
21+
stateFile: devstream.state
22+
23+
vars:
24+
GITHUB_USER: YOUR_GITHUB_USER
25+
DOCKERHUB_USER: YOUR_DOCKERHUB_USER
26+
27+
tools:
28+
- name: helm-installer
29+
instanceID: argocd
30+
31+
apps:
32+
- name: myapp1
33+
spec:
34+
language: python
35+
framework: django
36+
repo:
37+
url: github.com/[[ GITHUB_USER ]]/myapp1
38+
repoTemplate:
39+
url: github.com/devstream-io/dtm-repo-scaffolding-python-flask
40+
ci:
41+
- type: github-actions
42+
options:
43+
imageRepo:
44+
user: [[ DOCKERHUB_USER ]]
45+
cd:
46+
- type: argocdapp
47+
```
48+
49+
Update the "YOUR_GITHUB_USER" and "YOUR_DOCKERHUB_USER" in the above file accordingly.
50+
51+
---
52+
53+
## Run
54+
55+
First, initialize:
56+
57+
```bash
58+
# this downloads the required plugins, according to the config file, automatically.
59+
dtm init -f config.yaml
60+
```
61+
62+
<script id="asciicast-EMzx8lzZq5AJpAMoJY23fh8A3" src="https://asciinema.org/a/EMzx8lzZq5AJpAMoJY23fh8A3.js" async></script>
63+
64+
Then we apply it by running:
65+
66+
```bash
67+
dtm apply -f config.yaml -y
68+
```
69+
70+
<script id="asciicast-z1XlVm9kGjzArV9aNERD7acfH" src="https://asciinema.org/a/z1XlVm9kGjzArV9aNERD7acfH.js" async></script>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# GitHub + GitHub Actions with DTM Tools
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# GitLab + GitLab CI with DTM Apps
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# GitLab + GitLab CI with DTM Tools

docs/use-cases/gitops.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,13 @@ Let's continue to look at the results of the `apply` command.
214214
215215
The repository is created automatically by DevStream with scaffolding code:
216216
217-
![](gitops/a.png)
217+
![](../images/gitops-a.png)
218218
219219
### 8.2 CI Pipelines with GitHub Actions
220220
221221
GitHub Actions pipelines are created and executed:
222222
223-
![](gitops/b.png)
223+
![](../images/gitops-b.png)
224224
225225
### 8.3 Argo CD Installation
226226

docs/use-cases/gitops.zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ export IMAGE_REPO_PASSWORD="YOUR_DOCKERHUB_TOKEN_HERE"
210210
211211
DevStream 已经通过 `repo-scaffolding` 插件自动创建了一个仓库:
212212
213-
![](gitops/a.png)
213+
![](../images/gitops-a.png)
214214
215215
### 8.2 基于 GitHub Actions 的 CI 流水线
216216
217217
GitHub Actions 流水线已经被创建并运行:
218218
219-
![](gitops/b.png)
219+
![](../images/gitops-b.png)
220220
221221
### 8.3 Argo CD 的安装
222222

0 commit comments

Comments
 (0)