将你的 Astro 网站部署到 Zerops
Zerops 是一个以开发优先的云平台,可用于部署服务端渲染的 Astro 网站。
本指南将指导你使用 Node.js 适配器将 Astro 项目部署到 Zerops。
前提条件
段落标题 前提条件- 使用 @astrojs/node服务端渲染适配器 的 Astro 项目
- 一个 Zerops 账户 - 如果你还没有账户,可以免费创建一个 Zerops 账户。
你可以直接将 Zerops x Astro - Node.js 示例应用 导入到你的 Zerops 控制面板,并一键部署!
project:  name: astroservices:  - hostname: astronode    type: nodejs@20    buildFromGit: https://github.com/zeropsio/recipe-astro-nodejs    ports:      - port: 4321        httpSupport: true    enableSubdomainAccess: true    minContainers: 1创建一个 Zerops Node.js 项目
段落标题 创建一个 Zerops Node.js 项目你可以通过 Zerops project add 向导 为你的 Astro 网站创建一个 Node.js 服务,或者通过使用 .yaml 导入一个 Astro 网站。
以下 YAML 结构将设置一个名为 my-astro-sites 的项目,其中包含一个名为 hellothere 的 Node.js v20 服务。一个 Zerops 项目可以包含多个 Astro 应用。
project:  name: my-astro-sitesservices:  - hostname: hellothere    type: nodejs@20    ports:      - port: 4321        httpSupport: true    minContainers: 1在 Zerops 上构建和部署你的应用
段落标题 在 Zerops 上构建和部署你的应用现在你已经在 Zerops 上准备好了一个 Node.js 服务,你需要在项目的根目录创建一个 zerops.yml 文件,以触发在 Zerops 上的构建和部署流程。
以下示例展示了如何为具有主机名 hellothere 的示例项目配置所需的构建和运行操作:
  zerops:    - setup: hellothere      build:        base: nodejs@20        buildCommands:          - npm i          - npm run build        deploy:          - dist          - package.json          - node_modules        cache:          - node_modules          - package-lock.json      run:        start: node dist/server/entry.mjs      envVariables:        HOST: 0.0.0.0        NODE_ENV: production  zerops:    - setup: hellothere      build:        base: nodejs@20        buildCommands:          - pnpm i          - pnpm run build        deploy:          - dist          - package.json          - node_modules        cache:          - node_modules          - pnpm-lock.yaml      run:        start: node dist/server/entry.mjs      envVariables:        HOST: 0.0.0.0        NODE_ENV: production  zerops:    - setup: astronode      build:        base: nodejs@20        buildCommands:          - yarn          - yarn build        deploy:          - dist          - package.json          - node_modules        cache:          - node_modules          - yarn.lock      run:        start: node dist/server/entry.mjs      envVariables:        HOST: 0.0.0.0        NODE_ENV: production通过 GitHub / GitLab 触发流水线
段落标题 通过 GitHub / GitLab 触发流水线要在推送到分支或新发布时设置连续部署,请转到你的 Node.js 服务详情,并将你的 Zerops 服务与 GitHub 或 GitLab 仓库连接。
使用 Zerops CLI (zcli) 触发流水线
段落标题 使用 Zerops CLI (zcli) 触发流水线- 
安装 Zerops CLI。 Terminal window # 要直接下载 zcli 二进制文件,# 请使用 https://github.com/zeropsio/zcli/releasesnpm i -g @zerops/zcli
- 
在 Zerops 应用中打开 Settings > Access Token Management并生成一个新的访问令牌。
- 
使用以下命令和你的访问令牌登录: Terminal window zcli login <token>
- 
导航到你的应用根目录( zerops.yml文件所在位置),运行以下命令以触发部署:Terminal window zcli push