Skip to main content

使用命令行接口 (CLI) 进行项目部署

🌐 Project deployment with the Command Line Interface (CLI)

Page summary:

使用 strapi loginstrapi linkstrapi deploy CLI 命令将 Strapi 项目部署到 Strapi Cloud,并可选择在 git 仓库提交时自动部署。

🌐 Deploy a Strapi project to Strapi Cloud using the strapi login, strapi link, and strapi deploy CLI commands, with optional automatic deployment on git repository commits.

这是一个使用命令行接口在 Strapi Cloud 上部署你的项目的逐步指南。

🌐 This is a step-by-step guide for deploying your project on Strapi Cloud using the Command Line Interface.

Prerequisites

在使用命令行接口将你的 Strapi 应用部署到 Strapi Cloud 之前,你需要具备以下先决条件:

🌐 Before you can deploy your Strapi application on Strapi Cloud using the Command Line Interface, you need to have the following prerequisites:

  • 拥有一个 Google、GitHub 或 GitLab 账号。
  • 已经创建了 Strapi Cloud 项目(请参见 使用 Cloud 仪表板部署项目)。
  • 拥有一个已创建的 Strapi 项目(参见 CMS 文档中的 从 CLI 安装),存储在本地。项目必须小于 100MB。
  • 确保你的硬盘中有可用存储空间,用于存放操作系统的临时文件夹。

登录 Strapi 云

🌐 Logging in to Strapi Cloud

  1. 打开你的终端。
  2. 导航到存储在本地电脑上的 Strapi 项目的文件夹。
  3. 输入以下命令以登录 Strapi Cloud:
terminal
yarn strapi login
  1. 在自动打开的浏览器窗口中,确认显示的代码与终端消息中写的代码相同。
  2. 仍然在浏览器窗口中,选择通过 Google、GitHub 或 GitLab 登录。窗口应在不久后确认登录成功。

将本地项目链接到 Strapi Cloud

🌐 Linking your local project to Strapi Cloud

  1. 在你的终端中,仍然在你的 Strapi 项目文件夹中,输入以下命令将本地项目链接到你现有的 Strapi Cloud 项目:
terminal
yarn strapi link
  1. 从终端显示的列表中选择你想要关联的 Strapi Cloud 项目。

部署你的项目

🌐 Deploying your project

  1. 在你的终端中,仍然在你的 Strapi 项目文件夹中,输入以下命令来部署项目:
terminal
yarn strapi deploy
  1. 在终端中跟随进度条,直到确认项目已成功通过 Strapi Cloud 部署。

自动部署后续更改

🌐 Automatically deploying subsequent changes

默认情况下,在使用 Cloud CLI 部署项目时,每次进行更改后,都需要手动再次通过运行相应的 deploy 命令来部署所有后续更改。

🌐 By default, when deploying a project with the Cloud CLI, you need to manually deploy again all subsequent changes by running the corresponding deploy command everytime you make a change.

另一种选择是通过 git 仓库启用自动部署。操作步骤如下:

🌐 Another option is to enable automatic deployment through a git repository. To do so:

  1. 将你的代码托管在 git 仓库上,例如 GitHubGitLab
  2. 将你的 Strapi Cloud 项目连接到仓库(请参阅 项目设置 > 常规 中的 已连接仓库 设置)。
  3. 仍然在 项目设置 > 常规 选项卡中,勾选“在每次推送到此分支的提交时部署项目”设置框。从现在起,每当提交推送到已连接的 Git 仓库时,都会触发一次新的 Strapi Cloud 部署。
Note

自动部署与所有其他部署方法兼容,因此一旦连接了 git 仓库,你可以从 Cloud 仪表板CLI 或通过向已连接的仓库推送新提交来触发对 Strapi Cloud 的新部署。

🌐 Automatic deployment is compatible with all other deployment methods, so once a git repository is connected, you can trigger a new deployment to Strapi Cloud from the Cloud dashboard, from the CLI, or by pushing new commits to your connected repository.

接下来做什么?

既然你已经通过命令行接口部署了项目,我们鼓励你探索以下想法,以获得更完整的 Strapi Cloud 体验:

🌐 Now that you have deployed your project via the Command Line Interface, we encourage you to explore the following ideas to have an even more complete Strapi Cloud experience: