Skip to main content

Digital Ocean

将你的 Mastra 应用部署到 Digital Ocean 的应用平台和 Droplets。

🌐 Deploy your Mastra applications to Digital Ocean's App Platform and Droplets.

note

本指南假设你的 Mastra 应用是使用默认的 npx create-mastra@latest 命令创建的。有关如何创建新的 Mastra 应用的更多信息,请参阅我们的入门指南

说明
Direct link to 说明

🌐 Instructions

先决条件

  • 包含你 Mastra 应用的 Git 仓库。这可以是 GitHub 仓库、GitLab 仓库,或任何其他兼容的源代码提供商。
  • 一个 Digital Ocean 账户

部署步骤

  1. 创建新应用

    🌐 Create a new App

  2. 配置部署源

    🌐 Configure Deployment Source

    • 连接并选择你的仓库。你也可以选择一个容器镜像或示例应用。
    • 选择你要部署的分支。
    • 如有必要,请配置源目录。如果你的 Mastra 应用使用默认目录结构,此处无需操作。
    • 前往下一步。
  3. 配置资源设置和环境变量

    🌐 Configure Resource Settings and Environment Variables

    • Node.js 构建应该会被自动检测到。
    • 配置构建命令:你需要为应用平台添加自定义构建命令,以便成功构建你的 Mastra 项目。根据你的包管理器设置构建命令:
    npm run build
    • 为你的 Mastra 应用添加任何所需的环境变量。这包括 API 密钥、数据库 URL 以及其他配置值。
    • 你可以在此选择配置你的资源大小。
    • 你还可以选择配置的其他内容包括:资源的区域、唯一的应用名称以及资源所属的项目。
    • 完成后,你可以在查看配置和价格估算后创建应用。
  4. 部署

    🌐 Deployment

    • 你的应用将被自动构建和部署。
    • Digital Ocean 将为你提供一个 URL 来访问你部署的应用。

你现在可以通过 Digital Ocean 提供的 URL 访问已部署的应用。

🌐 You can now access your deployed application at the URL provided by Digital Ocean.

warning

Digital Ocean 应用平台使用的是临时文件系统,这意味着写入文件系统的任何文件都是短期存在的,可能会丢失。请从你的 Mastra 配置中移除所有使用文件 URL 的 LibSQLStore。请使用内存存储(:memory:)或外部存储提供商,如 Turso、PostgreSQL 或 Upstash。

连接到你的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