跳转到内容

将你的 Astro 网站部署到 Zerops

Zerops 是一个开发者优先的云平台,可用于部署静态和 SSR 的 Astro 网站。

本指南将引导你在 Zerops 上设置和部署静态和 SSR 的 Astro 网站。

在 Zerops 上运行应用需要两个步骤

  1. 创建项目
  2. 触发构建和部署流水线

项目和服务既可以通过添加项目向导添加,也可以使用 yaml 结构导入。

# see https://docs.zerops.io/references/import for full reference
project:
name: recipe-astro
services:
- hostname: app
type: static

这将创建一个名为 recipe-astro 的项目,其中包含一个名为 app 的 Zerops 静态服务。

要告诉 Zerops 如何构建和运行你的网站,请将 zerops.yml 文件添加到你的仓库中。

zerops.yml
# see https://docs.zerops.io/zerops-yml/specification for full reference
zerops:
- setup: app
build:
base: nodejs@20
buildCommands:
- npm i
- npm build
deployFiles:
- dist/~
run:
base: static

现在你可以使用 Zerops CLI 触发构建和部署流水线,或者在服务详情中将 app 服务与你的 GitHub / GitLab 仓库连接。

更新你的 start 脚本,以运行 Node 适配器的服务器输出。

package.json
"scripts": {
"start": "node ./dist/server/entry.mjs",
}

项目和服务既可以通过添加项目向导添加,也可以使用 yaml 结构导入。

# see https://docs.zerops.io/references/import for full reference
project:
name: recipe-astro
services:
- hostname: app
type: nodejs@20

这将创建一个名为 recipe-astro 的项目,其中包含一个名为 app 的 Zerops Node.js 服务。

要告诉 Zerops 如何在 standalone 模式下使用官方的 Astro Node.js 适配器来构建和运行你的网站,请将 zerops.yml 文件添加到你的仓库中。

zerops.yml
# see https://docs.zerops.io/zerops-yml/specification for full reference
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

现在你可以使用 Zerops CLI 触发构建和部署流水线,或者在服务详情中将 app 服务与你的 GitHub / GitLab 仓库连接。

  1. 安装 Zerops CLI。

    终端窗口
    # To download the zcli binary directly,
    # use https://github.com/zeropsio/zcli/releases
    npm i -g @zerops/zcli
  2. 在 Zerops 应用中打开 设置 > 访问令牌管理 并生成一个新的访问令牌。

  3. 使用以下命令和你的访问令牌登录

    终端窗口
    zcli login <token>
  4. 导航到你的应用根目录(zerops.yml 所在的位置),然后运行以下命令来触发部署

    终端窗口
    zcli push

更多部署指南

贡献 社区 赞助