Skip to content

Commit

Permalink
add juno agent makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
askuy committed Jul 10, 2020
1 parent 4dd73b0 commit 683a70d
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 82 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ db/
vendor/
default
default.etcd/
release
44 changes: 26 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@

SHELL:=/bin/bash
BASE_PATH:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BUILD_PATH:=$(BASE_PATH)/build
TITLE:=$(shell basename $(BASE_PATH))
VCS_INFO:=$(shell $(BUILD_PATH)/script/shell/vcs.sh)
BUILD_TIME:=$(shell date +%Y-%m-%d--%T)
APP_PKG:=$(shell $(BUILD_PATH)/script/shell/apppkg.sh)
JUPITER:=$(APP_PKG)/vendor/github.com/labstack/echo/v4/application
LDFLAGS:="-X $(JUPITER).vcsInfo=$(VCS_INFO) -X $(JUPITER).buildTime=$(BUILD_TIME) -X $(JUPITER).name=$(APP_NAME) -X $(JUPITER).id=$(APP_ID)"
SCRIPT_PATH:=$(BASE_PATH)/script
APP_NAME:=$(shell basename $(BASE_PATH))
COMPILE_OUT:=$(BASE_PATH)/release
APP_VERSION:=0.2.0


all:print fmt buildAgent

print:
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>making print<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@echo SHELL:$(SHELL)
@echo BASE_PATH:$(BASE_PATH)
@echo BUILD_PATH:$(BUILD_PATH)
@echo TITLE:$(TITLE)
@echo VCS_INFO:$(VCS_INFO)
@echo BUILD_TIME:$(BUILD_TIME)
@echo JUPITER:$(JUPITER)
@echo SCRIPT_PATH:$(SCRIPT_PATH)
@echo APP_NAME:$(APP_NAME)
@echo COMPILE_OUT:$(COMPILE_OUT)
@echo APP_VERSION:$(APP_VERSION)
@echo -e "\n"

fmt:
Expand Down Expand Up @@ -50,15 +46,27 @@ test:
@echo testPath ${BAST_PATH}
go test -v .${BAST_PATH}/...

buildAgent:
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>making build<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
chmod +x $(BUILD_PATH)/script/shell/*.sh
$(BUILD_PATH)/script/shell/build.sh $(LDFLAGS)
@echo -e "\n"


license: ## Add license header for all code files
@find . -name \*.go -exec sh -c "if ! grep -q 'LICENSE' '{}'; then mv '{}' tmp && cp doc/LICENSEHEADER.txt '{}' && cat tmp >> '{}' && rm tmp; fi" \;


run:
go run cmd/agent/main.go --config=config/config-live.toml
go run cmd/juno-agent/main.go --config=config/config.toml


build_all:build_agent build_data


build_agent:
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>making build juno agent<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@chmod +x $(SCRIPT_PATH)/build/*.sh
@cd cmd/juno-agent && $(SCRIPT_PATH)/build/gobuild.sh $(APP_NAME) $(COMPILE_OUT) $(APP_VERSION)
@echo -e "\n"

build_data:
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>making build juno agent data<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@chmod +x $(SCRIPT_PATH)/build/*.sh
@$(SCRIPT_PATH)/build/build_data.sh $(APP_NAME) $(APP_VERSION) $(BASE_PATH) $(COMPILE_OUT)/$(APP_VERSION)
@echo -e "\n"
6 changes: 0 additions & 6 deletions build/script/shell/apppkg.sh

This file was deleted.

22 changes: 0 additions & 22 deletions build/script/shell/build.sh

This file was deleted.

15 changes: 0 additions & 15 deletions build/script/shell/conn.sh

This file was deleted.

16 changes: 0 additions & 16 deletions build/script/shell/vcs.sh

This file was deleted.

File renamed without changes.
8 changes: 4 additions & 4 deletions config/config-live.toml → config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
enable = true
[plugin.regProxy.prometheus]
enable = true
path = "/home/www/server/prometheus/conf"
path = "/home/www/system/prometheus/conf"
[plugin.confProxy]
# 配置中心地址
env=["dev","live","pre"]
Expand All @@ -33,15 +33,15 @@
dir = "/usr/local/openresty/nginx/conf"
[plugin.report]
enable = true
debug = false
addr = "http://127.0.0.1:60812/api/v1/resource/node/heartbeat"
debug = true
addr = "http://127.0.0.1:50000/api/v1/resource/node/heartbeat"
internal = "60s"
hostName = "JUNO_HOST" # 环境变量的名称,或者命令行参数的名称
regionCode = "REGION_CODE" # 环境变量的名称,或者命令行参数的名称
regionName = "REGION_NAME"
zoneCode = "ZONE_CODE"
zoneName = "ZONE_NAME"
env = "env"
env = "ENV"
[plugin.healthCheck]
enable = true
[plugin.process]
Expand Down
1 change: 1 addition & 0 deletions pkg/model/agentStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type AgentReportRequest struct {
Hostname string `json:"hostname"`
IP string `json:"ip"`
AgentVersion string `json:"agent_version"`
AgentType int `json:"agent_type"`
RegionCode string `json:"region_code"`
RegionName string `json:"region_name"`
ZoneCode string `json:"zone_code"`
Expand Down
3 changes: 2 additions & 1 deletion pkg/report/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func (r *Report) ReportAgentStatus() error {
req := model.AgentReportRequest{
Hostname: r.config.HostName,
IP: appIP,
AgentVersion: "0.0.0.1",
AgentType: 1,
AgentVersion: "0.2.1",
RegionCode: r.config.RegionCode,
RegionName: r.config.RegionName,
ZoneCode: r.config.ZoneCode,
Expand Down
Binary file removed release/juno-agent.tar.gz
Binary file not shown.
27 changes: 27 additions & 0 deletions script/build/build_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

APP_NAME=${1:?"app name"}
APP_VERSION=${2:?"app version"}
BASE_PATH=${3:?"base path"}
RELEASE_PATH=${4:?"release path"}

#DIRINFO=${DIRINFO:-""}
#SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#
#
#if [[ -z ${DIRINFO} ]];then
# DIRINFO=$(mktemp)
# "${SCRIPTPATH}/folder.sh" ${RELEASE_PATH}> "${DIRINFO}"
#fi
#
#while read -r line; do
# cp -r ${BASE_PATH}/config ${RELEASE_PATH}/$line
# cp -r ${BASE_PATH}/data ${RELEASE_PATH}/$line
# cp -r ${BASE_PATH}/assets/dist ${RELEASE_PATH}/$line
#done < "${DIRINFO}"
PUB_TAR=${RELEASE_PATH}/${APP_NAME}_data_${APP_VERSION}.tar.gz
PUB_ZIP=${RELEASE_PATH}/${APP_NAME}_data_${APP_VERSION}.zip
tar zcf ${PUB_TAR} ./config
zip -r ${PUB_ZIP} ./config
echo ${PUB_TAR}
echo ${PUB_ZIP}
8 changes: 8 additions & 0 deletions script/build/folder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

RELEASE_PATH=${1:?"release path"}
for dir in $(ls ${RELEASE_PATH})
do
echo $dir
# [ -d $dir ] && echo $dir
done
88 changes: 88 additions & 0 deletions script/build/gobuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".

# Copyright Istio Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script builds and version stamps the output

VERBOSE=${VERBOSE:-"0"}
V=""
if [[ "${VERBOSE}" == "1" ]];then
V="-x"
set -x
fi

SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

APP_NAME=${1:?"app name"}
OUT=${2:?"output path"}
APP_VERSION=${3:?"app version"}
shift

set -e

BUILD_GOOS=${GOOS:-linux}
BUILD_GOARCH=${GOARCH:-amd64}
GOBINARY=${GOBINARY:-go}
GOPKG="$GOPATH/pkg"
BUILDINFO=${BUILDINFO:-""}
STATIC=${STATIC:-1}
LDFLAGS=${LDFLAGS:--extldflags -static}
GOBUILDFLAGS=${GOBUILDFLAGS:-""}
# Split GOBUILDFLAGS by spaces into an array called GOBUILDFLAGS_ARRAY.
IFS=' ' read -r -a GOBUILDFLAGS_ARRAY <<< "$GOBUILDFLAGS"

GCFLAGS=${GCFLAGS:-}
export CGO_ENABLED=0

if [[ "${STATIC}" != "1" ]];then
LDFLAGS=""
fi

# gather buildinfo if not already provided
# For a release build BUILDINFO should be produced
# at the beginning of the build and used throughout
if [[ -z ${BUILDINFO} ]];then
BUILDINFO=$(mktemp)
"${SCRIPTPATH}/report_build_info.sh" ${APP_NAME}> "${BUILDINFO}"
fi

# BUILD LD_EXTRAFLAGS
LD_EXTRAFLAGS=""

while read -r line; do
LD_EXTRAFLAGS="${LD_EXTRAFLAGS} -X ${line}"
done < "${BUILDINFO}"

# verify go version before build
# NB. this was copied verbatim from Kubernetes hack
minimum_go_version=go1.13 # supported patterns: go1.x, go1.x.x (x should be a number)
IFS=" " read -ra go_version <<< "$(${GOBINARY} version)"
if [[ "${minimum_go_version}" != $(echo -e "${minimum_go_version}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then
echo "Warning: Detected that you are using an older version of the Go compiler. Juno requires ${minimum_go_version} or greater."
fi

OPTIMIZATION_FLAGS="-trimpath"
if [ "${DEBUG}" == "1" ]; then
OPTIMIZATION_FLAGS=""
fi

goxc -d=${OUT} -pv=${APP_VERSION} -bc='linux,windows,darwin' -build-ldflags="${LD_EXTRAFLAGS}" -c=../../config
61 changes: 61 additions & 0 deletions script/build/report_build_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".

# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
APP_NAME=${1:?"app name"}

if BUILD_GIT_REVISION=$(git rev-parse HEAD 2> /dev/null); then
if [[ -n "$(git status --porcelain 2>/dev/null)" ]]; then
BUILD_GIT_REVISION=${BUILD_GIT_REVISION}"-dirty"
fi
else
BUILD_GIT_REVISION=unknown
fi

# Check for local changes
if git diff-index --quiet HEAD --; then
tree_status="Clean"
else
tree_status="Modified"
fi

# XXX This needs to be updated to accomodate tags added after building, rather than prior to builds
RELEASE_TAG=$(git describe --match '[0-9]*\.[0-9]*\.[0-9]*' --exact-match 2> /dev/null || echo "")

# security wanted VERSION='unknown'
VERSION="${BUILD_GIT_REVISION}"
if [[ -n "${RELEASE_TAG}" ]]; then
VERSION="${RELEASE_TAG}"
fi

GIT_DESCRIBE_TAG=$(git describe --tags)

# used by common/scripts/gobuild.sh
echo "github.com/douyu/jupiter/pkg.appName=${APP_NAME}"
echo "github.com/douyu/jupiter/pkg.buildVersion=${VERSION}"
echo "github.com/douyu/jupiter/pkg.buildGitRevision=${BUILD_GIT_REVISION}"
echo "github.com/douyu/jupiter/pkg.buildStatus=${tree_status}"
echo "github.com/douyu/jupiter/pkg.buildTag=${GIT_DESCRIBE_TAG}"
echo "github.com/douyu/jupiter/pkg.buildUser=$(whoami)"
echo "github.com/douyu/jupiter/pkg.buildHost=$(hostname -f)"
echo "github.com/douyu/jupiter/pkg.buildTime=$(date '+%Y-%m-%d--%T')"


0 comments on commit 683a70d

Please sign in to comment.