快速开始

在这个“快速开始”流程中,你将使用 DevStream 自动化地完成以下工作:

  • 在 GitHub 上创建一个包含了自动生成的 Golang Gin 框架代码的 web 应用代码库;
  • 为这个代码库配置好 GitHub Actions 工作流。

1 下载

进入你的工作目录,运行:

Bash

  1. sh -c "$(curl -fsSL https://download.devstream.io/download.sh)"

提示

上面的命令会做以下事情:

  • 检测你的操作系统和芯片架构;
  • 找到最新版本的 dtm 二进制文件;
  • 根据操作系统和架构下载正确的 dtm 二进制文件;
  • 授予二进制文件执行权限。

可选

你可以将 dtm 移到 PATH 中。例如:mv dtm /usr/local/bin/

更多安装方式详见安装dtm


2 配置

运行以下命令来生成 quickstart 的模板配置文件 config.yaml

Bash

  1. ./dtm show config -t quickstart > config.yaml

运行以下命令以设置这些环境变量(记得替换双引号内的值):

Bash

  1. export GITHUB_USER="<YOUR_GITHUB_USER_NAME_HERE>"
  2. export DOCKERHUB_USERNAME="<YOUR_DOCKER_HUB_USER_NAME_HERE>"
  3. export IMAGE_REPO_PASSWORD="<YOUR_DOCKER_HUB_USER_NAME_HERE>"
  4. export GITHUB_TOKEN="<YOUR_GITHUB_PERSONAL_ACCESS_TOKEN_HERE>"

提示

参考 Personal Access Tokendtm 生成新的 GITHUB_TOKEN

对于“快速开始”,你只需要勾选 repoworkflowdelete_repo 权限。

接着,你可以运行以下命令,以使用环境变量来修改配置文件:

macOS 或基于 FreeBSD 的操作系统GNU Linux 用户

  1. sed -i.bak "s@YOUR_GITHUB_USERNAME_CASE_SENSITIVE@${GITHUB_USER}@g" config.yaml
  2. sed -i.bak "s@YOUR_DOCKER_USERNAME@${DOCKERHUB_USERNAME}@g" config.yaml
  1. sed -i "s@YOUR_GITHUB_USERNAME_CASE_SENSITIVE@${GITHUB_USER}@g" config.yaml
  2. sed -i "s@YOUR_DOCKER_USERNAME@${DOCKERHUB_USERNAME}@g" config.yaml

3 初始化(Init)

运行:

Bash

  1. ./dtm init -f config.yaml

你会看到类似下面的输出

  1. 2022-12-12 11:40:34 [INFO] Using dir </Users/stein/.devstream/plugins> to store plugins.
  2. 2022-12-12 11:40:34 [INFO] -------------------- [ repo-scaffolding-darwin-arm64_0.10.2 ] --------------------
  3. 2022-12-12 11:40:35 [INFO] Downloading: [repo-scaffolding-darwin-arm64_0.10.2.so] ...
  4. 87.75 MiB / 87.75 MiB [================================] 100.00% 7.16 MiB/s 12s
  5. 2022-12-12 11:40:47 [SUCCESS] [repo-scaffolding-darwin-arm64_0.10.2.so] download succeeded.
  6. 2022-12-12 11:40:48 [INFO] Downloading: [repo-scaffolding-darwin-arm64_0.10.2.md5] ...
  7. 33 B / 33 B [=========================================] 100.00% 115.84 KiB/s 0s
  8. 2022-12-12 11:40:48 [SUCCESS] [repo-scaffolding-darwin-arm64_0.10.2.md5] download succeeded.
  9. 2022-12-12 11:40:48 [INFO] Initialize [repo-scaffolding-darwin-arm64_0.10.2] finished.
  10. 2022-12-12 11:40:48 [INFO] -------------------- [ repo-scaffolding-darwin-arm64_0.10.2 ] --------------------
  11. 2022-12-12 11:40:48 [INFO] -------------------- [ github-actions-darwin-arm64_0.10.2 ] --------------------
  12. 2022-12-12 11:40:48 [INFO] Downloading: [github-actions-darwin-arm64_0.10.2.so] ...
  13. 90.27 MiB / 90.27 MiB [================================] 100.00% 10.88 MiB/s 8s
  14. 2022-12-12 11:40:57 [SUCCESS] [github-actions-darwin-arm64_0.10.2.so] download succeeded.
  15. 2022-12-12 11:40:57 [INFO] Downloading: [github-actions-darwin-arm64_0.10.2.md5] ...
  16. 33 B / 33 B [=========================================] 100.00% 145.46 KiB/s 0s
  17. 2022-12-12 11:40:57 [SUCCESS] [github-actions-darwin-arm64_0.10.2.md5] download succeeded.
  18. 2022-12-12 11:40:57 [INFO] Initialize [github-actions-darwin-arm64_0.10.2] finished.
  19. 2022-12-12 11:40:57 [INFO] -------------------- [ github-actions-darwin-arm64_0.10.2 ] --------------------
  20. 2022-12-12 11:40:57 [SUCCESS] Initialize finished.

4 应用(Apply)

运行:

Bash

  1. ./dtm apply -f config.yaml -y

你会看到类似下面的输出

  1. 2022-12-12 11:44:39 [INFO] Apply started.
  2. 2022-12-12 11:44:39 [INFO] Using local backend. State file: devstream.state.
  3. 2022-12-12 11:44:39 [INFO] Tool (repo-scaffolding/golang-github) found in config but doesn't exist in the state, will be created.
  4. 2022-12-12 11:44:39 ℹ [INFO] Tool (github-actions/default) found in config but doesn't exist in the state, will be created.
  5. 2022-12-12 11:44:39 [INFO] Start executing the plan.
  6. 2022-12-12 11:44:39 [INFO] Changes count: 2.
  7. 2022-12-12 11:44:39 [INFO] -------------------- [ Processing progress: 1/2. ] --------------------
  8. 2022-12-12 11:44:39 [INFO] Processing: (repo-scaffolding/golang-github) -> Create ...
  9. 2022-12-12 11:44:39 [INFO] github start to download repoTemplate...2022-12-12 11:44:42 [SUCCESS] The repo go-webapp-devstream-demo has been created.
  10. 2022-12-12 11:44:49 [SUCCESS] Tool (repo-scaffolding/golang-github) Create done.
  11. 2022-12-12 11:44:49 [INFO] -------------------- [ Processing progress: 2/2. ] --------------------
  12. 2022-12-12 11:44:49 [INFO] Processing: (github-actions/default) -> Create ...
  13. 2022-12-12 11:44:57 [SUCCESS] Tool (github-actions/default) Create done.
  14. 2022-12-12 11:44:57 [INFO] -------------------- [ Processing done. ] --------------------
  15. 2022-12-12 11:44:57 [SUCCESS] All plugins applied successfully.
  16. 2022-12-12 11:44:57 [SUCCESS] Apply finished.

5 检查结果

前往你的 GitHub 仓库列表,可以看到一个新的仓库 go-webapp-devstream-demo 已经被创建了。

包含了 Golang web 应用程序的脚手架代码,并正确设置了 GitHub Actions CI 工作流。

DevStream 在生成仓库脚手架和创建工作流时的代码提交,已经触发了 CI,且工作流已经成功地运行完毕,如下图所示:

快速开始 - 图1


6 清理

运行:

Bash

  1. ./dtm delete -f config.yaml

输入 y 然后回车,你会看到类似下面的输出:

输出

  1. 2022-12-12 12:29:00 [INFO] Delete started.
  2. 2022-12-12 12:29:00 [INFO] Using local backend. State file: devstream.state.
  3. 2022-12-12 12:29:00 [INFO] Tool (github-actions/default) will be deleted.
  4. 2022-12-12 12:29:00 [INFO] Tool (repo-scaffolding/golang-github) will be deleted.
  5. Continue? [y/n]
  6. Enter a value (Default is n): y
  7. 2022-12-12 12:29:00 [INFO] Start executing the plan.
  8. 2022-12-12 12:29:00 [INFO] Changes count: 2.
  9. 2022-12-12 12:29:00 [INFO] -------------------- [ Processing progress: 1/2. ] --------------------
  10. 2022-12-12 12:29:00 [INFO] Processing: (github-actions/default) -> Delete ...
  11. 2022-12-12 12:29:02 [INFO] Prepare to delete 'github-actions_default' from States.
  12. 2022-12-12 12:29:02 [SUCCESS] Tool (github-actions/default) delete done.
  13. 2022-12-12 12:29:02 [INFO] -------------------- [ Processing progress: 2/2. ] --------------------
  14. 2022-12-12 12:29:02 [INFO] Processing: (repo-scaffolding/golang-github) -> Delete ...
  15. 2022-12-12 12:29:03 [SUCCESS] GitHub repo go-webapp-devstream-demo removed.
  16. 2022-12-12 12:29:03 [INFO] Prepare to delete 'repo-scaffolding_golang-github' from States.
  17. 2022-12-12 12:29:03 [SUCCESS] Tool (repo-scaffolding/golang-github) delete done.
  18. 2022-12-12 12:29:03 [INFO] -------------------- [ Processing done. ] --------------------
  19. 2022-12-12 12:29:03 [SUCCESS] All plugins deleted successfully.
  20. 2022-12-12 12:29:03 [SUCCESS] Delete finished.

现在,如果你看看 GitHub 仓库列表,所有东西都被 DevStream 消灭了。妙哉!

你也可以通过运行 rm devstream.state 来删除 DevStream 状态文件(现在应该是个空文件)。