Quick Start
This quick start guides you through deploying a Vue Website using CloudBase CLI.
0. Activate Cloud Development services
If you already have a pay-as-you-go Cloud Development environment, you can skip this step.
Before using Cloud Development services, you need to log in to the Tencent Cloud CloudBase console to ensure that the Cloud Development service is activated and an available environment has been created. If you are unfamiliar with creating an environment, refer to the CloudBase Quick Start - Activating an Environment document for guidance.
1. Log in
First, log in to your Tencent Cloud account. After obtaining your authorization, CloudBase CLI can access your resources. CloudBase CLI provides two methods to obtain authorization: Tencent Cloud - CloudBase Console Authorization and Tencent Cloud - Cloud API Key Authorization.
Tencent Cloud - CloudBase Console Authorization
Enter the following command in your terminal
tcb login
CloudBase CLI will automatically open the CloudBase Console to obtain authorization. You need to click the 'Agree to Authorize' button to allow CloudBase CLI to obtain authorization. If you are not logged in, you need to log in before you can perform this operation.
If your account is not a master account, please refer to Sub-account Login in the login instructions.
Tencent Cloud - Cloud API Key Authorization
Tencent Cloud API keys can access all resources under your account. Please store them securely and replace them regularly. After replacing a key, promptly delete the old key.
First, you need to go to the Tencent Cloud official website to obtain Cloud API keys, then enter the following command in your terminal:
tcb login --key
After pressing Enter, enter the SecretId and SecretKey of your Cloud API keys as prompted to complete the login.
Login in CI
In CI (Continuous Integration) builds, you can use the following method to log in directly via API keys, avoiding interactive input:
tcb login --apiKeyId xxx --apiKey xxx
2. Create Project
Initialization
You can use the following command to create a project. When creating the project, CloudBase CLI will create a folder based on the project name you entered and write relevant configuration and template files.
Using the tcb new
command requires CLI version 1.0+.
tcb new app node-starter
A Cloud Development project is an entity associated with cloud development environment resources. It aggregates services such as cloud functions, databases, and file storage. You can write functions, store files in the project, and quickly operate your cloud functions, file storage, databases, and other resources through CloudBase.
Cloud Development Project File Structure
.
├── .gitignore
├── functions // Cloud functions directory
│ └── node-app
│ └── index.js
└── cloudbaserc.json // Project configuration file
Write Functions
By default, all Node and PHP functions are stored in the functions
directory using the function name as the folder name, such as functions/node-app/index.js
. For Java functions, you need to rename the JAR file to match the function name and place it in the functions
directory, for example, functions/cloudbase.jar
.
If you wish to store functions in a different directory, you can specify your desired directory using the functionRoot
option in the configuration file. The functionRoot
option represents the path of the cloud functions folder relative to the project root directory.
For example, to create a Node.js function app, here is the content of functions/app/index.js
:
"use strict";
exports.main = async (event, context) => {
console.log("Hello World");
console.log(event);
console.log(context);
};
Modify Configuration
By default, project configuration is stored in the cloudbaserc.json
file. The default generated function configuration is for Node-related settings. For other languages such as PHP and Java, you need to modify the corresponding handler (entry point) and runtime. Refer to the configuration file section in the cloudbaserc.json documentation.
If you wish to specify another file as the configuration file, you can add the --config-file config-path
parameter when using CLI commands. Currently, configuration files in JS and JSON formats are supported.
{
"envId": "xxx",
"functionRoot": "./functions",
"functions": [
{
"name": "node-app",
"timeout": 5,
"envVariables": {},
"runtime": "Nodejs10.15",
"memorySize": 128,
"handler": "index.main"
}
]
}
3. Deploy Functions
Run the command tcb fn deploy node-app
in the project root directory (where cloudbaserc.json is located) to deploy the node-app
function.
tcb fn deploy node-app
After deployment is complete, you can use the tcb fn list
command to view the list of deployed functions.
tcb fn list