Skip to content

将你的 Astro 站点部署到 Clever Cloud

Clever Cloud 是一个欧洲云平台,提供自动化、可扩展的服务。

¥Clever Cloud is a European cloud platform that provides automated, scalable services.

¥Project Configuration

你可以在 Clever Cloud 上部署完全静态和按需渲染的 Astro 项目。无论你的 output 模式 (预渲染或按需) 是什么,你都可以选择部署为使用构建后钩子运行的静态应用,或者部署为与你的 package.json 开箱即用的 Node.js 应用。

¥You can deploy both fully static and on-demand rendered Astro projects on Clever Cloud. Regardless of your output mode (pre-rendered or on-demand), you can choose to deploy as a static application which runs using a post-build hook, or as a Node.js application, which works out-of-the-box with your package.json.

¥Port and host

Clever Cloud 上的应用在端口 8080 上监听。如果你的项目需要此配置,请在 Astro 中的以下两个位置之一设置你的端口和主机:

¥Applications on Clever Cloud listen on port 8080. If your project requires this configuration, set your port and host in Astro in one of two locations:

  1. package.json 脚本中:

    package.json
    "scripts": {
    "dev": "astro dev",
    "start": "astro dev",
    "build": "astro check && astro build",
    "preview": "astro preview --host 0.0.0.0 --port 8080",
    "astro": "astro"
    }
  2. astro.config.mjs 中:

    astro.config.mjs
    import { defineConfig } from 'astro/config';
    export default defineConfig({
    server: {
    port: 8080,
    host: true
    }
    });

¥Deploy Astro from the Console

要将你的 Astro 项目部署到 Clever Cloud,你需要创建一个新的应用。应用向导将引导你完成必要的配置步骤。

¥To deploy your Astro project to Clever Cloud, you will need to create a new application. The application wizard will walk you through the necessary configuration steps.

  1. From the lateral menubar, click Create > An application

  2. Choose how to deploy:

    • Create a brand new app: to deploy from a local repository with Git

    or

    • Select a GitHub repository: to deploy from GitHub
  3. Select a Node.js application, or a static one.

  4. Set up the minimal size for your instance and scalability options. Astro sites can typically be deployed using the Nano instance. Depending on your project’s specifications and dependencies, you may need to adjust accordingly as you watch the metrics from the Overview page.

  5. Select a region to deploy your instance.

  6. Skip connecting Add-ons to your Clever application unless you’re using a database or Keycloak.

  7. Inject environment variables:

    • For Node.js, no specific environment variable is needed to deploy Astro if you’re using npm. If you’re using yarn or pnpm, set the following environment variables:
    Terminal window
    CC_NODE_BUILD_TOOL="custom"
    CC_PRE_BUILD_HOOK="npm install -g pnpm && pnpm install"
    CC_CUSTOM_BUILD_TOOL="pnpm run astro telemetry disable && pnpm build"
    CC_RUN_COMMAND="pnpm run preview"
    • For a static application, add these variables:
    Terminal window
    CC_POST_BUILD_HOOK="npm run build"
    CC_PRE_BUILD_HOOK="npm install && npm run astro telemetry disable"
    CC_WEBROOT="/dist"
  8. Deploy! If you’re deploying from GitHub, your deployment should start automatically. If you’re using Git, copy the remote and push on the master branch.

¥Official Resources

More Deployment Guides

Astro 中文网 - 粤ICP备13048890号