Skip to content

Commit 17ddd2c

Browse files
authored
Merge pull request #1363 from devstream-io/main
bugfix for v0.10.3
2 parents 029d19f + 941be7b commit 17ddd2c

File tree

5 files changed

+166
-7
lines changed

5 files changed

+166
-7
lines changed

docs/best-practices/apps.zh.md

Lines changed: 152 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,153 @@
1-
# 使用DevStream的新功能Apps来进行GitOps
1+
# 使用 DevStream 的新特性 Apps 来实现 GitOps
22

3-
TODO
3+
## 0 目标
4+
5+
在本教程中,我们会使用 DevStream 的新特性 应用(Apps),来达到与 [GitOps](gitops.zh.md) 相似的效果。但它的配置更短,来展示 应用 的强大能力。如果你还没有读过原始的 GitOps 最佳实践,可以先点击前面的链接。
6+
7+
我们会创建两个应用程序(一个基于 Python,另一个是 Go 语言),并且创建共用的 CI/CD 流水线,即两个应用程序都会通过 Argo CD 来部署,就像前面的 GitOps 做到的那样。
8+
9+
---
10+
11+
## 1 概览
12+
13+
DevStream 使用 应用 的概念来创建带有代码脚手架和 GitHub Actions 流水线的仓库,并安装 Argo CD,最后使用 Arco CD 部署应用程序。
14+
15+
---
16+
17+
## 2 创建配置文件
18+
19+
为本教程创建临时工作目录:
20+
21+
```bash
22+
mkdir test
23+
cd test/
24+
```
25+
26+
下载 dtm(详见 [GitOps](./gitops.zh.md) 最佳实践,如果你还没有下载过的话)
27+
28+
运行以下命令以生成配置文件:
29+
30+
```bash
31+
./dtm show config --template=apps > config.yaml
32+
```
33+
34+
替换下面命令中的双引号内里面的内容,并运行,以设置环境变量:
35+
36+
```shell
37+
export GITHUB_USER="<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN_HERE>"
38+
export DOCKERHUB_USERNAME="<YOUR_DOCKER_HUB_USER_NAME_HERE>"
39+
```
40+
41+
现在我们就可以使用前面设置的环境变量来更新配置文件了:
42+
43+
=== "基于 **macOS****FreeBSD** 的系统"
44+
45+
```shell
46+
sed -i.bak "s@YOUR_GITHUB_USER@${GITHUB_USER}@g" config.yaml
47+
sed -i.bak "s@YOUR_DOCKERHUB_USER@${DOCKERHUB_USERNAME}@g" config.yaml
48+
```
49+
50+
=== "**GNU** Linux 用户"
51+
52+
```shell
53+
sed -i "s@YOUR_GITHUB_USERNAME_CASE_SENSITIVE@${GITHUB_USER}@g" config.yaml
54+
sed -i "s@YOUR_DOCKER_USERNAME@${DOCKERHUB_USERNAME}@g" config.yaml
55+
```
56+
57+
---
58+
59+
## 3 初始化(Init)和应用(Apply)
60+
61+
运行下面这个命令,以根据配置文件来自动下载对应的插件:
62+
63+
```bash
64+
./dtm init -f config.yaml
65+
```
66+
67+
再运行 apply 命令:
68+
69+
```bash
70+
./dtm apply -f config.yaml -y
71+
```
72+
73+
你会看到类似下面的输出:
74+
75+
```bash
76+
tiexin@mbp ~/work/devstream-io/test $ ./dtm apply -f config.yaml -y
77+
2022-12-16 14:30:27 ℹ [INFO] Apply started.
78+
2022-12-16 14:30:28 ℹ [INFO] Using local backend. State file: devstream.state.
79+
2022-12-16 14:30:28 ℹ [INFO] Tool (helm-installer/argocd) found in config but doesn't exist in the state, will be created.
80+
2022-12-16 14:30:28 ℹ [INFO] Tool (repo-scaffolding/myapp1) found in config but doesn't exist in the state, will be created.
81+
2022-12-16 14:30:28 ℹ [INFO] Tool (repo-scaffolding/myapp2) found in config but doesn't exist in the state, will be created.
82+
2022-12-16 14:30:28 ℹ [INFO] Tool (github-actions/myapp1) found in config but doesn't exist in the state, will be created.
83+
2022-12-16 14:30:28 ℹ [INFO] Tool (argocdapp/myapp1) found in config but doesn't exist in the state, will be created.
84+
2022-12-16 14:30:28 ℹ [INFO] Tool (github-actions/myapp2) found in config but doesn't exist in the state, will be created.
85+
2022-12-16 14:30:28 ℹ [INFO] Tool (argocdapp/myapp2) found in config but doesn't exist in the state, will be created.
86+
2022-12-16 14:30:28 ℹ [INFO] Start executing the plan.
87+
2022-12-16 14:30:28 ℹ [INFO] Changes count: 7.
88+
2022-12-16 14:30:28 ℹ [INFO] -------------------- [ Processing progress: 1/7. ] --------------------
89+
2022-12-16 14:30:28 ℹ [INFO] Processing: (helm-installer/argocd) -> Create ...
90+
2022-12-16 14:30:29 ℹ [INFO] Filling default config with instance: argocd.
91+
2022-12-16 14:30:29 ℹ [INFO] Creating or updating helm chart ...
92+
... (略)
93+
... (略)
94+
2022-12-16 14:32:09 ℹ [INFO] -------------------- [ Processing progress: 7/7. ] --------------------
95+
2022-12-16 14:32:09 ℹ [INFO] Processing: (argocdapp/myapp2) -> Create ...
96+
2022-12-16 14:32:19 ℹ [INFO] application.argoproj.io/myapp2 created
97+
2022-12-16 14:32:19 ✔ [SUCCESS] Tool (argocdapp/myapp2) Create done.
98+
2022-12-16 14:32:19 ℹ [INFO] -------------------- [ Processing done. ] --------------------
99+
2022-12-16 14:32:19 ✔ [SUCCESS] All plugins applied successfully.
100+
2022-12-16 14:32:19 ✔ [SUCCESS] Apply finished.
101+
```
102+
103+
---
104+
105+
## 4 查看结果
106+
107+
让我们来继续看看 `apply` 命令的结果:
108+
109+
与我们在[GitOps](./gitops.zh.md)最佳实践中所做的类似,我们可以检查 dtm 是否为两个应用程序创建了代码仓库并为其创建了 CI 流水线,同时安装了 Argo CD,而且两个应用程序都使用了 Argo CD 来部署到了 Kubernetes 集群中。
110+
111+
---
112+
113+
## 5 清理
114+
115+
运行:
116+
117+
```bash
118+
./dtm delete -f config.yaml -y
119+
```
120+
121+
你会看到类似下面的输出:
122+
123+
```bash
124+
2022-12-16 14:34:30 ℹ [INFO] Delete started.
125+
2022-12-16 14:34:31 ℹ [INFO] Using local backend. State file: devstream.state.
126+
2022-12-16 14:34:31 ℹ [INFO] Tool (github-actions/myapp1) will be deleted.
127+
2022-12-16 14:34:31 ℹ [INFO] Tool (argocdapp/myapp1) will be deleted.
128+
2022-12-16 14:34:31 ℹ [INFO] Tool (github-actions/myapp2) will be deleted.
129+
2022-12-16 14:34:31 ℹ [INFO] Tool (argocdapp/myapp2) will be deleted.
130+
2022-12-16 14:34:31 ℹ [INFO] Tool (repo-scaffolding/myapp1) will be deleted.
131+
2022-12-16 14:34:31 ℹ [INFO] Tool (repo-scaffolding/myapp2) will be deleted.
132+
2022-12-16 14:34:31 ℹ [INFO] Tool (helm-installer/argocd) will be deleted.
133+
2022-12-16 14:34:31 ℹ [INFO] Start executing the plan.
134+
2022-12-16 14:34:31 ℹ [INFO] Changes count: 7.
135+
2022-12-16 14:34:31 ℹ [INFO] -------------------- [ Processing progress: 1/7. ] --------------------
136+
2022-12-16 14:34:31 ℹ [INFO] Processing: (github-actions/myapp1) -> Delete ...
137+
2022-12-16 14:34:33 ℹ [INFO] Prepare to delete 'github-actions_myapp1' from States.
138+
2022-12-16 14:34:33 ✔ [SUCCESS] Tool (github-actions/myapp1) delete done.
139+
... (略)
140+
... (略)
141+
2022-12-16 14:34:40 ✔ [SUCCESS] Tool (helm-installer/argocd) delete done.
142+
2022-12-16 14:34:40 ℹ [INFO] -------------------- [ Processing done. ] --------------------
143+
2022-12-16 14:34:40 ✔ [SUCCESS] All plugins deleted successfully.
144+
2022-12-16 14:34:40 ✔ [SUCCESS] Delete finished.
145+
```
146+
147+
后面我们就能删除创建的所有文件了:
148+
149+
```bash
150+
cd ../
151+
rm -rf test/
152+
rm -rf ~/.devstream/
153+
```

docs/best-practices/gitlab-jenkins-harbor-java-springboot.zh.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ DevStream 可以简单地以 **local** 作为 Backend,也就是将状态保存
8383

8484
下文将以 `local` Backend 为例演示。
8585

86-
在编写 `gitlab-ce-docker``jenkins``harbor` 三个插件的配置文件之前,你需要先定义一些变量,这会让工具的配置和维护变得更加简单
86+
在编写 `gitlab-ce-docker``helm-installer`(用户安装 Jenkins 和 Harbor)这两个插件的配置文件之前,你需要先定义一些变量,这会让后续的配置和维护工作变得更加简单
8787

8888
```yaml title="config-tools.yaml"
8989
config:
@@ -291,7 +291,7 @@ Stdout: 34cdd2a834a1c21be192064eacf1e29536ff45c52562956b97d6d376a5dae11b
291291

292292
```sh
293293
docker exec -it gitlab bash
294-
echo "44.33.22.11 gitlab.example.com" >> /etc/hosts
294+
echo "44.33.22.11 jenkins.example.com" >> /etc/hosts
295295
exit
296296
```
297297

@@ -399,7 +399,7 @@ pipelineTemplates:
399399
enableRestart: true
400400
imageRepo:
401401
user: admin
402-
url: http://[[ harborURL ]]/library
402+
url: [[ harborURL ]]/library
403403
```
404404

405405
可以看到这里的状态配置换成了 devstream-app.state,这里需要保证和前面 tools 所使用的状态文件不是同一个。

internal/pkg/plugin/installer/ci/validate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func SetDefault(ciType server.CIServerType) func(option configmanager.RawOptions
2626
if err != nil {
2727
return nil, err
2828
}
29+
// set default value of repoInfo
30+
if err := opts.ProjectRepo.SetDefault(); err != nil {
31+
return nil, err
32+
}
2933
opts.CIFileConfig = opts.Pipeline.BuildCIFileConfig(ciType, opts.ProjectRepo)
3034
return mapz.DecodeStructToMap(opts)
3135
}

internal/pkg/plugin/jenkinspipeline/option.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ func (j *jobOptions) createOrUpdateJob(jenkinsClient jenkins.JenkinsAPI, secretT
7373
SecretToken: secretToken,
7474
FolderName: j.JobName.getJobFolder(),
7575
GitlabConnection: globalConfig.GitlabConnectionID,
76-
RepoURL: string(repoInfo.CloneURL),
76+
RepoURL: string(repoInfo.GetCloneURL()),
7777
RepoOwner: repoInfo.GetRepoOwner(),
78-
RepoName: repoInfo.Repo,
78+
RepoName: repoInfo.GetRepoName(),
7979
RepoCredentialsId: globalConfig.CredentialID,
8080
}
8181
jobScript, err := jenkins.BuildRenderedScript(jobRenderInfo)

internal/pkg/plugin/jenkinspipeline/validate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ func setJenkinsDefault(options configmanager.RawOptions) (configmanager.RawOptio
2020
return nil, err
2121
}
2222

23+
// set project default value
24+
if err := opts.ProjectRepo.SetDefault(); err != nil {
25+
return nil, err
26+
}
27+
2328
// if jenkins is offline, just use offline Jenkinsfile
2429
if opts.needOfflineConfig() {
2530
opts.CIFileConfig = &cifile.CIFileConfig{

0 commit comments

Comments
 (0)