Skip to main content

Cloud Hosting Container Plugin

Tencent CloudBase Framework Container Plugin

Tencent CloudBase Framework Container Plugin

Github License Npm version issue PRs Welcome star star

CloudBase Framework "Container" Plugin: Deploy project applications to CloudBase's cloud hosting environment with one click via the CloudBase Framework, delivering a high-performance container computing service featuring automatic elastic scaling for production-ready use. It integrates seamlessly with other plugins like the Website plugin and Node plugin to enable cloud-native integrated development.

Features

  • Cost Savings: Achieves significant resource cost reduction through resource scaling, elastic scaling, and flexible billing.
  • Minimal Configuration: Automatic framework detection, zero configuration required.
  • Extensive language and framework support
    • Node.JS
    • PHP
    • Java
    • Go
    • Dart
    • Deno

Usage

Step 1. Preparations

Specific steps please refer to Preparing the Cloud Development Environment and CloudBase CLI Command Tool

Step 2. Enter the project directory and initialize

If it is an existing backend application project

cloudbase

If you want to start a new project from scratch, you can directly execute init to begin a project from a template.

cloudbase init

Step 3. One-Click Deployment

cloudbase framework deploy

Configuration

By default, no configuration is required for use. The following configuration parameters are intended for scenarios with specific requirements.

Configuration Example

After running cloudbase init, the Cloud Development configuration file cloudbaserc.json` will be created. You can modify and write plugin configurations in the plugins section of the configuration file.

{
"envId": "{{envId}}",
"framework": {
"plugins": {
"client": {
"use": "@cloudbase/framework-plugin-container",
"inputs": {
"serviceName": "node-api",
"servicePath": "/node-api",
"localPath": "./"
}
}
}
}
}

Configuration Parameters Description

uploadType

Optional. The container image code source type supports three options: package|image|repository, representing local code package, image address, and git repository address respectively. Default is package. When selecting image, imageInfo must be filled; when selecting repository, codeDetail must be provided.

serviceName

Required. Service name in string format, such as node-api.

servicePath

Required. Service path configuration in string format, such as /node-api.

localPath

Optional. Path of the local code folder relative to the project root directory. Default: ./

localAbsolutePath

Optional. Absolute path of the local code folder.

version

Optional. Version name. Default: 1.0.0

isPublic

Optional. Whether to allow public access. Default: true

flowRatio

Optional. Traffic ratio (0-100). Default: 100

mode

Optional. Replica mode.

Supported in version 1.4.0 and later

Replica mode, in string format. Default: low-cost. Options: low-cost | high-availability

The low-cost` mode represents a low-cost configuration with cold start delays. It locks the minimum replica count to 0, defaults to 0.25C0.5G specifications, and prohibits modification of the minimum replica count. To modify, switch modes first.

The high-availability` mode represents a high-availability configuration without cold starts. It prohibits a minimum replica count of 0, defaults to 1C1G specifications, and requires switching modes first to set the minimum replica count to 0.

cpu

Optional. CPU size (0.25-128, unit: cores). Default: 0.25

mem

Optional. Mem size (0.5-128, unit: G). Default: 0.5

minNum

Optional. Minimum replicas (0-50). Default: 0

maxNum

Optional. Maximum replicas (1-50). Default: 10

policyType

Optional. Policy type (cpu). Default: cpu

policyThreshold

Optional. Policy threshold (1-100). Default: 60

containerPort

Optional. Service port. Default: 80

dockerfilePath

Optional. Dockerfile path. Default: ./Dockerfile

buildDir

Optional. Build directory. Default: ./

envVariables

Optional. Environment variable key-value pairs to be injected into the cloud-hosted runtime environment variables.

imageInfo

When uploadTypeis set toimage, imageInfo` must be provided in object format.

Attribute NameTypeLengthRequiredDescription
imageUrlString1-512YesImage pull address

The imageUrl follows the format [registry-url]/[namespace]/[image]:[tag], supporting both Tencent Cloud ccr.ccs.tencentyun.com image addresses and public dockerhub images such as nginx:latest.

Example:

{
"envId": "{{envId}}",
"framework": {
"name": "capp-example",
"plugins": {
"client": {
"use": "@cloudbase/framework-plugin-container",
"inputs": {
"serviceName": "node-api",
"servicePath": "/node-api",
"localPath": "./",
"uploadType": "image",
"imageInfo": {
"imageUrl": "ccr.ccs.tencentyun.com/tcb-100010952056-rjdt/webpage_node-api:node-api-001-1597238358"
}
}
}
}
}
}

codeDetail

When uploadTypeis set torepository, codeDetail` must be provided in object format.

Attribute NameTypeLengthRequiredDescription
nameCodeRepoName object1-512Norepo name
urlString1-512Norepo URL

Example:

{
"envId": "{{envId}}",
"framework": {
"name": "capp-example",
"plugins": {
"client": {
"use": "@cloudbase/framework-plugin-container",
"inputs": {
"serviceName": "deno",
"servicePath": "/deno",
"localPath": "./",
"uploadType": "repository",
"codeDetail": {
"name": "deno-docker",
"url": "https://github.com/TabSpace/deno-docker"
}
}
}
}
}
}

volumeMounts

Mount directory settings are supported since version 1.4.0

The type is in object format, where the key is the mount path and the value is the Name of the mounted CFS Addon.

Example:

{
"version": "2.0",
"envId": "{{env.ENV_ID}}",
"framework": {
"name": "grafana",
"plugins": {
"client": {
"use": "@cloudbase/framework-plugin-container",
"inputs": {
"mode": "low-cost",
"serviceName": "grafana",
"servicePath": "/",
"localPath": "./",
"uploadType": "package",
"containerPort": 3000,
"envVariables": {},
"volumeMounts": {
"/var/lib/grafana": "grafana-cfs"
}
}
}
},
"requirement": {
"addons": [
{
"type": "CFS",
"name": "grafana-cfs"
}
]
}
}
}

customLogs

Optional, user-defined log collection path, is supported since version 1.4.0.

String format, maximum length 1024

initialDelaySeconds

Optional. The delay time before starting health checks.

Unit: s, range: 0-1000.

bumpVersion

Optional. Whether to automatically create a new version.

Selecting the option to automatically create a new version allows for gradual traffic rollout and control in the console; if not selected, in-place updates will be performed automatically.

versionRemark

Optional, version remarks

More Plugins

Please visit the CloudBase Framework Plugin List to use other plugins in combination

Documentation Resources