From 0a671e7caba69a6a587014b6a3438b879430e618 Mon Sep 17 00:00:00 2001 From: glyasai Date: Sun, 29 Sep 2019 18:27:20 +0800 Subject: [PATCH] [REV] use 'ldflags' instead of 'tag' --- release.sh | 10 +++++-- util/license/license.go | 25 +++++++++++++++-- util/license/no_license.go | 56 -------------------------------------- 3 files changed, 30 insertions(+), 61 deletions(-) delete mode 100644 util/license/no_license.go diff --git a/release.sh b/release.sh index f710f4d44..218511c2a 100755 --- a/release.sh +++ b/release.sh @@ -28,6 +28,10 @@ buildTime=$(date +%F-%H) git_commit=$(git log -n 1 --pretty --format=%h) release_desc=${VERSION}-${git_commit}-${buildTime} +ENTERPRISE=false +if [ "${ENTERPRISE}" = "true" ];then + ENTERPRISE=true +fi build::node() { local releasedir=./.release @@ -38,7 +42,7 @@ build::node() { case $1 in node) echo "build node" - docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -tags license -o $releasedir/dist/usr/local/bin/node ./cmd/node + docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" --ldflags "-w -s -X github.com/goodrain/rainbond/util/license.enterprise=${ENTERPRISE}" -o $releasedir/dist/usr/local/bin/node ./cmd/node ;; grctl) echo "build grctl" @@ -50,7 +54,7 @@ build::node() { ;; *) echo "build node" - docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -tags license -o $releasedir/dist/usr/local/bin/node ./cmd/node + docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" --ldflags "-w -s -X github.com/goodrain/rainbond/util/license.enterprise=${ENTERPRISE}" -o $releasedir/dist/usr/local/bin/node ./cmd/node echo "build grctl" docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o $releasedir/dist/usr/local/bin/grctl ./cmd/grctl echo "build certutil" @@ -87,7 +91,7 @@ build::binary() { docker run --rm -e GOOS=${GOOS} -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GATEWAY_GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o ${OUTPATH} ./cmd/$1 else if [ "${ENTERPRISE}" = "true" ];then - docker run --rm -e GOOS=${GOOS} -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -tags license -o ${OUTPATH} ./cmd/$1 + docker run --rm -e GOOS=${GOOS} -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" --ldflags "-w -s -X github.com/goodrain/rainbond/util/license.enterprise=${ENTERPRISE}" -o ${OUTPATH} ./cmd/$1 else docker run --rm -e GOOS=${GOOS} -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o ${OUTPATH} ./cmd/$1 fi diff --git a/util/license/license.go b/util/license/license.go index 7f13cad01..fe41b3352 100644 --- a/util/license/license.go +++ b/util/license/license.go @@ -16,8 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -//+build license - package license import ( @@ -26,10 +24,13 @@ import ( "io/ioutil" "os" "plugin" + "strconv" "github.com/Sirupsen/logrus" ) +var enterprise string + // LicInfo license information type LicInfo struct { LicKey string `json:"license_key"` @@ -45,6 +46,14 @@ type LicInfo struct { ModuleList []string `json:"module_list"` } +func isEnterprise() bool { + res, err := strconv.ParseBool(enterprise) + if err != nil { + logrus.Warningf("enterprise: %s; error parsing 'string' to 'bool': %v", enterprise, err) + } + return res +} + func readFromFile(lfile string) (string, error) { _, err := os.Stat(lfile) if err != nil { @@ -61,6 +70,9 @@ func readFromFile(lfile string) (string, error) { // VerifyTime verifies the time in the license. func VerifyTime(licPath, licSoPath string) bool { + if !isEnterprise() { + return true + } lic, err := readFromFile(licPath) if err != nil { logrus.Errorf("failed to read license from file: %v", err) @@ -81,6 +93,9 @@ func VerifyTime(licPath, licSoPath string) bool { // VerifyNodes verifies the number of the nodes in the license. func VerifyNodes(licPath, licSoPath string, nodeNums int) bool { + if !isEnterprise() { + return true + } lic, err := readFromFile(licPath) if err != nil { logrus.Errorf("failed to read license from file: %v", err) @@ -101,6 +116,9 @@ func VerifyNodes(licPath, licSoPath string, nodeNums int) bool { // GetLicInfo - func GetLicInfo(licPath, licSoPath string) (*LicInfo, error) { + if !isEnterprise() { + return nil, nil + } lic, err := readFromFile(licPath) if err != nil { logrus.Errorf("failed to read license from file: %v", err) @@ -128,6 +146,9 @@ func GetLicInfo(licPath, licSoPath string) (*LicInfo, error) { // GenLicKey - func GenLicKey(licSoPath string) (string, error) { + if !isEnterprise() { + return "", nil + } p, err := plugin.Open(licSoPath) if err != nil { logrus.Errorf("license.so path: %s; error opening license.so: %v", licSoPath, err) diff --git a/util/license/no_license.go b/util/license/no_license.go deleted file mode 100644 index bdbb1f746..000000000 --- a/util/license/no_license.go +++ /dev/null @@ -1,56 +0,0 @@ -// RAINBOND, Application Management Platform -// Copyright (C) 2014-2017 Goodrain Co., Ltd. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. For any non-GPL usage of Rainbond, -// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd. -// must be obtained first. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -//+build !license - -package license - -// LicInfo license information -type LicInfo struct { - LicKey string `json:"license_key"` - Code string `json:"code"` - Company string `json:"company"` - Node int64 `json:"node"` - CPU int64 `json:"cpu"` - Memory int64 `json:"memory"` - Tenant int64 `json:"tenant"` - EndTime string `json:"end_time"` - StartTime string `json:"start_time"` - DataCenter int64 `json:"data_center"` - ModuleList []string `json:"module_list"` -} - -// VerifyTime verifies the time in the license. -func VerifyTime(licPath, licSoPath string) bool { - return true -} - -// VerifyNodes verifies the number of the nodes in the license. -func VerifyNodes(licPath, licSoPath string, nodeNums int) bool { - return true -} - -// GetLicInfo - -func GetLicInfo(licPath, licSoPath string) (*LicInfo, error) { - return nil, nil -} - -// GenLicKey - -func GenLicKey(licSoPath string) (string, error) { - return "", nil -}