Digital Ocean
将你的 Mastra 应用部署到 Digital Ocean 的应用平台和 Droplets。
🌐 Deploy your Mastra applications to Digital Ocean's App Platform and Droplets.
本指南假设你的 Mastra 应用是使用默认的 npx create-mastra@latest 命令创建的。有关如何创建新的 Mastra 应用的更多信息,请参阅我们的入门指南
说明Direct link to 说明
🌐 Instructions
- App Platform
- Droplets
先决条件
- 包含你 Mastra 应用的 Git 仓库。这可以是 GitHub 仓库、GitLab 仓库,或任何其他兼容的源代码提供商。
- 一个 Digital Ocean 账户
部署步骤
创建新应用
🌐 Create a new App
- 登录到你的 Digital Ocean 仪表板。
- 导航到 应用平台 服务。
- 选择你的源提供商并创建一个新应用。
配置部署源
🌐 Configure Deployment Source
- 连接并选择你的仓库。你也可以选择一个容器镜像或示例应用。
- 选择你要部署的分支。
- 如有必要,请配置源目录。如果你的 Mastra 应用使用默认目录结构,此处无需操作。
- 前往下一步。
配置资源设置和环境变量
🌐 Configure Resource Settings and Environment Variables
- Node.js 构建应该会被自动检测到。
- 配置构建命令:你需要为应用平台添加自定义构建命令,以便成功构建你的 Mastra 项目。根据你的包管理器设置构建命令:
- npm
- pnpm
- Yarn
- Bun
npm run buildpnpm run buildyarn buildbun run build- 为你的 Mastra 应用添加任何所需的环境变量。这包括 API 密钥、数据库 URL 以及其他配置值。
- 你可以在此选择配置你的资源大小。
- 你还可以选择配置的其他内容包括:资源的区域、唯一的应用名称以及资源所属的项目。
- 完成后,你可以在查看配置和价格估算后创建应用。
部署
🌐 Deployment
- 你的应用将被自动构建和部署。
- Digital Ocean 将为你提供一个 URL 来访问你部署的应用。
你现在可以通过 Digital Ocean 提供的 URL 访问已部署的应用。
🌐 You can now access your deployed application at the URL provided by Digital Ocean.
Digital Ocean 应用平台使用的是临时文件系统,这意味着写入文件系统的任何文件都是短期存在的,可能会丢失。请从你的 Mastra 配置中移除所有使用文件 URL 的 LibSQLStore。请使用内存存储(:memory:)或外部存储提供商,如 Turso、PostgreSQL 或 Upstash。
将你的 Mastra 应用部署到 Digital Ocean 的 Droplets 上。
🌐 Deploy your Mastra application to Digital Ocean's Droplets.
先决条件
- 一个 Digital Ocean 账户
- 一个运行 Ubuntu 24+ 的 Droplet
- 一个 A 记录指向你的 droplet 的域名
- 配置的反向代理(例如,使用 nginx)
- 已配置 SSL 证书(例如,使用 Let's Encrypt)
- 在你的云服务器上安装 Node.js 22.13.0 或更高版本
部署步骤
克隆你的Mastra应用
🌐 Clone your Mastra application
连接到你的 Droplet 并克隆你的仓库:
🌐 Connect to your Droplet and clone your repository:
- Public Repository
- Private Repository
git clone https://github.com/<your-username>/<your-repository>.gitgit clone https://<your-username>:<your-personal-access-token>@github.com/<your-username>/<your-repository>.git导航到仓库目录:
🌐 Navigate to the repository directory:
cd "<your-repository>"安装依赖
🌐 Install dependencies
npm install设置环境变量
🌐 Set up environment variables
创建一个
.env文件并添加你的环境变量:🌐 Create a
.envfile and add your environment variables:touch .env编辑
.env文件并添加你的环境变量:🌐 Edit the
.envfile and add your environment variables:OPENAI_API_KEY=<your-openai-api-key>
# Add other required environment variables构建应用
🌐 Build the application
npm run build运行应用
🌐 Run the application
node --env-file=".env" .mastra/output/index.mjsnote你的 Mastra 应用默认将在端口 4111 上运行。请确保你的反向代理已配置为将请求转发到该端口。
连接到你的Mastra服务器Direct link to 连接到你的Mastra服务器
🌐 Connect to your Mastra server
现在,你可以使用 @mastra/client-js 包中的 MastraClient 从客户端应用连接到 Mastra 服务器。
🌐 You can now connect to your Mastra server from your client application using a MastraClient from the @mastra/client-js package.
有关更多信息,请参阅 MastraClient 文档。
🌐 Refer to the MastraClient documentation for more information.
import { MastraClient } from "@mastra/client-js";
const mastraClient = new MastraClient({
baseUrl: "https://<your-domain-name>",
});
下一步Direct link to 下一步
🌐 Next steps