11# 快速开始
22
3- 如果你更喜欢看 DevStream 的实际操作,请先观看 [ 演示视频 ] ( ./index.zh.md ) 。
3+ 我们将在本文使用 DevStream 自动完成以下操作:
44
5- > 注意:DevStream 目前只有 Linux 和 macOS 版本,Windows 将在以后支持。
5+ - 创建一个包含了 web 应用程序的 GitHub 仓库,代码基于 [ gin] ( https://github.com/gin-gonic/gin ) 框架(用Go语言编写)自动生成;
6+ - 为前面创建的仓库设置 GitHub Actions 工作流。
67
7- 在这个快速开始的示例中,我们将使用 DevStream 做以下自动化工作:
8-
9- 1 . 使用 Golang 的 web 应用程序脚手架在 GitHub 创建仓库。
10- 2 . 为我们创建的 Golang 应用程序设置 GitHub Actions,包含 Go web 应用程序的构建和测试阶段。
8+ ---
119
1210## 1 下载
1311
1715sh -c " $( curl -fsSL https://raw.githubusercontent.com/devstream-io/devstream/main/hack/install/download.sh) "
1816```
1917
20- 这个命令会根据你的操作系统和芯片架构下载对应的 ` dtm ` 二进制文件到你的工作目录中,并赋予二进制文件执行权限。
21-
22- > 可选:建议你将 dtm 移动到包含于 PATH 的目录下,比如 ` mv dtm /usr/local/bin/ ` 。
18+ > 小贴士:上面的命令会做以下事情:
19+ >
20+ > - 检测你的操作系统和芯片架构
21+ > - 找到最新版本的 ` dtm ` 二进制文件
22+ > - 根据操作系统和架构下载正确的 ` dtm ` 二进制文件
23+ > - 授予二进制文件执行权限
24+ >
25+ > 可选:你可以将 ` dtm ` 移到 PATH 中。例如:` mv dtm /usr/local/bin/ ` 。
26+ >
27+ > 更多安装方式详见[ 安装dtm] ( ./install.zh.md ) 。
2328
24- _ 更多安装方式详见 [ 安装dtm ] ( ./install.zh.md ) 。 _
29+ ---
2530
2631## 2 配置
2732
@@ -31,12 +36,6 @@ _更多安装方式详见[安装dtm](./install.zh.md)。_
3136./dtm show config -t quickstart > config.yaml
3237```
3338
34- 正如前文所述,我们将在 GitHub Actions 中操作 GitHub 仓库的脚手架和 CI 工作流。所以,我们需要设置以下环境变量:
35-
36- - GITHUB_USER
37- - GITHUB_TOKEN
38- - DOCKERHUB_USERNAME
39-
4039运行以下命令以设置这些环境变量(记得替换双引号内的值):
4140
4241``` shell
@@ -45,171 +44,148 @@ export GITHUB_TOKEN="<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN_HERE>"
4544export DOCKERHUB_USERNAME=" <YOUR_DOCKER_HUB_USER_NAME_HERE>"
4645```
4746
48- > 小贴士:前往 [ Personal Access Token] ( https://github.com/settings/tokens/new ) 为 ` dtm ` 生成新的 ` GITHUB_TOKEN ` 。
49- >
50- > 对于“快速开始”,我们只需要勾选 ` repo ` 、` workflow ` 、` delete_repo ` 权限,但我们更建议你全部勾选,未来的插件可能需要更多权限 。
47+ > 小贴士:前往 [ Personal Access Token] ( https://github.com/settings/tokens/new ) 为 ` dtm ` 生成新的 ` GITHUB_TOKEN ` 。
48+ >
49+ > 对于“快速开始”,我们只需要勾选 ` repo ` 、` workflow ` 、` delete_repo ` 权限。
5150
5251接着,让我们运行以下命令,以使用环境变量来修改配置文件:
5352
5453对于 ** macOS** 或 基于 ** FreeBSD** 的操作系统:
5554
56-
5755``` shell
58- sed -i.bak " s@YOUR_GITHUB_USERNAME_CASE_SENSITIVE@${GITHUB_USER} @g" quickstart.yaml
59- sed -i.bak " s@YOUR_DOCKER_USERNAME@${DOCKERHUB_USERNAME} @g" quickstart.yaml
60- ```
61-
62- 对于 ** GNU** Linux 用户:
63-
64- ``` shell
65- sed -i " s@YOUR_GITHUB_USERNAME_CASE_SENSITIVE@${GITHUB_USER} @g" quickstart.yaml
66- sed -i " s@YOUR_DOCKER_USERNAME@${DOCKERHUB_USERNAME} @g" quickstart.yaml
56+ sed -i.bak " s@YOUR_GITHUB_USERNAME_CASE_SENSITIVE@${GITHUB_USER} @g" config.yaml
57+ sed -i.bak " s@YOUR_DOCKER_USERNAME@${DOCKERHUB_USERNAME} @g" config.yaml
6758```
6859
60+ > 对于 ** GNU** Linux 用户,运行:
61+ >
62+ > ``` shell
63+ > sed -i " s@YOUR_GITHUB_USERNAME_CASE_SENSITIVE@${GITHUB_USER} @g" config.yaml
64+ > sed -i " s@YOUR_DOCKER_USERNAME@${DOCKERHUB_USERNAME} @g" config.yaml
65+ > ` ` `
6966
67+ ---
7068
7169# # 3 初始化
7270
7371运行:
7472
7573` ` ` shell
76- ./dtm init -f quickstart.yaml
74+ ./dtm init
7775```
7876
79- 你会看到类似这样的日志输出:
80-
77+ > 你会看到类似下面的输出:
8178```
82- 2022-06-30 11:21:48 ℹ [INFO] Got Backend from config: local
83- 2022-06-30 11:21:48 ℹ [INFO] Using dir <.devstream> to store plugins.
84- 2022-06-30 11:21:48 ℹ [INFO] Downloading: [github-repo-scaffolding-golang-darwin-arm64_0.7.0.so] ...
85- 15.05 MiB / 15.05 MiB [================================] 100.00% 21.17 MiB/s 0s
86- 2022-06-30 11:21:49 ✔ [SUCCESS] [github-repo-scaffolding-golang-darwin-arm64_0.7.0.so] download succeeded.
87- 2022-06-30 11:21:49 ℹ [INFO] Downloading: [github-repo-scaffolding-golang-darwin-arm64_0.7.0.md5] ...
88- 33 B / 33 B [==========================================] 100.00% 35.29 KiB/s 0s
89- 2022-06-30 11:21:49 ✔ [SUCCESS] [github-repo-scaffolding-golang-darwin-arm64_0.7.0.md5] download succeeded.
90- 2022-06-30 11:21:49 ℹ [INFO] Plugin: github-repo-scaffolding-golang-darwin-arm64_0.7.0.so doesn't match with .md5 and will be downloaded.
91- 2022-06-30 11:21:49 ℹ [INFO] Downloading: [github-repo-scaffolding-golang-darwin-arm64_0.7.0.so] ...
92- 15.05 MiB / 15.05 MiB [================================] 100.00% 31.25 MiB/s 0s
93- 2022-06-30 11:21:50 ✔ [SUCCESS] [github-repo-scaffolding-golang-darwin-arm64_0.7.0.so] download succeeded.
94- 2022-06-30 11:21:50 ℹ [INFO] Downloading: [github-repo-scaffolding-golang-darwin-arm64_0.7.0.md5] ...
95- 33 B / 33 B [==========================================] 100.00% 43.43 KiB/s 0s
96- 2022-06-30 11:21:50 ✔ [SUCCESS] [github-repo-scaffolding-golang-darwin-arm64_0.7.0.md5] download succeeded.
97- 2022-06-30 11:21:50 ℹ [INFO] Downloading: [githubactions-golang-darwin-arm64_0.7.0.so] ...
98- 17.49 MiB / 17.49 MiB [================================] 100.00% 31.18 MiB/s 0s
99- 2022-06-30 11:21:51 ✔ [SUCCESS] [githubactions-golang-darwin-arm64_0.7.0.so] download succeeded.
100- 2022-06-30 11:21:51 ℹ [INFO] Downloading: [githubactions-golang-darwin-arm64_0.7.0.md5] ...
101- 33 B / 33 B [=========================================] 100.00% 160.70 KiB/s 0s
102- 2022-06-30 11:21:51 ✔ [SUCCESS] [githubactions-golang-darwin-arm64_0.7.0.md5] download succeeded.
103- 2022-06-30 11:21:51 ℹ [INFO] Plugin: githubactions-golang-darwin-arm64_0.7.0.so doesn't match with .md5 and will be downloaded.
104- 2022-06-30 11:21:51 ℹ [INFO] Downloading: [githubactions-golang-darwin-arm64_0.7.0.so] ...
105- 17.49 MiB / 17.49 MiB [================================] 100.00% 31.78 MiB/s 0s
106- 2022-06-30 11:21:52 ✔ [SUCCESS] [githubactions-golang-darwin-arm64_0.7.0.so] download succeeded.
107- 2022-06-30 11:21:52 ℹ [INFO] Downloading: [githubactions-golang-darwin-arm64_0.7.0.md5] ...
108- 33 B / 33 B [==========================================] 100.00% 87.12 KiB/s 0s
109- 2022-06-30 11:21:52 ✔ [SUCCESS] [githubactions-golang-darwin-arm64_0.7.0.md5] download succeeded.
110- 2022-06-30 11:21:52 ✔ [SUCCESS] Initialize finished.
79+ 2022-12-02 16:11:55 ℹ [INFO] Using dir </Users/tiexin/.devstream/plugins> to store plugins.
80+ 2022-12-02 16:11:55 ℹ [INFO] -------------------- [ repo-scaffolding-darwin-arm64_0.10.1 ] --------------------
81+ 2022-12-02 16:11:57 ℹ [INFO] Downloading: [repo-scaffolding-darwin-arm64_0.10.1.so] ...
82+ 87.82 MiB / 87.82 MiB [================================] 100.00% 12.30 MiB/s 7s
83+ 2022-12-02 16:12:04 ✔ [SUCCESS] [repo-scaffolding-darwin-arm64_0.10.1.so] download succeeded.
84+ 2022-12-02 16:12:04 ℹ [INFO] Downloading: [repo-scaffolding-darwin-arm64_0.10.1.md5] ...
85+ 33 B / 33 B [==========================================] 100.00% 50.98 KiB/s 0s
86+ 2022-12-02 16:12:04 ✔ [SUCCESS] [repo-scaffolding-darwin-arm64_0.10.1.md5] download succeeded.
87+ 2022-12-02 16:12:04 ℹ [INFO] Initialize [repo-scaffolding-darwin-arm64_0.10.1] finished.
88+ 2022-12-02 16:12:04 ℹ [INFO] -------------------- [ repo-scaffolding-darwin-arm64_0.10.1 ] --------------------
89+ 2022-12-02 16:12:04 ℹ [INFO] -------------------- [ githubactions-golang-darwin-arm64_0.10.1 ] --------------------
90+ 2022-12-02 16:12:05 ℹ [INFO] Downloading: [githubactions-golang-darwin-arm64_0.10.1.so] ...
91+ 86.44 MiB / 86.44 MiB [================================] 100.00% 15.12 MiB/s 5s
92+ 2022-12-02 16:12:10 ✔ [SUCCESS] [githubactions-golang-darwin-arm64_0.10.1.so] download succeeded.
93+ 2022-12-02 16:12:10 ℹ [INFO] Downloading: [githubactions-golang-darwin-arm64_0.10.1.md5] ...
94+ 33 B / 33 B [==========================================] 100.00% 71.24 KiB/s 0s
95+ 2022-12-02 16:12:10 ✔ [SUCCESS] [githubactions-golang-darwin-arm64_0.10.1.md5] download succeeded.
96+ 2022-12-02 16:12:11 ℹ [INFO] Initialize [githubactions-golang-darwin-arm64_0.10.1] finished.
97+ 2022-12-02 16:12:11 ℹ [INFO] -------------------- [ githubactions-golang-darwin-arm64_0.10.1 ] --------------------
98+ 2022-12-02 16:12:11 ✔ [SUCCESS] Initialize finished.
11199```
112100
101+ ---
102+
113103## 4 应用(Apply)
114104
115105运行:
116106
117107``` shell
118- ./dtm apply -f quickstart.yaml
108+ ./dtm apply -y
119109```
120110
121- 当它提示 :
111+ > 你会看到类似下面的输出 :
122112
123- ``` shell
124- ...(以上省略)
125- Continue? [y/n]
126- Enter a value (Default is n):
127113```
128-
129- 请输入 ` y ` 并按回车键。
130-
131- 你会看到类似下面的输出:
132-
133- ```
134- 2022-06-30 11:25:47 ℹ [INFO] Apply started.
135- 2022-06-30 11:25:47 ℹ [INFO] Got Backend from config: local
136- 2022-06-30 11:25:47 ℹ [INFO] Using dir <.devstream> to store plugins.
137- 2022-06-30 11:25:47 ℹ [INFO] Using local backend. State file: devstream.state.
138- 2022-06-30 11:25:47 ℹ [INFO] Tool (github-repo-scaffolding-golang/default) found in config but doesn't exist in the state, will be created.
139- 2022-06-30 11:25:47 ℹ [INFO] Tool (githubactions-golang/default) found in config but doesn't exist in the state, will be created.
140- Continue? [y/n]
141- Enter a value (Default is n): y
142-
143- 2022-06-30 11:26:20 ℹ [INFO] Start executing the plan.
144- 2022-06-30 11:26:20 ℹ [INFO] Changes count: 2.
145- 2022-06-30 11:26:20 ℹ [INFO] -------------------- [ Processing progress: 1/2. ] --------------------
146- 2022-06-30 11:26:20 ℹ [INFO] Processing: (github-repo-scaffolding-golang/default) -> Create ...
147- 2022-06-30 11:26:24 ℹ [INFO] The repo go-webapp-devstream-demo has been created.
148- 2022-06-30 11:26:37 ✔ [SUCCESS] Tool (github-repo-scaffolding-golang/default) Create done.
149- 2022-06-30 11:26:37 ℹ [INFO] -------------------- [ Processing progress: 2/2. ] --------------------
150- 2022-06-30 11:26:37 ℹ [INFO] Processing: (githubactions-golang/default) -> Create ...
151- 2022-06-30 11:26:38 ℹ [INFO] Creating GitHub Actions workflow pr-builder.yml ...
152- 2022-06-30 11:26:38 ✔ [SUCCESS] Github Actions workflow pr-builder.yml created.
153- 2022-06-30 11:26:38 ℹ [INFO] Creating GitHub Actions workflow main-builder.yml ...
154- 2022-06-30 11:26:39 ✔ [SUCCESS] Github Actions workflow main-builder.yml created.
155- 2022-06-30 11:26:39 ✔ [SUCCESS] Tool (githubactions-golang/default) Create done.
156- 2022-06-30 11:26:39 ℹ [INFO] -------------------- [ Processing done. ] --------------------
157- 2022-06-30 11:26:39 ✔ [SUCCESS] All plugins applied successfully.
158- 2022-06-30 11:26:39 ✔ [SUCCESS] Apply finished.
114+ 2022-12-02 16:18:00 ℹ [INFO] Apply started.
115+ 2022-12-02 16:18:00 ℹ [INFO] Using local backend. State file: devstream.state.
116+ 2022-12-02 16:18:00 ℹ [INFO] Tool (repo-scaffolding/golang-github) found in config but doesn't exist in the state, will be created.
117+ 2022-12-02 16:18:00 ℹ [INFO] Tool (githubactions-golang/default) found in config but doesn't exist in the state, will be created.
118+ 2022-12-02 16:18:00 ℹ [INFO] Start executing the plan.
119+ 2022-12-02 16:18:00 ℹ [INFO] Changes count: 2.
120+ 2022-12-02 16:18:00 ℹ [INFO] -------------------- [ Processing progress: 1/2. ] --------------------
121+ 2022-12-02 16:18:00 ℹ [INFO] Processing: (repo-scaffolding/golang-github) -> Create ...
122+ 2022-12-02 16:18:00 ℹ [INFO] github start to download repoTemplate...
123+ 2022-12-02 16:18:04 ✔ [SUCCESS] The repo go-webapp-devstream-demo has been created.
124+ 2022-12-02 16:18:12 ✔ [SUCCESS] Tool (repo-scaffolding/golang-github) Create done.
125+ 2022-12-02 16:18:12 ℹ [INFO] -------------------- [ Processing progress: 2/2. ] --------------------
126+ 2022-12-02 16:18:12 ℹ [INFO] Processing: (githubactions-golang/default) -> Create ...
127+ 2022-12-02 16:18:13 ℹ [INFO] Creating GitHub Actions workflow pr-builder.yml ...
128+ 2022-12-02 16:18:14 ✔ [SUCCESS] Github Actions workflow pr-builder.yml created.
129+ 2022-12-02 16:18:14 ℹ [INFO] Creating GitHub Actions workflow main-builder.yml ...
130+ 2022-12-02 16:18:15 ✔ [SUCCESS] Github Actions workflow main-builder.yml created.
131+ 2022-12-02 16:18:15 ✔ [SUCCESS] Tool (githubactions-golang/default) Create done.
132+ 2022-12-02 16:18:15 ℹ [INFO] -------------------- [ Processing done. ] --------------------
133+ 2022-12-02 16:18:15 ✔ [SUCCESS] All plugins applied successfully.
134+ 2022-12-02 16:18:15 ✔ [SUCCESS] Apply finished.
159135```
160136
161-
137+ ---
162138
163139## 5 检查结果
164140
165- 前往你的 GitHub 仓库列表,你可以看到一个新的仓库 ` go-webapp-devstream-demo ` 已经被创建了。
141+ 前往你的 GitHub 仓库列表,可以看到一个新的仓库 ` go-webapp-devstream-demo ` 已经被创建了。
166142
167143包含了 Golang web 应用程序的脚手架代码,并正确设置了 GitHub Actions CI 工作流。
168144
169145DevStream 在生成仓库脚手架和创建工作流时的代码提交,已经触发了 CI,且工作流已经成功地运行完毕,如下图所示:
170146
171147![ ] ( ./images/repo-scaffolding.png )
172148
149+ ---
150+
173151## 6 清理
174152
175153运行:
176154
177155``` shell
178- ./dtm delete -f quickstart.yaml
156+ ./dtm delete
179157```
180158
181- 像之前那样,在收到提示时输入 ` y ` ,你将会看到类似输出 :
159+ 输入 ` y ` 然后回车,你会看到类似下面的输出 :
182160
183161```
184- 2022-06-30 11:31:01 ℹ [INFO] Delete started.
185- 2022-06-30 11:31:01 ℹ [INFO] Got Backend from config: local
186- 2022-06-30 11:31:01 ℹ [INFO] Using dir <.devstream> to store plugins.
187- 2022-06-30 11:31:01 ℹ [INFO] Using local backend. State file: devstream.state.
188- 2022-06-30 11:31:01 ℹ [INFO] Tool (githubactions-golang/default) will be deleted.
189- 2022-06-30 11:31:01 ℹ [INFO] Tool (github-repo-scaffolding-golang/default) will be deleted.
162+ 2022-12-02 16:19:07 ℹ [INFO] Delete started.
163+ 2022-12-02 16:19:07 ℹ [INFO] Using local backend. State file: devstream.state.
164+ 2022-12-02 16:19:07 ℹ [INFO] Tool (githubactions-golang/default) will be deleted.
165+ 2022-12-02 16:19:07 ℹ [INFO] Tool (repo-scaffolding/golang-github) will be deleted.
190166Continue? [y/n]
191167Enter a value (Default is n): y
192168
193- 2022-06-30 11:31:03 ℹ [INFO] Start executing the plan.
194- 2022-06-30 11:31:03 ℹ [INFO] Changes count: 2.
195- 2022-06-30 11:31:03 ℹ [INFO] -------------------- [ Processing progress: 1/2. ] --------------------
196- 2022-06-30 11:31:03 ℹ [INFO] Processing: (githubactions-golang/default) -> Delete ...
197- 2022-06-30 11:31:04 ℹ [INFO] Deleting GitHub Actions workflow pr-builder.yml ...
198- 2022-06-30 11:31:05 ✔ [SUCCESS] GitHub Actions workflow pr-builder.yml removed.
199- 2022-06-30 11:31:05 ℹ [INFO] Deleting GitHub Actions workflow main-builder.yml ...
200- 2022-06-30 11:31:06 ✔ [SUCCESS] GitHub Actions workflow main-builder.yml removed.
201- 2022-06-30 11:31:06 ℹ [INFO] Prepare to delete 'githubactions-golang_default' from States.
202- 2022-06-30 11:31:06 ✔ [SUCCESS] Tool (githubactions-golang/default) delete done.
203- 2022-06-30 11:31:06 ℹ [INFO] -------------------- [ Processing progress: 2/2. ] --------------------
204- 2022-06-30 11:31:06 ℹ [INFO] Processing: (github- repo-scaffolding-golang/default ) -> Delete ...
205- 2022-06-30 11:31:06 ✔ [SUCCESS] GitHub repo go-webapp-devstream-demo removed.
206- 2022-06-30 11:31:06 ℹ [INFO] Prepare to delete 'github- repo-scaffolding-golang_default ' from States.
207- 2022-06-30 11:31:06 ✔ [SUCCESS] Tool (github- repo-scaffolding-golang/default ) delete done.
208- 2022-06-30 11:31:06 ℹ [INFO] -------------------- [ Processing done. ] --------------------
209- 2022-06-30 11:31:06 ✔ [SUCCESS] All plugins deleted successfully.
210- 2022-06-30 11:31:06 ✔ [SUCCESS] Delete finished.
169+ 2022-12-02 16:19:08 ℹ [INFO] Start executing the plan.
170+ 2022-12-02 16:19:08 ℹ [INFO] Changes count: 2.
171+ 2022-12-02 16:19:08 ℹ [INFO] -------------------- [ Processing progress: 1/2. ] --------------------
172+ 2022-12-02 16:19:08 ℹ [INFO] Processing: (githubactions-golang/default) -> Delete ...
173+ 2022-12-02 16:19:09 ℹ [INFO] Deleting GitHub Actions workflow pr-builder.yml ...
174+ 2022-12-02 16:19:09 ✔ [SUCCESS] GitHub Actions workflow pr-builder.yml removed.
175+ 2022-12-02 16:19:10 ℹ [INFO] Deleting GitHub Actions workflow main-builder.yml ...
176+ 2022-12-02 16:19:10 ✔ [SUCCESS] GitHub Actions workflow main-builder.yml removed.
177+ 2022-12-02 16:19:10 ℹ [INFO] Prepare to delete 'githubactions-golang_default' from States.
178+ 2022-12-02 16:19:10 ✔ [SUCCESS] Tool (githubactions-golang/default) delete done.
179+ 2022-12-02 16:19:10 ℹ [INFO] -------------------- [ Processing progress: 2/2. ] --------------------
180+ 2022-12-02 16:19:10 ℹ [INFO] Processing: (repo-scaffolding/golang-github ) -> Delete ...
181+ 2022-12-02 16:19:11 ✔ [SUCCESS] GitHub repo go-webapp-devstream-demo removed.
182+ 2022-12-02 16:19:11 ℹ [INFO] Prepare to delete 'repo-scaffolding_golang-github ' from States.
183+ 2022-12-02 16:19:11 ✔ [SUCCESS] Tool (repo-scaffolding/golang-github ) delete done.
184+ 2022-12-02 16:19:11 ℹ [INFO] -------------------- [ Processing done. ] --------------------
185+ 2022-12-02 16:19:11 ✔ [SUCCESS] All plugins deleted successfully.
186+ 2022-12-02 16:19:11 ✔ [SUCCESS] Delete finished.
211187```
212188
213189现在,如果你看看 GitHub 仓库列表,所有东西都被 DevStream 消灭了。妙哉!
214190
215- > 可选: 你也可以通过运行: ` rm devstream.state ` 来删除 DevStream 状态文件(现在应该是个空文件)。
191+ 你也可以通过运行 ` rm devstream.state ` 来删除 DevStream 状态文件(现在应该是个空文件)。
0 commit comments