logo
0
0
WeChat Login
feat: 支持插件变量方式部署并重构CI配置

部署 EdgeOne Pages 插件

使用 edgeone 命令行工具部署 EdgeOne Pages 静态网站。

前置条件

  • 已获取 EdgeOne Pages API Token

使用方式

本插件支持两种使用方式:插件变量方式Script 方式


方式一:插件变量方式(settings)

通过 settings 传入参数,插件自动执行部署命令,无需手动编写 script。

参数说明

参数必填说明默认值
project_nameEdgeOne Pages 项目名称-
api_tokenEdgeOne Pages API Token-
directory部署目录路径.
environment部署环境,preview 为预发环境,不填为生产生产环境

预发环境示例

tag_deploy.staging:
  - imports: https://cnb.cool/***/-/blob/main/envs.yml
    stages:
      - name: build
        image: node:20-alpine
        script: npm install && npm run build
      - name: 部署预发环境
        image: tencentcom/deploy-eopages:latest
        settings:
          project_name: landing-page-demo
          api_token: $EDGEONE_PAGES_API_TOKEN
          directory: ./dist
          environment: preview

生产环境示例

tag_deploy.production:
  - imports: https://cnb.cool/***/-/blob/main/envs.yml
    stages:
      - name: build
        image: node:20-alpine
        script: npm install && npm run build
      - name: 部署生产环境
        image: tencentcom/deploy-eopages:latest
        settings:
          project_name: landing-page-demo
          api_token: $EDGEONE_PAGES_API_TOKEN
          directory: ./dist

方式二:Script 方式

直接使用 script 编写自定义的 edgeone 命令,适合需要灵活控制部署流程的场景。

Script 预发环境示例

tag_deploy.staging:
  - imports: https://cnb.cool/***/-/blob/main/envs.yml
    stages:
      - name: build
        image: node:20-alpine
        script: npm install && npm run build
      - name: 部署我的 eo pages 预发环境
        image: tencentcom/deploy-eopages:latest
        script: |
          edgeone pages deploy ./dist -n landing-page-demo -e preview -t $EDGEONE_PAGES_API_TOKEN

Script 生产环境示例

tag_deploy.production:
  - imports: https://cnb.cool/***/-/blob/main/envs.yml
    stages:
      - name: build
        image: node:20-alpine
        script: npm install && npm run build
      - name: 部署我的 eo pages 正式环境
        image: tencentcom/deploy-eopages:latest
        script: |
          edgeone pages deploy ./dist -n landing-page-demo -t $EDGEONE_PAGES_API_TOKEN

环境部署配置

edgeone pages 提供了预发以及生产两个环境,刚好契合 cnb 的自定义部署功能,可以在 .cnb/tag_deploy 中配置环境。

environments:
  - name: staging
    description: staging环境发布
  - name: production
    description: 生产环境发布
    require:
      - environmentName: staging
        after: 60

密钥管理

API Token 为敏感信息,推荐使用密钥仓库来存储,然后在流水线中引用:

# envs.yml
EDGEONE_PAGES_API_TOKEN: mRH1***wu0C

参考文档