From cae301c0116e8cf6a490e7236b17dc063aab5034 Mon Sep 17 00:00:00 2001 From: "U-JOHNLIU\\jonhl" Date: Wed, 12 Jan 2022 20:02:10 +0800 Subject: [PATCH] feat: add dashboard ci --- apps/dgiot_mqtt/README.md | 57 ++++++++++++++++++++++++++++++++-- dgiot_install.sh | 65 ++++++++++++++++++++++++++------------- 2 files changed, 99 insertions(+), 23 deletions(-) diff --git a/apps/dgiot_mqtt/README.md b/apps/dgiot_mqtt/README.md index a69589f5..990c6670 100644 --- a/apps/dgiot_mqtt/README.md +++ b/apps/dgiot_mqtt/README.md @@ -1,4 +1,57 @@ -## dgiot_mqtt +# Dlink协议 + Dlink协议是针对物联网开发领域设计的一种数据交换规范,数据格式是JSON,用于设备端和物联网平台的双向通信,更便捷地实现和规范了设备端和物联网平台之间的业务数据交互。 -dgiot_mqtt +## 协议框架 +![dlink proctol.png](http://dgiot-1253666439.cos.ap-shanghai-fsi.myqcloud.com/shuwa_tech/zh/backend/dgiot/dlink%20proctol.png) ++ 设备层和用户层隔离,物理层和逻辑层隔离 ++ 用户层mqtt权限与openApi权限保持一致性 ++ 设备侧topic交互采用 {productId}/{deviceAddr}的组合来唯一标识设备, deviceAddr为设备物理地址 ++ 用户侧topic交互采用{deviceId}来唯一标识设备,用{userId}来唯一标识用户,deviceId为设备虚拟地址 + +### 鉴权设计 ++ deviceId=md5("Device" + {productId} + {devAddr}).subString(10) ++ %u 表示用Username做ACL规则 ++ %c 表示用ClientId做ACL规则 ++ %d 表示用DeviceAddr做ACL规则, Token是dgiot用户登录权限系统的token,与API权限一致 ++ %t 表示用Token做ACL规则, Token是dgiot用户登录权限系统的token,与API权限一致 + +| 客户端 | Username | Password | ClientId | 登录鉴权| 订阅ACL | 发布ACL| +| -------- | -------- | ------- | -------- |-------- | ------- | -------- | +| Device |{productId}|{productSecret}|{deviceId}| 一型一密 | $dg/device/%u/# | $dg/thing/%u/# | +| Device |{productId}|{deviceSecret}|{deviceId}| 一机一密 | $dg/device/%u/%d/# | $dg/thing/%u/%d/# | +| Device |{productId}|{productSecret}|{deviceId}| 证书加密 | $dg/device/%u/# | $dg/thing/%u/# | +| User |{userId}|{Token}|{Token}| Token认证 | $dg/user/%t/# | $dg/thing/%t/# | + + + +## topic设计 +| 分类 | Topic | 发布者 | 订阅者 | +| -------- | -------- | ------- | -------- | +| 双向消息 |$dg/device/{productId}/{deviceAddr}/messages| 平台 | 设备 | +| 双向消息 |$dg/thing/{productId}/{deviceAddr}/messages| 设备 | 平台 | +| 双向消息 |$dg/thing/{deviceId}/messages|用户|平台| +| 双向消息 |$dg/user/{deviceId}/messages|平台|用户| +| 双向命令 |$dg/device/{productId}/{deviceAddr}/commands/request_id={request_id}| 平台 | 设备 | +| 双向命令 |$dg/thing/{productId}/{deviceAddr}/commands/request_id={request_id}| 设备 | 平台 | +| 双向命令 |$dg/thing/{deviceId}/commands/request_id={request_id}|用户|平台| +| 双向命令 |$dg/user/{deviceId}/commands/request_id={request_id}| 平台 | 用户 | +| 属性上报 |$dg/thing/{productId}/{deviceAddr}/properties/report|设备|平台| +| 属性上报 |$dg/user/{deviceId}/properties/report|平台|用户| +| 子属性上报 |$dg/thing/{productId}/{deviceAddr}/gateway/sub_devices/properties/report|设备|平台| +| 子属性上报 |$dg/user/{deviceId}/gateway/sub_devices/properties/report|平台|用户| +| 属性设置 |$dg/thing/{deviceId}/properties/set/request_id={request_id}|用户|平台| +| 属性设置 |$dg/device/{productId}/{deviceAddr}/properties/set/request_id={request_id}|平台|设备| +| 属性设置 |$dg/thing/{productId}/{deviceAddr}/properties/set/request_id={request_id}|设备|平台| +| 属性设置 |$dg/user/{deviceId}/properties/set/request_id={request_id}|平台|用户| +| 属性获取 |$dg/thing/{deviceId}/properties/get/request_id={request_id}|用户|平台| +| 属性获取 |$dg/device/{productId}/{deviceAddr}/properties/get/response/request_id={request_id}|平台|设备| +| 属性获取 |$dg/thing/{productId}/{deviceAddr}/properties/get/response/request_id={request_id}|设备|平台| +| 属性获取|$dg/{deviceId}/user/properties/get/request_id={request_id}|平台|用户| +| 属性获取 |$dg/thing/{productId}/{deviceAddr}/shadow/get/request_id={request_id}|设备|平台| +| 属性获取 |$dg/device/{productId}/{deviceAddr}/shadow/get/request_id={request_id}|平台|设备| +| 事件上报 |$dg/thing/{productId}/{deviceAddr}/events|设备|平台| +| 事件上报 |$dg/user/{deviceId}/events|平台|用户| + +## payload设计 +待设计 diff --git a/dgiot_install.sh b/dgiot_install.sh index e2892807..c3d8c138 100644 --- a/dgiot_install.sh +++ b/dgiot_install.sh @@ -105,10 +105,10 @@ else fi # ============================= get input parameters ================================================= -# dgiot_install.sh -v [single | cluster | devops] -d [prod.iotn2n.com | your_domain_name] -s [dgiot_44 | dgiot_n] -p [dgiot | dgiot_your_plugin] +# dgiot_install.sh -v [single | cluster | devops | ci] -d [prod.iotn2n.com | your_domain_name] -s [dgiot_44 | dgiot_n] -p [dgiot | dgiot_your_plugin] # set parameters by default value -verType=single # [single | cluster | devops] +verType=single # [single | cluster | devops | ci] domain_name="prod.iotn2n.com" #[prod.iotn2n.com | your_domain_name] software="dgiot_187" #[dgiot_187 | dgiot_n] plugin="dgiot" #[dgiot | dgiot_your_plugin] @@ -135,10 +135,9 @@ do p) echo "plugin=$OPTARG" plugin=$(echo $OPTARG) - verType="devops" ;; h) - echo "Usage: `basename $0` -v [single | cluster] -s [dgiot_187 | dgiot_n] -d [prod.iotn2n.com | your_domain_name] -p [dgiot | dgiot_your_plugin]" + echo "Usage: `basename $0` -v [single | cluster | devops | ci] -s [dgiot_187 | dgiot_n] -d [prod.iotn2n.com | your_domain_name] -p [dgiot | your_dgiot_plugin]" exit 0 ;; ?) #unknow option @@ -1090,16 +1089,20 @@ function build_dashboard() { rm ${script_dir}/dgiot_dashboard/dist/ -rf ${script_dir}/node-v16.5.0-linux-x64/bin/pnpm add -g pnpm ${script_dir}/node-v16.5.0-linux-x64/bin/pnpm install - ${script_dir}/node-v16.5.0-linux-x64/bin/pnpm run fix-memory-limit - cpucount=`cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l` - if [ 1 == ${cpucount} ];then + #${script_dir}/node-v16.5.0-linux-x64/bin/pnpm run fix-memory-limit + cpucount=`cat /proc/cpuinfo| grep 'cpu cores'| uniq |awk '{print $4}'` + if [ ${cpucount} -gt 1 ];then + ${script_dir}/node-v16.5.0-linux-x64/bin/pnpm build + sh ${script_dir}/dgiot_dashboard/config/lite/lite.sh + ${script_dir}/node-v16.5.0-linux-x64/bin/pnpm build + echo "not build" + else echo -e "`date +%F_%T` $LINENO: ${GREEN} cpucore = 1 not build dgiot_dashboard${NC}" git clone -b gh-pages https://github.com.cnpmjs.org/dgiot/dgiot-dashboard.git dist - else - ${script_dir}/node-v16.5.0-linux-x64/bin/pnpm build fi } -function devops() { + +function pre_build_dgiot() { ## 关闭dgiot clean_service dgiot count=`ps -ef |grep beam.smp |grep -v "grep" |wc -l` @@ -1111,17 +1114,18 @@ function devops() { cd ${script_dir}/ - #2. 更新最新的后端代码 - cd ${script_dir}/ - rm ${script_dir}/dgiot/ -rf - if [ ! -d ${script_dir}/dgiot/ ]; then - git clone https://gitee.com/dgiiot/dgiot.git + rm ${script_dir}/dgiot/apps/dgiot_api/priv/www -rf + mkdir -p ${script_dir}/dgiot/apps/dgiot_api/priv/www/ + if [ -d ${script_dir}/dgiot_dashboard/lite/ ]; then + cp ${script_dir}/dgiot_dashboard/lite/ ${script_dir}/dgiot/apps/dgiot_api/priv/www/ -rf fi - build_dashboard - if [ -d ${script_dir}/dgiot_dashboard/dist/ ]; then - rm ${script_dir}/dgiot/apps/dgiot_api/priv/www -rf - cp ${script_dir}/dgiot_dashboard/dist/ ${script_dir}/dgiot/apps/dgiot_api/priv/www/ -rf + if [ -d ${script_dir}/dgiot_dashboard/dev/ ]; then + cp ${script_dir}/dgiot_dashboard/dev/ ${script_dir}/dgiot/apps/dgiot_api/priv/www/ -rf + fi + + if [ -f ${script_dir}/dgiot_dashboard/config/index.html ]; then + cp ${script_dir}/dgiot_dashboard/config/index.html ${script_dir}/dgiot/apps/dgiot_api/priv/www/ -rf fi cd ${script_dir}/dgiot/ @@ -1134,6 +1138,7 @@ function devops() { rm ${script_dir}/dgiot/rebar.config -rf cd ${script_dir}/dgiot/apps/ + rm ${script_dir}/dgiot/apps/$plugin/ -rf if [ ! -d ${script_dir}/dgiot/apps/$plugin/ ]; then git clone root@git.iotn2n.com:dgiot/$plugin.git fi @@ -1153,8 +1158,9 @@ function devops() { rm ${script_dir}/dgiot/apps/dgiot_http/etc/dgiot_http.conf -rf cp ${script_dir}/dgiot/apps/$plugin/conf/dgiot_http.conf ${script_dir}/dgiot/apps/dgiot_http/etc/dgiot_http.conf -rf cd ${script_dir}/dgiot - make + } +function post_build_dgiot() { mv ${script_dir}/dgiot/_build/emqx/rel/emqx/ ${script_dir}/dgiot/_build/emqx/rel/dgiot cd ${script_dir}/dgiot/_build/emqx/rel @@ -1164,8 +1170,23 @@ function devops() { mkdir -p ${install_dir}/go_fastdfs/files/package/ fi cp ./${software}.tar.gz ${install_dir}/go_fastdfs/files/package/ + } + +function devops() { + build_dashboard + pre_build_dgiot + make + post_build_dgiot } +function ci() { + build_dashboard + pre_build_dgiot + make ci + post_build_dgiot +} + + function install_windows() { # initdb -D /data/dgiot/dgiot_pg_writer/data/ # pg_ctl -D /data/dgiot/dgiot_pg_writer/data/ -l logfile start @@ -1219,9 +1240,11 @@ else fi elif [ "${verType}" == "devops" ]; then devops + elif [ "${verType}" == "ci" ]; then + ci else echo "please input correct verType" fi fi -echo -e "`date +%F_%T` $LINENO: ${GREEN} dgiot ${verType} deploy end${NC}" +echo -e "`date +%F_%T` $LINENO: ${GREEN} dgiot ${verType} deploy success end${NC}"