Skip to main content

Configuration Instructions

This document provides an explanation of the framework-related fields in cloudbaserc.json.

Before using CloudBase Framework, you need to create a cloudbaserc.json configuration file. The cloudbaserc.json file serves as the configuration file for CloudBase CLI, CloudBase VSCode extension, and CloudBase applications, determining how CloudBase builds and deploys your application.

The framework` field contains configuration information for CloudBase Framework. For other configurations, please refer to https://docs.cloudbase.net/cli-v1/config.html.

Here is an example of a cloudbaserc configuration file:

{
"envId": "{{env.ENV_ID}}",
"$schema": "https://framework-1258016615.tcloudbaseapp.com/schema/latest.json",
"version": "2.0",
"framework": {}
}

The CloudBase Framework configuration file includes the following categories of configuration information:

CategoryDescription
Project InformationDescribe your application information
Plugin ConfigurationDescribes which CloudBase Framework plugins your application depends on to build and deploy your application based on the configuration.
LifecycleConfigures custom actions to be executed before and after the build and deploy lifecycle.
Application DependenciesConfigures extended resources and environment variables that the application depends on for one-click cloud deployment scenarios.
Template VariablesAllows the use of template variables in configurations to achieve dynamic configuration.

Project Information

Project information is used to describe your application information.

name

Type: `String

Requirements:

  • Length: 1-32 characters

  • Supports only A-Z a-z 0-9 - and _

The unique application identifier requires that duplicate names are not allowed under the same account.

Example:

{
"framework": {
"name": "cloudbase-helloworld"
}
}

Plugin Configuration

Describes which CloudBase Framework plugins your application depends on to build and deploy your application based on the configuration.

plugins

Type: Record<string,PluginConfig>

Describes which CloudBase Framework plugins your application depends on, so that your application can be built and deployed based on the configuration. Applications can use multiple plugins. For specific plugin configuration methods, refer to the following section.

Example:

{
"framework": {
"plugins": {}
}
}

plugins.<deploy_name>

Type: PluginConfig

Single plugin configuration

Consists of PluginConfig objects:

FieldDescriptionType
useThe npm package name of the plugin used, for example, @cloudbase/framework-plugin-website, supports specifying the plugin version, for example, @cloudbase/framework-plugin-website@1.3.5String
inputsConfiguration for plugin input parameters. Different plugins support different input parameters. Please refer to the README or documentation of the corresponding plugin.Object

For the list of currently supported plugins, please refer to https://github.com/Tencent/cloudbase-framework#currently-supported-plugins

Example:

{
"framework": {
"plugins": {
"client": {
"use": "@cloudbase/framework-plugin-website",
"inputs": {
"buildCommand": "npm run build",
"outputPath": "dist",
"cloudPath": "/vue"
}
},
"server": {
"use": "@cloudbase/framework-plugin-function",
"inputs": {
"functionRootPath": "cloudfunctions",
"functions": [{
"name": "vue-echo"
}]
}
}
}
}
}

Lifecycle

Configuring custom actions to be executed before and after the build and deploy lifecycle.

hooks

Type: HoosConfig

The hook configuration for CloudBase Framework before and after deployment allows customizing execution actions for different application lifecycles here.

Pre-hook, a hook executed before the full build and deployment actions of the Framework, can run command-line commands.

Configuration consists of the following objects:

FieldDescriptionType
prevDeployPre-hook configuration informationPreDeployHooksConfig
postDeployPost-hook configuration informationPostDeployHooksConfig

Example:

{
"framework": {
"hooks": {}
}
}

hooks.preDeploy

Type: PreDeployHooksConfig

Pre-hook, a hook executed before the full build and deployment actions of the Framework, can run command-line commands.

Configuration consists of the following PreDeployHooksConfig objects:

FieldDescriptionType
typeThe type of the pre-hook, currently only supports execCommand, which means executing command-line commandsString
commandsList of command commands to be executedArray

Example:

{
"framework": {
"hooks": {
"preDeploy": {
"type": "execCommand",
"commands": [
"sudo npm install -g lerna",
"lerna bootstrap"
]
}
}
}
}

hooks.postDeploy

Type: PostDeployHooksConfig

Post-hook, a hook invoked in the cloud after the deployment of the Framework, can call some cloud functions.

Configuration consists of the following PostDeployHooksConfig objects:

FieldDescriptionType
typeThe type of the pre-hook, currently only supports callFunction, which means executing cloud functions in the cloudString
functionsList of cloud functions to be invoked, supports array, for exampleArray<FunctionConfig>

The FunctionConfig` object format is as follows:

FieldDescriptionType
functionNameName of the cloud function to be invokedString
paramsParameter information for invoking cloud functionsRecord<string,string>

Example:

{
"framework": {
"hooks": {
"postDeploy": {
"type": "callFunction",
"functions":[
{
"functionName": "echo",
"params": {
"foo": "bar"
}
}
]
}
}
}
}

Application Dependencies

In one-click cloud deployment scenarios, you need to configure application dependencies to declare extended resources and environment variables that the application depends on.

requirement

Type: RequirementConfig

Describes business parameters such as dependent resource information and environment variables when the project is installed and deployed with one click via the console.

The RequirementConfig` object format is as follows:

FieldDescriptionType
addonsExternal cloud resources used during application deployment, including cfs, cynosdb, redis, etc.AddonsConfig
environmentDeclares environment variables for the application at build time and runtime, injected by default into the computing environment (Cloud Functions, Cloud Applications), also used as environment variables during cloud build and deployment, and can be referenced in cloudbaserc.json via {{env.ENV_NAME}}EnvironmentConfig

requirement.addons

Type: AddonsConfig

External cloud resources used during application deployment, including cfs, cynosdb, redis, etc.

The AddonsConfig` object format is as follows:

FieldDescriptionType
typeResource type, currently supports CFS and CynosDB`'CFS''CynosDB'`
nameResource name, supports only a-z, 0-9, and -String
envMapMaps the IP and PORT generated by cloud resources to corresponding environment variable names using the defined keys and injects them into the environment.Record<string, string>

Currently supported resources:

TypeDescriptionExported Environment Variables
CFSShared file storage service. CFS can be used in conjunction with cloud-hosted container services to provide elastic, high-performance shared storage for multiple compute nodes.None
CynosDBTencent Cloud database CynosDB (TencentDB for CynosDB) is a self-developed new generation of high-performance, highly available enterprise-grade distributed cloud database. Currently supports the database engine MySQL 5.7IP, PORT, USERNAME, PASSWORD

Example:


"framework": {
"requirement": {
"addons": [
{
"type": "CynosDB",
"name": "wordpress",
"envMap": {
"IP": "WORDPRESS-IP",
"PORT": "WORDPRESS-PORT",
"USERNAME": "WORDPRESS-USERNAME",
"PASSWORD": "WORDPRESS-PASSWORD"
}
}
]
}
}
}

requirement.environment

Type: Record<string,EnvironmentConfig>

Declares environment variables for the application at build time and runtime, injected by default into the computing environment (Cloud Functions, Cloud Applications), also used as environment variables during cloud build and deployment, and can be referenced in cloudbaserc.json via {{env.ENV_NAME}}

Configuration consists of the environment variable key and an object of related environment variable options, with the environment variable options in the format EnvironmentConfig

The EnvironmentConfig` object format is as follows:

FieldDescriptionType
descriptionEnvironment variable description, which will prompt during inputString
requiredRequiredBoolean
defaultDefault valueString
validationValidation rule configurationValidationConfig

The ValidationConfig` object format is as follows:

FieldDescriptionType
ruleValidation rule informationRuleConfig
errorMessageError message when validation failsString

`| Field | Description | Type |

FieldDescriptionType
typeValidation rule type, currently supports "RegExp" for regular expressionString
patternPattern for regular expressionString
flagFlag for regular expressionString

Example:

{
"framework": {
"requirement": {
"environment": {
"SECRET_TOKEN": {
"description": "A secret key for verifying the integrity of signed cookies.",
"required": true,
"default": "default_value",
"validation": {
"rule": {
"type": "RegExp",
"pattern": "[3-9]",
"flag": "g"
},
"errorMessage": "Value must be 3-9"
}
}
}
}
}
}

Template Variables

The configuration file supports the dynamic variables feature. Enable it by declaring "version": "2.0" in cloudbaserc.json.

The dynamic variables feature allows the use of dynamic variables in the cloudbaserc.json configuration file to retrieve dynamic data from environment variables. Values enclosed in {{}} are defined as dynamic variables, which can reference values from data sources. For example, {{env.ENV_ID}}:

Step 1: Create cloudbaserc.json and .env files in the project root directory.

`plain text . ├─cloudbaserc.json ├─.env


Step 2: Add variables in the **.env** file.

`plain text
ENV_ID=pro-123
DB_NAME=pro_user

Step 3: Inject template variables via env in the cloudbaserc.json file.

{
"version": "2.0",
"envId": "{{env.ENV_ID}}",
"framework": {
"name": "node-capp",
"plugins": {
"node": {
"use": "@cloudbase/framework-plugin-node",
"inputs": {
"name": "node-capp",
"path": "/node-capp",
"platform": "container",
"containerOptions": {
"envVariables": {
"env": "{{env.ENV_ID}}",
"db": "{{env.DB_NAME}}"
}
}
}
}
}
}
}

Step 4: One-click application deployment

cloudbase framework deploy

Mode Switching

Assuming you have completed the configuration of the above template variables

Step 1: Additionally create the .env.dev file in the project root directory.

`plain text . ├─cloudbaserc.json ├─.env ├─.env.dev


Step 2: Add variables in the **.env.dev** file.

`plain text
ENV_ID=dev-123
DB_NAME=dev_user

Step 3: Specify the mode using --mode when deploying applications.

cloudbase framework deploy --mode dev

Complete Sample

{
"version": "2.0",
"envId": "{{env.ENV_ID}}",
"$schema": "https://framework-1258016615.tcloudbaseapp.com/schema/latest.json",
"framework": {
"plugins": {
"admin": {
"use": "@cloudbase/framework-plugin-website",
"inputs": {
"outputPath": "./packages/admin/dist",
"installCommand": "echo \"Skip Install\"",
"buildCommand": "npm run build",
"cloudPath": "{{env.deployPath}}"
}
},
"init": {
"use": "@cloudbase/framework-plugin-function",
"inputs": {
"functionRootPath": "./packages",
"functions": [
{
"name": "cms-init",
"timeout": 60,
"envVariables": {
"CMS_ADMIN_USER_NAME": "{{env.administratorName}}",
"CMS_ADMIN_PASS_WORD": "{{env.administratorPassword}}",
"CMS_OPERATOR_USER_NAME": "{{env.operatorName}}",
"CMS_OPERATOR_PASS_WORD": "{{env.operatorPassword}}",
"CMS_DEPLOY_PATH": "{{env.deployPath}}",
"ACCESS_DOMAIN": "{{env.accessDomain}}"
},
"installDependency": true,
"handler": "index.main"
}
]
}
},
"service": {
"use": "@cloudbase/framework-plugin-node",
"inputs": {
"name": "tcb-ext-cms-service",
"entry": "app.js",
"projectPath": "./packages/service",
"path": "/tcb-ext-cms-service",
"functionOptions": {
"timeout": 15,
"envVariables": {
"NODE_ENV": "production"
}
}
}
},
"db": {
"use": "@cloudbase/framework-plugin-database",
"inputs": {
"collections": [
{
"collectionName": "tcb-ext-cms-projects",
"description": "CMS system project data (Please do not modify manually)",
"aclTag": "ADMINONLY"
},
{
"collectionName": "tcb-ext-cms-schemas",
"description": "CMS system content model data (Please do not modify manually)",
"aclTag": "ADMINONLY"
},
{
"collectionName": "tcb-ext-cms-users",
"description": "CMS system user data, storing CMS user information including administrator account details, role information, etc. (Please do not modify manually)",
"aclTag": "ADMINONLY"
},
{
"collectionName": "tcb-ext-cms-webhooks",
"description": "CMS system webhook collection, storing the callback interface configuration for the CMS system. Changes to CMS system data can be synchronized via callbacks (Please do not modify manually)",
"aclTag": "ADMINONLY"
},
{
"collectionName": "tcb-ext-cms-settings",
"description": "CMS system configuration collection, storing the settings of the CMS system (Please do not modify manually)",
"aclTag": "ADMINONLY"
},
{
"collectionName": "tcb-ext-cms-user-roles",
"description": "CMS system user role configuration collection, storing custom user role information for the CMS system (Please do not modify manually)",
"aclTag": "ADMINONLY"
}
]
}
}
},
"requirement": {
"addons": [],
"environment": {
"administratorName": {
"description": "Administrator account name, which must be longer than 4 characters and can only contain letters and numbers",
"required": true,
"default": "admin",
"validation": {
"rule": {
"type": "RegExp",
"pattern": "[^[a-zA-Z0-9]+[a-zA-Z0-9_-]?[a-zA-Z0-9]+$]",
"flag": "g"
},
"errorMessage": "Combination of letters and numbers, cannot be all numbers, length must be 1-32"
}
}
}
}
}
}