categraf/Makefile

47 lines
1.8 KiB
Makefile
Raw Normal View History

2022-06-04 22:22:26 +08:00
.SILENT:
2022-06-04 22:11:40 +08:00
.PHONY: build build-linux build-windows pack
2022-05-29 17:37:57 +08:00
2022-06-04 22:11:40 +08:00
APP:=categraf
ROOT:=$(shell pwd -P)
GIT_COMMIT:=$(shell git --work-tree ${ROOT} rev-parse 'HEAD^{commit}')
_GIT_VERSION:=$(shell git --work-tree ${ROOT} describe --tags --abbrev=14 "${GIT_COMMIT}^{commit}" 2>/dev/null)
2022-06-13 12:20:04 +08:00
TAG=$(shell echo "${_GIT_VERSION}" | awk -F"-" '{print $$1}')
GIT_VERSION:="$(TAG)-$(GIT_COMMIT)"
2022-06-04 22:28:04 +08:00
BUILD_VERSION:='flashcat.cloud/categraf/config.Version=$(GIT_VERSION)'
2022-06-04 22:11:40 +08:00
LDFLAGS:="-w -s -X $(BUILD_VERSION)"
2022-06-07 10:36:17 +08:00
all: build
2022-06-04 22:11:40 +08:00
vendor:
GOPROXY=https://goproxy.cn go mod vendor
2022-05-29 17:37:57 +08:00
build:
2022-06-04 22:11:40 +08:00
echo "Building version $(GIT_VERSION)"
go build -ldflags $(LDFLAGS) -o $(APP)
2022-06-24 10:10:54 +08:00
build-enterprise:
echo "Building version $(GIT_VERSION)"
go build --tags "enterprise" -ldflags $(LDFLAGS) -o $(APP)
2022-06-13 12:20:04 +08:00
2022-06-04 22:11:40 +08:00
build-linux:
echo "Building version $(GIT_VERSION) for linux"
2022-06-05 15:40:16 +08:00
GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -o $(APP)
2022-06-04 22:11:40 +08:00
build-windows:
echo "Building version $(GIT_VERSION) for windows"
2022-06-04 22:22:26 +08:00
GOOS=windows GOARCH=amd64 go build -ldflags $(LDFLAGS) -o $(APP).exe
2022-06-04 22:11:40 +08:00
build-mac:
echo "Building version $(GIT_VERSION) for mac"
2022-06-04 22:22:26 +08:00
GOOS=darwin GOARCH=amd64 go build -ldflags $(LDFLAGS) -o $(APP).mac
2022-06-04 22:11:40 +08:00
2022-06-13 12:20:04 +08:00
build-image: build-linux
echo "Building image flashcatcloud/categraf:$(TAG)"
cp -rf conf/config.toml conf/logs.toml conf/input.cpu conf/input.disk conf/input.diskio conf/input.docker conf/input.kernel conf/input.kernel_vmstat conf/input.linux_sysctl_fs conf/input.mem conf/input.net conf/input.netstat conf/input.processes conf/input.system docker/conf/ && cp -f categraf docker/ && cd docker && docker build -t flashcatcloud/categraf:$(TAG) .
2022-06-13 12:20:04 +08:00
2022-06-04 22:11:40 +08:00
pack:build-linux build-windows
2022-06-13 12:20:04 +08:00
rm -rf $(APP)-$(TAG).tar.gz
rm -rf $(APP)-$(TAG).zip
tar -zcvf $(APP)-$(TAG)-linux-amd64.tar.gz conf $(APP)
zip -r $(APP)-$(TAG)-windows-amd64.zip conf $(APP).exe