# Strapi 云端 - CLI 部署

> Source: https://strapi.nodejs.cn/cloud/getting-started/deployment-cli

🌐 Project deployment with the Command Line Interface (CLI)

使用 `strapi login`、`strapi link` 和 `strapi 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 仪表板部署项目](/cloud/getting-started/deployment)）。
- 拥有一个已创建的 Strapi 项目（参见 CMS 文档中的 [从 CLI 安装](/cms/installation/cli)），存储在本地。项目必须小于 100MB。
- 确保你的硬盘中有可用存储空间，用于存放操作系统的临时文件夹。

:::

## 登录 Strapi 云 {#logging-in-to-strapi-cloud}

🌐 Logging in to Strapi Cloud

1. 打开你的终端。
2. 导航到存储在本地电脑上的 Strapi 项目的文件夹。
3. 输入以下命令以登录 Strapi Cloud：

  ```bash
  yarn strapi login
  ```
  ```bash
  npx run strapi login
  ```

4. 在自动打开的浏览器窗口中，确认显示的代码与终端消息中写的代码相同。
5. 仍然在浏览器窗口中，选择通过 Google、GitHub 或 GitLab 登录。窗口应在不久后确认登录成功。

## 将本地项目链接到 Strapi Cloud {#linking-your-local-project-to-strapi-cloud}

🌐 Linking your local project to Strapi Cloud

1. 在你的终端中，仍然在你的 Strapi 项目文件夹中，输入以下命令将本地项目链接到你现有的 Strapi Cloud 项目：

  ```bash
  yarn strapi link
  ```
  ```bash
  npx run strapi link
  ```

2. 从终端显示的列表中选择你想要关联的 Strapi Cloud 项目。

## 部署你的项目 {#deploying-your-project}

🌐 Deploying your project

1. 在你的终端中，仍然在你的 Strapi 项目文件夹中，输入以下命令来部署项目：

  ```bash
  yarn strapi deploy
  ```
  ```bash
  npx run strapi deploy
  ```

2. 在终端中跟随进度条，直到确认项目已成功通过 Strapi Cloud 部署。

### 自动部署后续更改 {#automatically-deploying-subsequent-changes}

🌐 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 仓库上，例如 [GitHub](https://www.github.com) 或 [GitLab](https://www.gitlab.com)。
2. 将你的 Strapi Cloud 项目连接到仓库（请参阅 [项目设置 > 常规](/cloud/projects/settings#general) 中的 _已连接仓库_ 设置）。
3. 仍然在 _项目设置 > 常规_ 选项卡中，勾选“在每次推送到此分支的提交时部署项目”设置框。从现在起，每当提交推送到已连接的 Git 仓库时，都会触发一次新的 Strapi Cloud 部署。

:::note

自动部署与所有其他部署方法兼容，因此一旦连接了 git 仓库，你可以从 [Cloud 仪表板](/cloud/projects/deploys)、[CLI](/cloud/cli/cloud-cli#strapi-deploy) 或通过向已连接的仓库推送新提交来触发对 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](/cloud/projects/deploys), [from the CLI](/cloud/cli/cloud-cli#strapi-deploy), or by pushing new commits to your connected repository.

:::

##  接下来做什么？ {#icon-namefast-forward--what-to-do-next}

既然你已经通过命令行接口部署了项目，我们鼓励你探索以下想法，以获得更完整的 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:

- 访问 Cloud 仪表板以查看你 Strapi 项目的[有用指标和信息](/cloud/projects/overview)。
- 请查看完整的 [命令行接口文档](/cloud/cli/cloud-cli) 以了解其他可用命令。
