将你的 Astro 站点部署到 Zerops
Zerops 是一个开发优先的云平台,可用于部署静态和 SSR Astro 网站。
¥Zerops is a dev-first cloud platform that can be used to deploy both Static and SSR Astro site.
本指南将引导你在 Zerops 上设置和部署静态和 SSR Astro 站点。
¥This guide will walk you through setting up and deploying both Static and SSR Astro sites on Zerops.
在 Zerops 上运行应用需要两个步骤:
¥Running apps on Zerops requires two steps:
- 创建项目
- 触发构建和部署管道
Zerops 上的 Astro 静态站点
Section titled “Zerops 上的 Astro 静态站点”¥Astro Static site on Zerops
为 Astro Static 创建项目和服务
Section titled “为 Astro Static 创建项目和服务”¥Creating a project and a service for Astro Static
可以通过 Project add 向导添加项目和服务,也可以使用 yaml 结构导入:
¥Projects and services can be added either through a Project add wizard or imported using a yaml structure:
# see https://docs.zerops.io/references/import for full referenceproject: name: recipe-astroservices: - hostname: app type: static这将创建一个名为 recipe-astro 的项目,其中包含名为 app 的 Zerops 静态服务。
¥This will create a project called recipe-astro with a Zerops Static service called app.
部署你的 Astro Static 站点
Section titled “部署你的 Astro Static 站点”¥Deploying your Astro Static site
要告诉 Zerops 如何构建和运行你的网站,请将 zerops.yml 添加到你的存储库:
¥To tell Zerops how to build and run your site, add a zerops.yml to your repository:
# 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现在,你可以通过从服务详细信息内部将 app 服务与你的 GitHub / GitLab 存储库连接起来来 使用 Zerops CLI 触发构建和部署管道 或 app 服务。
¥Now you can trigger the build & deploy pipeline using the Zerops CLI or by connecting the app service with your GitHub / GitLab repository from inside the service detail.
Zerops 上的 Astro SSR 站点
Section titled “Zerops 上的 Astro SSR 站点”¥Astro SSR site on Zerops
¥Update scripts
更新你的 start 脚本以运行来自 Node 适配器的服务器输出。
¥Update your start script to run the server output from the Node adapter.
"scripts": { "start": "node ./dist/server/entry.mjs",}为 Astro SSR(Node.js)创建项目和服务
Section titled “为 Astro SSR(Node.js)创建项目和服务”¥Creating a project and a service for Astro SSR (Node.js)
可以通过 Project add 向导添加项目和服务,也可以使用 yaml 结构导入:
¥Projects and services can be added either through a Project add wizard or imported using a yaml structure:
# see https://docs.zerops.io/references/import for full referenceproject: name: recipe-astroservices: - hostname: app type: nodejs@20这将创建一个名为 recipe-astro 的项目,其中包含名为 app 的 Zerops Node.js 服务。
¥This will create a project called recipe-astro with Zerops Node.js service called app.
部署你的 Astro SSR 站点
Section titled “部署你的 Astro SSR 站点”¥Deploying your Astro SSR site
要告诉 Zerops 如何在 standalone 模式下使用官方 Astro Node.js 适配器 构建和运行你的网站,请将 zerops.yml 文件添加到你的存储库:
¥To tell Zerops how to build and run your site using the official Astro Node.js adapter in standalone mode, add a zerops.yml file to your repository:
# 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现在,你可以通过从服务详细信息内部将 app 服务与你的 GitHub / GitLab 存储库连接起来来 使用 Zerops CLI 触发构建和部署管道 或 app 服务。
¥Now you can trigger the build & deploy pipeline using the Zerops CLI or by connecting the app service with your GitHub / GitLab repository from inside the service detail.
使用 Zerops CLI (zcli) 触发管道
Section titled “使用 Zerops CLI (zcli) 触发管道”¥Trigger the pipeline using Zerops CLI (zcli)
-
Install the Zerops CLI.
终端窗口 # To download the zcli binary directly,# use https://github.com/zeropsio/zcli/releasesnpm i -g @zerops/zcli -
Open
Settings > Access Token Managementin the Zerops app and generate a new access token. -
Log in using your access token with the following command:
终端窗口 zcli login <token> -
Navigate to the root of your app (where
zerops.ymlis located) and run the following command to trigger the deploy:终端窗口 zcli push
¥Resources
¥Official
¥Community