Browse Source

Merge pull request #134 from emqx/build_tags

Add build tags
jinfahua 5 years atrás
parent
commit
184029311b

+ 64 - 5
.github/workflows/fvt_tests.yaml

@@ -9,7 +9,7 @@ on:
             - prereleased
 
 jobs:
-    fvt_tests:
+    fvt_tests_with_edgex:
         runs-on: ubuntu-latest
 
         steps:
@@ -42,22 +42,22 @@ jobs:
         - name: build kuiper
           run: |
             sudo apt update && sudo apt install pkg-config libczmq-dev -y
-            make
+            make build_with_edgex
         - name: run edgex && emqx && kuiper
           run: |
             sudo ./fvt_scripts/setup_env.sh
             ln -s _build/kuiper-$(git describe --tags --always)-$(uname -s | tr "[A-Z]" "[a-z]")-x86_64/log kuiper_logs
         - name: run fvt tests
           timeout-minutes: 5
-          run: ./fvt_scripts/run_jmeter.sh
+          run: ./fvt_scripts/run_jmeter.sh with_edgex=true
         - uses: actions/upload-artifact@v1
           if: always()
           with:
-            name: kuiper_logs
+            name: kuiper_logs_with_edgex
             path: ./kuiper_logs
         - uses: actions/upload-artifact@v1
           with:
-            name: jmeter_logs
+            name: jmeter_logs_with_edgex
             path: ./jmeter_logs
         - name: checkout out
           run: |
@@ -69,3 +69,62 @@ jobs:
                 exit 1
             fi
             
+    fvt_tests_without_edgex:
+        runs-on: ubuntu-latest
+
+        steps:
+        - uses: actions/setup-go@v1
+          with:
+            go-version: '1.11.5'
+        - uses: actions/setup-java@v1
+          with:
+            java-version: '8' # The JDK version to make available on the path.
+            java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk
+            architecture: x64 # (x64 or x86) - defaults to x64
+        - name: set up jmeter
+          timeout-minutes: 10
+          env:
+            JMETER_VERSION: 5.2.1
+          run: |
+            wget -O /tmp/apache-jmeter.tgz http://us.mirrors.quenda.co/apache//jmeter/binaries/apache-jmeter-$JMETER_VERSION.tgz
+            cd /tmp && tar -xvf apache-jmeter.tgz
+            echo "jmeter.save.saveservice.output_format=xml" >> /tmp/apache-jmeter-$JMETER_VERSION/user.properties
+            echo "jmeter.save.saveservice.response_data.on_error=true" >> /tmp/apache-jmeter-$JMETER_VERSION/user.properties
+            wget -O /tmp/apache-jmeter-$JMETER_VERSION/lib/ext/mqtt-xmeter-1.13-jar-with-dependencies.jar https://github.com/emqx/mqtt-jmeter/raw/master/Download/v1.13.0/mqtt-xmeter-1.13-jar-with-dependencies.jar
+            ln -s /tmp/apache-jmeter-$JMETER_VERSION /opt/jmeter
+        - name: install emqx
+          env:
+            EMQX_VERSION: v4.0.2
+          run: |
+            wget -O emqx.deb https://www.emqx.io/downloads/broker/v4.0.2/emqx-ubuntu18.04-${EMQX_VERSION}_amd64.deb
+            sudo dpkg -i emqx.deb
+        - uses: actions/checkout@v2
+        - name: build kuiper
+          run: |
+            sudo apt update && sudo apt install pkg-config libczmq-dev -y
+            make
+        - name: run edgex && emqx && kuiper
+          run: |
+            sudo ./fvt_scripts/setup_env.sh
+            ln -s _build/kuiper-$(git describe --tags --always)-$(uname -s | tr "[A-Z]" "[a-z]")-x86_64/log kuiper_logs
+        - name: run fvt tests
+          timeout-minutes: 5
+          run: ./fvt_scripts/run_jmeter.sh with_edgex=false
+        - uses: actions/upload-artifact@v1
+          if: always()
+          with:
+            name: kuiper_logs_without_edgex
+            path: ./kuiper_logs
+        - uses: actions/upload-artifact@v1
+          with:
+            name: jmeter_logs_without_edgex
+            path: ./jmeter_logs
+        - name: checkout out
+          run: |
+            sudo apt update && sudo apt install -y libxml2-utils
+            cd jmeter_logs
+            if [ "$(xmllint --format --xpath '/testResults/sample/@rc' $(ls *.jtl) | sed -r 's/ /\n/g;' | sort -u | grep -E 'rc=\"[45][0-9][0-9]\"|rc=\"\"')" != "" ]; then
+                echo -e "---------------------------------------------\n"
+                echo "FVT tests error"
+                exit 1
+            fi

+ 32 - 3
Makefile

@@ -22,7 +22,13 @@ endif
 TARGET ?= emqx/kuiper
 
 .PHONY: build
-build:
+build: build_without_edgex
+
+.PHONY:pkg
+pkg: pkg_without_edgex
+
+.PHONY: build_prepare
+build_prepare:
 	@mkdir -p $(BUILD_PATH)/$(PACKAGE_NAME)/bin
 	@mkdir -p $(BUILD_PATH)/$(PACKAGE_NAME)/etc
 	@mkdir -p $(BUILD_PATH)/$(PACKAGE_NAME)/etc/sources
@@ -36,6 +42,8 @@ build:
 
 	@cp -r etc/* $(BUILD_PATH)/$(PACKAGE_NAME)/etc
 
+.PHONY: build_without_edgex
+build_without_edgex: build_prepare
 	@if [ ! -z $(GOOS) ] && [ ! -z $(GOARCH) ] && [ $(CGO_ENABLED) == 0 ];then \
 		GO111MODULE=on GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=$(VERSION)" -o cli xstream/cli/main.go; \
 		GO111MODULE=on GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=$(VERSION)" -o server xstream/server/main.go; \
@@ -47,8 +55,29 @@ build:
 	@mv ./cli ./server $(BUILD_PATH)/$(PACKAGE_NAME)/bin
 	@echo "Build successfully"
 
-.PHONY: pkg
-pkg: build
+.PHONY: pkg_without_edgex
+pkg_without_edgex: build_without_edgex
+	@make real_pkg
+
+.PHONY: build_with_edgex
+build_with_edgex: build_prepare
+	@if [ ! -z $(GOOS) ] && [ ! -z $(GOARCH) ] && [ $(CGO_ENABLED) == 0 ];then \
+		GO111MODULE=on GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=$(VERSION)" -tags edgex -o cli xstream/cli/main.go; \
+		GO111MODULE=on GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=$(VERSION)" -tags edgex -o server xstream/server/main.go; \
+	else \
+		GO111MODULE=on CGO_ENABLED=1 go build -ldflags="-s -w -X main.Version=$(VERSION)" -tags edgex -o cli xstream/cli/main.go; \
+		GO111MODULE=on CGO_ENABLED=1 go build -ldflags="-s -w -X main.Version=$(VERSION)" -tags edgex -o server xstream/server/main.go; \
+	fi
+	@if [ ! -z $$(which upx) ]; then upx ./cli; upx ./server; fi
+	@mv ./cli ./server $(BUILD_PATH)/$(PACKAGE_NAME)/bin
+	@echo "Build successfully"
+
+.PHONY: pkg_whit_edgex
+pkg_whit_edgex: build_with_edgex 
+	@make real_pkg
+
+.PHONY: real_pkg
+real_pkg:
 	@mkdir -p $(PACKAGES_PATH)
 	@cd $(BUILD_PATH) && zip -rq $(PACKAGE_NAME).zip $(PACKAGE_NAME)
 	@cd $(BUILD_PATH) && tar -czf $(PACKAGE_NAME).tar.gz $(PACKAGE_NAME)

+ 13 - 3
README-CN.md

@@ -147,11 +147,21 @@ Kuiper 可以运行在各类物联网的边缘使用场景中,比如工业物
 
 #### 编译
 
-+ 编译二进制:``$ make``
++ 编译二进制:
 
-+ 安装文件打包:`` $ make pkg``
+  - 编译二进制文件: `$ make`
 
-+ Docker 镜像:``$ make docker``
+  - 编译支持 EdgeX 的二进制文件: `$ make build_with_edgex`
+
++ 安装文件打包:
+
+  - 安装文件打包:: `$ make pkg`
+
+  - 支持 EdgeX 的安装文件打包: `$ make pkg_with_edgex`
+
++ Docker 镜像:`$ make docker`
+
+  > Docker 镜像默认支持 EdgeX
 
 
 如果您要实现交叉编译,请参考[此文档](docs/zh_CN/cross-compile.md)。

+ 15 - 3
README.md

@@ -147,9 +147,21 @@ It can be run at various IoT edge use scenarios, such as real-time processing of
 
 #### Compile
 
-- Binary: ``$ make``
-- Packages: `` $ make pkg``
-- Docker images: ``$ make docker``
++ Binary: 
+
+  - Binary: `$ make`
+
+  - Binary files that support EdgeX: `$ make build_with_edgex`
+
++ Packages: `` $ make pkg``
+
+  - Packages: `$ make pkg`
+
+  - Packages files that support EdgeX: `$ make pkg_with_edgex`
+
++ Docker images: `$ make docker`
+
+  > Docker images support EdgeX by default
 
 To using cross-compilation, refer to [this doc](docs/en_US/cross-compile.md).
 

+ 1 - 1
deploy/docker/Dockerfile

@@ -4,7 +4,7 @@ COPY . /go/kuiper
 
 WORKDIR /go/kuiper
 
-RUN apk add upx gcc make git libc-dev binutils-gold pkgconfig zeromq-dev && make
+RUN apk add upx gcc make git libc-dev binutils-gold pkgconfig zeromq-dev && make build_with_edgex
 
 FROM alpine:3.10
 

+ 24 - 2
fvt_scripts/run_jmeter.sh

@@ -1,4 +1,24 @@
 #!/bin/bash
+# This script accepts the following parameters:
+#
+# * with_edgex
+#
+# Example:
+#
+# ./fvt_scripts/run_jmeter.sh with_edgex=true
+#
+# or
+#
+# ./fvt_scripts/run_jmeter.sh with_edgex=false
+#
+
+set -e
+
+CONFIG=$@
+
+for line in $CONFIG; do
+  eval "$line"
+done
 
 function downloadjar
 {
@@ -47,5 +67,7 @@ echo -e "---------------------------------------------\n"
 /opt/jmeter/bin/jmeter.sh -Jjmeter.save.saveservice.output_format=xml -n -t fvt_scripts/select_aggr_rule_order.jmx -l jmeter_logs/select_aggr_rule_order.jtl
 echo -e "---------------------------------------------\n"
 
-/opt/jmeter/bin/jmeter.sh -Jjmeter.save.saveservice.output_format=xml -n -t fvt_scripts/select_edgex_condition_rule.jmx -Dbase="$base_dir" -Dfvt="$fvt_dir" -l jmeter_logs/select_edgex_condition_rule.jtl
-echo -e "---------------------------------------------\n"
+if test $with_edgex = true; then
+  /opt/jmeter/bin/jmeter.sh -Jjmeter.save.saveservice.output_format=xml -n -t fvt_scripts/select_edgex_condition_rule.jmx -Dbase="$base_dir" -Dfvt="$fvt_dir" -l jmeter_logs/select_edgex_condition_rule.jtl
+  echo -e "---------------------------------------------\n"
+fi

+ 2 - 0
xstream/extensions/edgex_source.go

@@ -1,3 +1,5 @@
+// +build edgex
+
 package extensions
 
 import (

+ 1 - 1
xstream/nodes/with_edgex.go

@@ -1,4 +1,4 @@
-// +build linux
+// +build edgex
 
 package nodes
 

+ 1 - 1
xstream/nodes/without_edgex.go

@@ -1,4 +1,4 @@
-// +build !linux
+// +build !edgex
 
 package nodes