NetlifyDeployer
NetlifyDeployer 类负责将独立的 Mastra 应用部署到 Netlify。它管理配置和部署,并在基础 Deployer 类的基础上扩展了特定于 Netlify 的功能。
🌐 The NetlifyDeployer class handles deployment of standalone Mastra applications to Netlify. It manages configuration, deployment, and extends the base Deployer class with Netlify specific functionality.
Netlify Functions 使用临时文件系统。请从你的 Mastra 配置中移除任何使用带文件 URL 的 LibSQLStore。可以使用内存存储(:memory:)或外部存储提供商,如 Turso、PostgreSQL 或 Upstash。
安装Direct link to 安装
🌐 Installation
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/deployer-netlify@latest
pnpm add @mastra/deployer-netlify@latest
yarn add @mastra/deployer-netlify@latest
bun add @mastra/deployer-netlify@latest
使用示例Direct link to 使用示例
🌐 Usage example
import { Mastra } from "@mastra/core";
import { NetlifyDeployer } from "@mastra/deployer-netlify";
export const mastra = new Mastra({
deployer: new NetlifyDeployer(),
});
查看 NetlifyDeployer API 参考,以获取所有可用的配置选项。
持续集成Direct link to 持续集成
🌐 Continuous integration
将你的 Mastra 项目的 Git 仓库连接到 Netlify 后,请更新项目设置。在 Netlify 仪表板中,进入 项目配置 > 构建与部署 > 持续部署,然后在 构建设置 下,设置以下内容:
🌐 After connecting your Mastra project’s Git repository to Netlify, update the project settings. In the Netlify dashboard, go to Project configuration > Build & deploy > Continuous deployment, and under Build settings, set the following:
- 构建命令:
npm run build(可选)
环境变量Direct link to 环境变量
🌐 Environment variables
在你第一次部署之前,请确保添加你的应用使用的任何环境变量。例如,如果你使用的是 OpenAI 作为 LLM,你需要在 Netlify 项目设置中设置 OPENAI_API_KEY。
🌐 Before your first deployment, make sure to add any environment variables used by your application. For example, if you're using OpenAI as the LLM, you'll need to set OPENAI_API_KEY in your Netlify project settings.
有关更多详细信息,请参见 环境变量概述。
你的项目现在已配置为自动部署,每当你将代码推送到 GitHub 仓库中配置的分支时,部署就会自动发生。
🌐 Your project is now configured with automatic deployments which occur whenever you push to the configured branch of your GitHub repository.
手动部署Direct link to 手动部署
🌐 Manual deployment
也可以使用 Netlify CLI 手动部署。安装 Netlify CLI 后,从项目根目录运行以下命令即可部署你的应用。你也可以从项目根目录运行 netlify dev 在本地测试你的 Mastra 应用。
🌐 Manual deployments are also possible using the Netlify CLI. With the Netlify CLI installed run the following from your project root to deploy your application. You can also run netlify dev from your project root to test your Mastra application locally.
netlify deploy --prod
在使用 netlify deploy 而不是持续部署时,你需要创建一个包含以下内容的 netlify.toml 文件:
🌐 When using netlify deploy instead of continuous deployment, you need to create a netlify.toml file with these contents:
[build]
command = "npm run build"
publish = ".netlify/v1/functions"
[functions]
directory = ".netlify/v1/functions"
node_bundler = "none"
included_files = [".netlify/v1/functions/**"]
[[redirects]]
from = "/*"
to = "/.netlify/functions/api/:splat"
status = 200
[build.environment]
NODE_VERSION = "22.13.0"
将 build.command 调整为你的项目。
🌐 Adjust the build.command to your project.
构建输出Direct link to 构建输出
🌐 Build output
使用 NetlifyDeployer 构建 Mastra 应用的输出包括项目中的所有代理、工具和工作流,以及在 Netlify 上运行应用所需的 Mastra 特定文件。
🌐 The build output for Mastra applications using the NetlifyDeployer includes all agents, tools, and workflows in your project, along with Mastra-specific files required to run your application on Netlify.
your-project/
└── .netlify/
└── v1/
├── config.json
└── functions/
└── api/
├── index.js
├── package.json
└── node_modules/
NetlifyDeployer 会在 .netlify/v1 中自动生成一个 config.json 配置文件,并包含以下设置:
🌐 The NetlifyDeployer automatically generates a config.json configuration file in .netlify/v1 with the following settings:
{
"functions": {
"directory": ".netlify/v1/functions",
"node_bundler": "none",
"included_files": [".netlify/v1/functions/**"]
},
"redirects": [
{
"force": true,
"from": "/*",
"to": "/.netlify/functions/api/:splat",
"status": 200
}
]
}
下一步Direct link to 下一步
🌐 Next steps