将你的 Astro 网站部署到 Zerops
Zerops 是一个以开发优先的云平台,可用于部署静态和服务端渲染的 Astro 网站。
本指南将引导你在 Zerops 上设置和部署静态 和 SSR 服务端渲染的 Astro 站点。
:::tip[Astro x Zerops 速览]想在不安装或设置任何东西的情况下测试在 Zerops 上运行 Astro 吗?使用 Zerops x Astro - Static 或 Zerops x Astro - SSR 存储库,一键部署示例 Astro 站点。:::
在 Zerops 上运行应用程序需要两个步骤:
- 创建项目
- 触发构建和部署流水线
:::note一个 Zerops 项目可以包含多个 Astro 站点。:::
在 Zerops 上部署 Astro 静态站点
创建 Astro 静态站点的项目和服务
可以通过 Project add 向导或使用 yaml 结构导入项目和服务:
# 参考 https://docs.zerops.io/references/import 了解更多
project:
name: recipe-astro
services:
- hostname: app
type: static这将创建一个名为 recipe-astro 的项目,其中包含一个名为 app 的 Zerops 静态服务。
部署你的 Astro 静态站点
要告诉 Zerops 如何构建和运行你的站点,请在存储库中添加 zerops.yml 文件:
# 参考 https://docs.zerops.io/zerops-yml/specification 了解更多
zerops:
- setup: app
build:
base: nodejs@20
buildCommands:
- npm i
- npm build
deployFiles:
- dist/~
run:
base: static
# 参考 https://docs.zerops.io/zerops-yml/specification 了解更多
zerops:
- setup: app
build:
base: nodejs@20
buildCommands:
- pnpm i
- pnpm build
deployFiles:
- dist/~
run:
base: static
# 参考 https://docs.zerops.io/zerops-yml/specification 了解更多
zerops:
- setup: app
build:
base: nodejs@20
buildCommands:
- yarn
- yarn build
deployFiles:
- dist/~
run:
base: static
现在你可以 使用 Zerops CLI 触发构建和部署流水线,或者通过服务详情内部将 app 服务与你的 GitHub / GitLab 存储库连接。
在 Zerops 上部署 Astro SSR 站点
更新脚本
更新你的 start 脚本以运行 Node 适配器的服务器输出。
"scripts": {
"start": "node ./dist/server/entry.mjs",
} 创建 Astro SSR(Node.js)的项目和服务
可以通过 Project add 向导或使用 yaml 结构导入项目和服务:
# 参考 https://docs.zerops.io/references/import 了解更多
project:
name: recipe-astro
services:
- hostname: app
type: nodejs@20这将创建一个名为 recipe-astro 的项目,其中包含一个名为 app 的 Zerops Node.js 服务。
部署你的 Astro SSR 站点
要告诉 Zerops 如何使用官方的 Astro Node.js 适配器 在 standalone 模式下构建和运行你的站点,请在存储库中添加 zerops.yml 文件:
# 参考 https://docs.zerops.io/zerops-yml/specification 了解更多
zerops:
- setup: app
build:
base: nodejs@20
buildCommands:
- npm i
- npm run build
deployFiles:
- dist
- package.json
- node_modules
run:
base: nodejs@20
ports:
- port: 3000
httpSupport: true
envVariables:
PORT: 3000
HOST: 0.0.0.0
start: npm start
# 参考 https://docs.zerops.io/zerops-yml/specification 了解更多
zerops:
- setup: app
build:
base: nodejs@20
buildCommands:
- pnpm i
- pnpm run build
deployFiles:
- dist
- package.json
- node_modules
run:
base: nodejs@20
ports:
- port: 3000
httpSupport: true
envVariables:
PORT: 3000
HOST: 0.0.0.0
start: pnpm start
# 参考 https://docs.zerops.io/zerops-yml/specification 了解更多
zerops:
- setup: app
build:
base: nodejs@20
buildCommands:
- yarn
- yarn build
deployFiles:
- dist
- package.json
- node_modules
run:
base: nodejs@20
ports:
- port: 3000
httpSupport: true
envVariables:
PORT: 3000
HOST: 0.0.0.0
start: yarn start
现在你可以 使用 Zerops CLI 触发构建和部署流水线,或者通过服务详情内部将 app 服务与你的 GitHub / GitLab 存储库连接。
使用 Zerops CLI 触发流水线(zcli)
安装 Zerops CLI。
# 要直接下载 zcli 二进制文件, # 请使用 https://github.com/zeropsio/zcli/releases npm i -g @zerops/zcli在 Zerops 中打开
Settings > Access Token Management并生成一个新的访问令牌。用以下命令使用访问令牌登录:
zcli login <token>导航到应用的根目录(
zerops.yml所在的位置),并运行以下命令以触发部署:zcli push