将你的 Astro 网站部署到 Zerops
Zerops 是一个开发者优先的云平台,可用于部署静态和 SSR 的 Astro 网站。
本指南将引导你在 Zerops 上设置和部署静态和 SSR 的 Astro 网站。
想在不安装或设置任何东西的情况下测试在 Zerops 上运行 Astro 吗?使用 Zerops x Astro - Static 或 Zerops x Astro - SSR on Node.js 仓库,你只需单击一下即可部署 Astro 示例网站。
在 Zerops 上运行应用需要两个步骤
- 创建项目
- 触发构建和部署流水线
一个 Zerops 项目可以包含多个 Astro 网站。
在 Zerops 上的 Astro 静态网站
标题为“在 Zerops 上的 Astro 静态网站”的部分为 Astro 静态网站创建项目和服务
标题为“为 Astro 静态网站创建项目和服务”的部分项目和服务既可以通过添加项目
向导添加,也可以使用 yaml 结构导入。
# see https://docs.zerops.io/references/import for full referenceproject: name: recipe-astroservices: - hostname: app type: static
这将创建一个名为 recipe-astro
的项目,其中包含一个名为 app
的 Zerops 静态服务。
部署你的 Astro 静态网站
标题为“部署你的 Astro 静态网站”的部分要告诉 Zerops 如何构建和运行你的网站,请将 zerops.yml
文件添加到你的仓库中。
# see https://docs.zerops.io/zerops-yml/specification for full referencezerops: - setup: app build: base: nodejs@20 buildCommands: - npm i - npm build deployFiles: - dist/~ run: base: static
# see https://docs.zerops.io/zerops-yml/specification for full referencezerops: - setup: app build: base: nodejs@20 buildCommands: - pnpm i - pnpm build deployFiles: - dist/~ run: base: static
# see https://docs.zerops.io/zerops-yml/specification for full referencezerops: - setup: app build: base: nodejs@20 buildCommands: - yarn - yarn build deployFiles: - dist/~ run: base: static
现在你可以使用 Zerops CLI 触发构建和部署流水线,或者在服务详情中将 app
服务与你的 GitHub / GitLab 仓库连接。
在 Zerops 上的 Astro SSR 网站
标题为“在 Zerops 上的 Astro SSR 网站”的部分更新脚本
标题为“更新脚本”的部分更新你的 start
脚本,以运行 Node 适配器的服务器输出。
"scripts": { "start": "node ./dist/server/entry.mjs",}
为 Astro SSR (Node.js) 创建项目和服务
标题为“为 Astro SSR (Node.js) 创建项目和服务”的部分项目和服务既可以通过添加项目
向导添加,也可以使用 yaml 结构导入。
# see https://docs.zerops.io/references/import for full referenceproject: name: recipe-astroservices: - hostname: app type: nodejs@20
这将创建一个名为 recipe-astro
的项目,其中包含一个名为 app
的 Zerops Node.js 服务。
部署你的 Astro SSR 网站
标题为“部署你的 Astro SSR 网站”的部分要告诉 Zerops 如何在 standalone
模式下使用官方的 Astro Node.js 适配器来构建和运行你的网站,请将 zerops.yml
文件添加到你的仓库中。
# see https://docs.zerops.io/zerops-yml/specification for full referencezerops: - 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
# see https://docs.zerops.io/zerops-yml/specification for full referencezerops: - 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
# see https://docs.zerops.io/zerops-yml/specification for full referencezerops: - 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) 触发流水线”的部分-
安装 Zerops CLI。
终端窗口 # To download the zcli binary directly,# use https://github.com/zeropsio/zcli/releasesnpm i -g @zerops/zcli -
在 Zerops 应用中打开
设置 > 访问令牌管理
并生成一个新的访问令牌。 -
使用以下命令和你的访问令牌登录
终端窗口 zcli login <token> -
导航到你的应用根目录(
zerops.yml
所在的位置),然后运行以下命令来触发部署终端窗口 zcli push
相关资源
标题为“资源”的部分- 3 分钟将 Astro 部署到 Zerops
- 在 Zerops 上通过一键部署来部署带 Node.js 的 Astro SSG
- 在 Zerops 上通过一键部署来部署带 Node.js 的 Astro SSR