当前位置:网站首页>Best practices cloud development cloudbase multi environment management practices

Best practices cloud development cloudbase multi environment management practices

2022-06-24 01:30:00 Tencent cloud development TCB

background

Development of cloud CloudBase Provide environment replication capability , It is convenient for developers to develop projects in multiple environments .

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

Function resource

1、 Cloud function code from A Environment corresponding function copy , Pay attention to the dead environment in the code ID A It needs to be manually modified to B.

If... Is used in the function Node SDK And Use the current environment , Suggest writing :

const cloudbase = require("@cloudbase/node-sdk")
const app = cloudbase.init({
  env: cloudbase.SYMBOL_CURRENT_ENV //  Automatically select the current environment 
})

2、 The function attribute configuration is as follows Memory , Timeout time , environment variable , Timing trigger ,VPC, Public network access configuration , Function corresponds to cloud access configuration & authentication ,CLS All log configurations are copied , No developer action .

3、 The function layer does not copy , It needs to be manually on B Create a new layer in .

Database resources

  1. During database replication, only empty collections with the same name are created in the new environment , The table data needs to be manually imported by the user in the console (A Environment library export , Import to B Environment library ).
  2. Database security rules , Index settings are copied , Developers don't need to operate .

Cloud storage resources

  1. Cloud storage configuration, such as permission configuration , All cache configurations are copied , No user action required
  2. Specific file resources , The user needs to manually guide (A Environment export file resources , Import to B Environmental Science )

Recommended Practice :

  • install cloudbase cli Tool and log in
npm i -g @cloudbase/cli  
tcb login
  • download A Environment all files to local
#  Download all the files 
tcb storage download / localPath --dir -e A
  • Upload local files to B Environmental Science
tcb storage upload localPath -e B

Multi environment project development practice

1. development environment , Production environment differentiation

Environment based replication capabilities , Can quickly build and develop dev And production prod Two sets of environments ( There is no need to create tables repeatedly , Repeat the operation of building a function ).

Reference documents :

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

Operation practice

1、 The cloud function side uses SDK Use the dynamic environment to write ( Similar to function resource replication ), Avoid writing dead environments ID.

  • Applet 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 //  Automatically select the current environment 
})

2、 The client is in the development and production environment , Specify the corresponding environment respectively ID that will do

wx.cloud.init({
//  Please fill in the environment here  ID,  Environmental Science  ID  You can open the cloud console to view 
env: config.ENV // dev or prod
})

Further more , In order to avoid the risk of manual operation , The environment can be configured in an engineering way ID, Such as Configure in development mode dev Environmental Science ID, In production mode, it is configured as prod Environmental Science ID, The specific implementation is not expanded here .

2. Project collaborative development

Under the same environment , The problem of dirty data is easy to occur in multi person collaborative development , Each developer can copy their own development environment based on the initial environment of the project , Debugging and development in each environment do not affect each other .

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

原网站

版权声明
本文为[Tencent cloud development TCB]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/11/20211117203913371G.html

随机推荐