CLI 安装

CLI 是 Erda 为开发者提供的命令行工具,您可以通过该工具在终端设备上轻松构建 Erda 应用。

安装操作

  1. curl https://raw.githubusercontent.com/erda-project/erda/master/tools/cli/install.sh | sh

tip 提示 脚本安装将根据安装机器选择合适的二进制安装文件,当前仅支持 macOS 和 Linux。默认安装最新的 Release 版本。安装工具依赖 jq 和 curl 命令工具。

版本

  • 安装历史版本 v1.5.0

    1. curl https://raw.githubusercontent.com/erda-project/erda/master/tools/cli/install.sh | sh -s -- v1.5.0
  • 安装开发版本

    1. curl https://raw.githubusercontent.com/erda-project/erda/master/tools/cli/install.sh | sh -s -- alpha

安装验证

完成安装后,您可以通过 erda-cli version 查看版本信息。

  1. $ erda-cli version
  2. Version: 2.1-alpha
  3. BuildTime: 2022-03-11 14:09:49
  4. GoVersion: go version go1.16.5 darwin/arm64
  5. CommitID: 389d769e76e600e4b9993db26c279c21e91f8297

您可以通过 erda-cli help 命令列出所有可用的 Erda Command,再通过子命令的 help 信息查看详细用法。

  1. $ erda-cli help
  2. _/_/_/_/ _/_/_/ _/_/_/ _/_/
  3. _/ _/ _/ _/ _/ _/ _/
  4. _/_/_/ _/_/_/ _/ _/ _/_/_/_/
  5. _/ _/ _/ _/ _/ _/ _/
  6. _/_/_/_/ _/ _/ _/_/_/ _/ _/
  7. Usage:
  8. erda-cli [command]
  9. Available Commands:
  10. build create a pipeline and run it
  11. clone clone project or application from Erda
  12. completion generate the autocompletion script for the specified shell
  13. config Config Project workspace configurations operation,including set, get, update, delete
  14. create create project
  15. ext extensions operation sets,including search, pull, push, retag
  16. help Help about any command
  17. migrate Erda MySQL Migrate
  18. project-deployment Project workspace deployment operation,including stop, start
  19. push push project to a Erda platform
  20. version show erda version info
  21. view View pipeline status
  22. Flags:
  23. -h, --help help for erda-cli
  24. --host string Erda host to visit (e.g. https://erda.cloud)
  25. --interactive if true, interactive with user (default true)
  26. -p, --password string Erda password to authenticate
  27. --remote string the remote for Erda repo (default "origin")
  28. -u, --username string Erda username to authenticate
  29. -V, --verbose if true, enable verbose mode
  30. Use "erda-cli [command] --help" for more information about a command.

自动补全

您可以通过 erda-cli completion -h 命令查看如何配置多种终端的自动补全(macOS 中推荐使用 zsh)。

  1. $ erda-cli completion -h
  2. Generate the autocompletion script for erda-cli for the specified shell.
  3. See each sub-command's help for details on how to use the generated script.
  4. Usage:
  5. erda-cli completion [command]
  6. Available Commands:
  7. bash generate the autocompletion script for bash
  8. fish generate the autocompletion script for fish
  9. powershell generate the autocompletion script for powershell
  10. zsh generate the autocompletion script for zsh

例如,在 Mac 上可参考 help 信息配置 zsh 的自动补全。

  1. $ erda-cli completion zsh -h
  2. Generate the autocompletion script for the zsh shell.
  3. If shell completion is not already enabled in your environment you will need
  4. to enable it. You can execute the following once:
  5. $ echo "autoload -U compinit; compinit" >> ~/.zshrc
  6. To load completions for every new session, execute once:
  7. # Linux:
  8. $ erda-cli completion zsh > "${fpath[1]}/_erda-cli"
  9. # macOS:
  10. $ erda-cli completion zsh > /usr/local/share/zsh/site-functions/_erda-cli
  11. You will need to start a new shell for this setup to take effect.

配置后的使用效果如下:

  1. $ erda-cli c[tab]
  2. clone -- clone project or application from Erda
  3. completion -- generate the autocompletion script for the specified shell
  4. create -- create project
  5. $ erda-cli completion [tab]
  6. bash -- generate the autocompletion script for bash
  7. fish -- generate the autocompletion script for fish
  8. powershell -- generate the autocompletion script for powershell
  9. zsh -- generate the autocompletion script for zsh
  10. $ erda-cli create --[tab]
  11. --description -- description of the project
  12. --host -- Erda host to visit (e.g. https://erda.cloud)
  13. --init-package -- package for init the project
  14. --interactive -- if true, interactive with user
  15. --name -- the name of the project
  16. --org -- the name of an organization
  17. --password -- Erda password to authenticate
  18. --remote -- the remote for Erda repo
  19. --username -- Erda username to authenticate
  20. --verbose -- if true, enable verbose mode
  21. --wait-import -- minutes wait for package to be import

配置

由于 CLI 将调用 Git 命令完成代码的相关操作,建议设置如下:

  1. git config --global user.name <YOUR_USERNAME>
  2. git config --global user.email <YOUR_EMAIL>
  3. git config --global credential.helper store

容器镜像安装

CLI 支持通过容器镜像方式进行安装使用。

  1. docker pull registry.erda.cloud/erda/cli:2.1-alpha

完成安装后,您可以通过 erda-cli version 查看版本信息。

  1. $ docker run --rm registry.erda.cloud/erda/cli:2.1-alpha version
  2. Version: 2.1
  3. BuildTime: 2022-03-23 16:31:34
  4. GoVersion: go version go1.16.3 linux/amd64
  5. CommitID: affb9103763f29cdf0461c43434ef13efb08cd29
  6. DockerImage: registry.erda.cloud/erda/cli:2.1-alpha-20220323162540-affb910

版本

  • 稳定版本:对应 Erda 版本为 v2.1.x,镜像版本为 2.1,即 registry.erda.cloud/erda/cli:2.1

  • 内测版本:对应 Erda 版本为 v2.1.x,镜像版本为 2.1-alpha,即 registry.erda.cloud/erda/cli:2.1-alpha

配置

CLI 的多数命令在运行时依赖于本地 Session 文件、本地工作空间等,因此通常需挂载多个文件至运行容器。

  1. docker run --rm -it -v ${HOME}:/root -e workspace=${PWD} -e home=${HOME} registry.erda.cloud/erda/cli:2.1-alpha

其中可通过 -e 参数传递 Home 目录、当前目录,通过 -v 参数挂住 Home 目录。

  • 鉴于容器的命令较长,可使用 alias 简短命令:

    1. alias erda-cli='docker run --rm -it -v ${HOME}:/root -e workspace=${PWD} -e home=${HOME} registry.erda.cloud/erda/cli:2.1-alpha'
  • 由于 CLI 将调用 Git 命令完成代码的相关操作,建议设置如下:

    1. git config --global user.name <YOUR_USERNAME>
    2. git config --global user.email <YOUR_EMAIL>
    3. git config --global credential.helper store