头图

background

Cloud Development CloudBase provides environment replication capabilities, which is convenient for developers to develop projects in multiple environments.

Environmental resource replication practice (Environment A -> Environment B)

Function resource

  1. The cloud function code is copied from the corresponding function of the A environment. Note that the hard-coded environment ID A in the code needs to be manually modified to B.

If the Node SDK is used in the function and the current environment is used, it is recommended to write:

const cloudbase = require("@cloudbase/node-sdk")
const app = cloudbase.init({
  env: cloudbase.SYMBOL_CURRENT_ENV // 自动选取当前环境
})
  1. Function attribute configuration such as memory, timeout time, environment variables, timing trigger, VPC, public network access configuration, function corresponding to cloud access configuration & authentication, CLS log configuration is copied, no developer operation is required.
  2. The function layer will not be copied, you need to create a new layer in B manually.

Database resources

  1. When the database is copied, only an empty collection with the same name is created in the new environment, and the table data needs to be manually imported by the user in the console (A environment library is exported, and the B environment library is imported).
  2. Database security rules and index settings are all copied, and developers do not need to operate.

Cloud storage resources

  1. Cloud storage configuration such as permission configuration and cache configuration are copied without user operation
  2. Specific file resources need to be manually imported by the user (A environment exports file resources and imports them to B environment)

Recommended Practice:

  • Install cloudbase cli tool and log in
npm i -g @cloudbase/cli

tcb login
  • Download all files of A environment to local
# 下载全部文件
tcb storage download / localPath --dir -e A
  • Upload local files to B environment
tcb storage upload localPath -e B

Multi-environment project development practice

1. Development environment, production environment distinction

Based on the environment replication capabilities, two environments for development dev and production prod can be quickly set up (eliminating the need to repeatedly build tables and functions).

Reference documents:

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/concepts/environment.html

Operation Practice

  1. When using the SDK on the cloud function side, use the dynamic environment writing method (similar to function resource copying) to avoid writing dead environment IDs.
  • Small program side example
const cloud = require('wx-server-sdk')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})
  • Tencent cloud side example
const cloudbase = require("@cloudbase/node-sdk")
const app = cloudbase.init({
env: cloudbase.SYMBOL_CURRENT_ENV // 自动选取当前环境
})
  1. In the development and production environment of the client, specify the corresponding environment ID respectively.
wx.cloud.init({
// 此处请填入环境 ID, 环境 ID 可打开云控制台查看
env: config.ENV // dev or prod
})
Furthermore, in order to avoid the risk of human operation, the environment ID can be configured in an engineering way, such as the dev environment ID in the development mode, and the prod environment ID in the production mode. The specific implementation will not be expanded here.

2. Project collaborative development

In the same environment, the problem of dirty data is prone to occur during multi-person collaborative development. Each developer can copy their own development environment based on the initial environment of the project, and debugging and development in each environment will not affect each other.

Open cloud development: https://console.cloud.tencent.com/tcb?tdl_anchor=techsite


CloudBase云开发
425 声望438 粉丝

云开发(Tencent CloudBase,TCB)是云端一体化的后端云服务 ,采用 serverless 架构,免去了移动应用构建中繁琐的服务器搭建和运维。同时云开发提供的静态托管、命令行工具(CLI)、Flutter SDK 等能力极大的降...


引用和评论

0 条评论