Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs gitops for apps #1356

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ docs/build

# YAML for testings
config*.yaml*
app*.yaml
variables*.yaml
variables*.yaml.bak
tools*.yaml
Expand Down
3 changes: 2 additions & 1 deletion cmd/devstream/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var showConfigCMD = &cobra.Command{
Examples:
dtm show config --plugin=A-PLUGIN-NAME,
dtm show config --template=quickstart,
dtm show config --template=gitops`,
dtm show config --template=gitops,
dtm show config --template=apps`,
Run: showConfigCMDFunc,
}

Expand Down
155 changes: 155 additions & 0 deletions docs/best-practices/apps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# 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](./gitops.md), 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
mkdir test
cd test/
```

Download dtm (see the [GitOps](./gitops.md) best practice if you haven't).

Then generate the config file by running:

```bash
./dtm show config --template=apps > config.yaml
```

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

```shell
export GITHUB_USER="<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN_HERE>"
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 systems"

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

=== "**GNU** Linux users"

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

---

## 3 Init and Apply

Run:

```bash
./dtm init -f config.yaml
```

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

Then we apply it by running:

```bash
./dtm apply -f config.yaml -y
```

You will see similar outputs as the following:

```bash
tiexin@mbp ~/work/devstream-io/test $ ./dtm apply -f config.yaml -y
2022-12-16 14:30:27 ℹ [INFO] Apply started.
2022-12-16 14:30:28 ℹ [INFO] Using local backend. State file: devstream.state.
2022-12-16 14:30:28 ℹ [INFO] Tool (helm-installer/argocd) found in config but doesn't exist in the state, will be created.
2022-12-16 14:30:28 ℹ [INFO] Tool (repo-scaffolding/myapp1) found in config but doesn't exist in the state, will be created.
2022-12-16 14:30:28 ℹ [INFO] Tool (repo-scaffolding/myapp2) found in config but doesn't exist in the state, will be created.
2022-12-16 14:30:28 ℹ [INFO] Tool (github-actions/myapp1) found in config but doesn't exist in the state, will be created.
2022-12-16 14:30:28 ℹ [INFO] Tool (argocdapp/myapp1) found in config but doesn't exist in the state, will be created.
2022-12-16 14:30:28 ℹ [INFO] Tool (github-actions/myapp2) found in config but doesn't exist in the state, will be created.
2022-12-16 14:30:28 ℹ [INFO] Tool (argocdapp/myapp2) found in config but doesn't exist in the state, will be created.
2022-12-16 14:30:28 ℹ [INFO] Start executing the plan.
2022-12-16 14:30:28 ℹ [INFO] Changes count: 7.
2022-12-16 14:30:28 ℹ [INFO] -------------------- [ Processing progress: 1/7. ] --------------------
2022-12-16 14:30:28 ℹ [INFO] Processing: (helm-installer/argocd) -> Create ...
2022-12-16 14:30:29 ℹ [INFO] Filling default config with instance: argocd.
2022-12-16 14:30:29 ℹ [INFO] Creating or updating helm chart ...
... (omitted)
... (omitted)
2022-12-16 14:32:09 ℹ [INFO] -------------------- [ Processing progress: 7/7. ] --------------------
2022-12-16 14:32:09 ℹ [INFO] Processing: (argocdapp/myapp2) -> Create ...
2022-12-16 14:32:19 ℹ [INFO] application.argoproj.io/myapp2 created
2022-12-16 14:32:19 ✔ [SUCCESS] Tool (argocdapp/myapp2) Create done.
2022-12-16 14:32:19 ℹ [INFO] -------------------- [ Processing done. ] --------------------
2022-12-16 14:32:19 ✔ [SUCCESS] All plugins applied successfully.
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](./gitops.md) 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
./dtm delete -f config.yaml -y
```

And you will get similar outputs to the following:

```bash
2022-12-16 14:34:30 ℹ [INFO] Delete started.
2022-12-16 14:34:31 ℹ [INFO] Using local backend. State file: devstream.state.
2022-12-16 14:34:31 ℹ [INFO] Tool (github-actions/myapp1) will be deleted.
2022-12-16 14:34:31 ℹ [INFO] Tool (argocdapp/myapp1) will be deleted.
2022-12-16 14:34:31 ℹ [INFO] Tool (github-actions/myapp2) will be deleted.
2022-12-16 14:34:31 ℹ [INFO] Tool (argocdapp/myapp2) will be deleted.
2022-12-16 14:34:31 ℹ [INFO] Tool (repo-scaffolding/myapp1) will be deleted.
2022-12-16 14:34:31 ℹ [INFO] Tool (repo-scaffolding/myapp2) will be deleted.
2022-12-16 14:34:31 ℹ [INFO] Tool (helm-installer/argocd) will be deleted.
2022-12-16 14:34:31 ℹ [INFO] Start executing the plan.
2022-12-16 14:34:31 ℹ [INFO] Changes count: 7.
2022-12-16 14:34:31 ℹ [INFO] -------------------- [ Processing progress: 1/7. ] --------------------
2022-12-16 14:34:31 ℹ [INFO] Processing: (github-actions/myapp1) -> Delete ...
2022-12-16 14:34:33 ℹ [INFO] Prepare to delete 'github-actions_myapp1' from States.
2022-12-16 14:34:33 ✔ [SUCCESS] Tool (github-actions/myapp1) delete done.
... (omitted)
... (omitted)
2022-12-16 14:34:40 ✔ [SUCCESS] Tool (helm-installer/argocd) delete done.
2022-12-16 14:34:40 ℹ [INFO] -------------------- [ Processing done. ] --------------------
2022-12-16 14:34:40 ✔ [SUCCESS] All plugins deleted successfully.
2022-12-16 14:34:40 ✔ [SUCCESS] Delete finished.
```

Then you can delete what we created:

```bash
cd ../
rm -rf test/
rm -rf ~/.devstream/
```
3 changes: 3 additions & 0 deletions docs/best-practices/apps.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 使用DevStream的新功能Apps来进行GitOps

TODO
45 changes: 45 additions & 0 deletions examples/apps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
config:
state:
backend: local
options:
stateFile: devstream.state

vars:
GITHUB_USER: YOUR_GITHUB_USER
DOCKERHUB_USER: YOUR_DOCKERHUB_USER

tools:
- name: helm-installer
instanceID: argocd

apps:
- name: myapp1
spec:
language: python
framework: django
repo:
url: github.com/[[ GITHUB_USER ]]/myapp1
repoTemplate:
url: github.com/devstream-io/dtm-repo-scaffolding-python-flask
ci:
- type: github-actions
options:
imageRepo:
user: [[ DOCKERHUB_USER ]]
cd:
- type: argocdapp
- name: myapp2
spec:
language: golang
framework: gin
repo:
url: github.com/[[ GITHUB_USER ]]/myapp2
repoTemplate:
url: github.com/devstream-io/dtm-repo-scaffolding-golang-gin
ci:
- type: github-actions
options:
imageRepo:
user: [[ DOCKERHUB_USER ]]
cd:
- type: argocdapp
1 change: 1 addition & 0 deletions internal/pkg/show/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
var templates = map[string]string{
"quickstart": QuickStart,
"gitops": GitOps,
"apps": Apps,
}

//go:generate go run gen_embed_var.go
Expand Down
3 changes: 3 additions & 0 deletions internal/pkg/show/config/embed_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/pkg/show/config/gen_embed.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ var QuickStart string

//go:embed templates/gitops.yaml
var GitOps string

//go:embed templates/apps.yaml
var Apps string
45 changes: 45 additions & 0 deletions internal/pkg/show/config/templates/apps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
config:
state:
backend: local
options:
stateFile: devstream.state

vars:
GITHUB_USER: YOUR_GITHUB_USER
DOCKERHUB_USER: YOUR_DOCKERHUB_USER

tools:
- name: helm-installer
instanceID: argocd

apps:
- name: myapp1
spec:
language: python
framework: django
repo:
url: github.com/[[ GITHUB_USER ]]/myapp1
repoTemplate:
url: github.com/devstream-io/dtm-repo-scaffolding-python-flask
ci:
- type: github-actions
options:
imageRepo:
user: [[ DOCKERHUB_USER ]]
cd:
- type: argocdapp
- name: myapp2
spec:
language: golang
framework: gin
repo:
url: github.com/[[ GITHUB_USER ]]/myapp2
repoTemplate:
url: github.com/devstream-io/dtm-repo-scaffolding-golang-gin
ci:
- type: github-actions
options:
imageRepo:
user: [[ DOCKERHUB_USER ]]
cd:
- type: argocdapp
7 changes: 6 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ nav:
- plugins/helm-installer/helm-installer*.md
- plugins/helm-installer/*.md
- plugins/*.md
- Best Practices: best-practices/
- Best Practices:
- best-practices/gitops*.md
- best-practices/apps*.md
- best-practices/gitlab-jenkins-harbor-java-springboot*.md
- best-practices/gjh-java-springboot-air-gapped-deployment*.md
- best-practices/image-registry*.md
- contributing_guide*.md
- contributor_ladder*.md
- Governance ⧉: https://github.com/devstream-io/devstream/blob/main/GOVERNANCE.md
Expand Down