2015-08-04 20:52:44 +00:00
|
|
|
UNAME := $(shell sh -c 'uname')
|
2015-08-18 16:16:59 +00:00
|
|
|
VERSION := $(shell sh -c 'git describe --always --tags')
|
2015-11-20 22:23:48 +00:00
|
|
|
ifdef GOBIN
|
|
|
|
PATH := $(GOBIN):$(PATH)
|
|
|
|
else
|
|
|
|
PATH := $(subst :,/bin:,$(GOPATH))/bin:$(PATH)
|
2015-09-10 17:01:08 +00:00
|
|
|
endif
|
2015-08-04 20:52:44 +00:00
|
|
|
|
2015-10-28 17:59:19 +00:00
|
|
|
# Standard Telegraf build
|
2015-12-04 18:44:56 +00:00
|
|
|
default: prepare build
|
|
|
|
|
2016-01-29 18:02:54 +00:00
|
|
|
# Windows build
|
2016-01-30 18:30:01 +00:00
|
|
|
windows: prepare-windows build-windows
|
2016-01-29 18:02:54 +00:00
|
|
|
|
2015-12-04 18:44:56 +00:00
|
|
|
# Only run the build (no dependency grabbing)
|
|
|
|
build:
|
2016-05-02 23:22:28 +00:00
|
|
|
go install -ldflags "-X main.version=$(VERSION)" ./...
|
2015-08-04 20:52:44 +00:00
|
|
|
|
2016-01-30 18:30:01 +00:00
|
|
|
build-windows:
|
|
|
|
go build -o telegraf.exe -ldflags \
|
2016-05-02 23:22:28 +00:00
|
|
|
"-X main.version=$(VERSION)" \
|
2016-01-30 18:30:01 +00:00
|
|
|
./cmd/telegraf/telegraf.go
|
|
|
|
|
2015-12-21 19:49:56 +00:00
|
|
|
build-for-docker:
|
2016-03-09 17:50:06 +00:00
|
|
|
CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo -o telegraf -ldflags \
|
2016-05-02 23:22:28 +00:00
|
|
|
"-s -X main.version=$(VERSION)" \
|
2015-12-21 19:49:56 +00:00
|
|
|
./cmd/telegraf/telegraf.go
|
|
|
|
|
2015-10-28 17:59:19 +00:00
|
|
|
# Build with race detector
|
2015-10-08 17:33:56 +00:00
|
|
|
dev: prepare
|
2016-05-02 23:22:28 +00:00
|
|
|
go build -race -ldflags "-X main.version=$(VERSION)" ./...
|
2015-10-08 17:33:56 +00:00
|
|
|
|
2016-02-18 04:57:33 +00:00
|
|
|
# run package script
|
|
|
|
package:
|
|
|
|
./scripts/build.py --package --version="$(VERSION)" --platform=linux --arch=all --upload
|
2015-12-21 19:49:56 +00:00
|
|
|
|
2015-12-08 23:18:23 +00:00
|
|
|
# Get dependencies and use gdm to checkout changesets
|
2015-07-06 04:46:43 +00:00
|
|
|
prepare:
|
2015-12-08 23:18:23 +00:00
|
|
|
go get github.com/sparrc/gdm
|
|
|
|
gdm restore
|
2015-08-04 20:52:44 +00:00
|
|
|
|
2016-01-29 18:02:54 +00:00
|
|
|
# Use the windows godeps file to prepare dependencies
|
|
|
|
prepare-windows:
|
|
|
|
go get github.com/sparrc/gdm
|
|
|
|
gdm restore -f Godeps_windows
|
|
|
|
|
2015-10-28 17:59:19 +00:00
|
|
|
# Run all docker containers necessary for unit tests
|
2015-10-27 17:50:16 +00:00
|
|
|
docker-run:
|
2015-08-18 16:16:59 +00:00
|
|
|
ifeq ($(UNAME), Darwin)
|
2015-10-27 17:50:16 +00:00
|
|
|
docker run --name kafka \
|
|
|
|
-e ADVERTISED_HOST=$(shell sh -c 'boot2docker ip || docker-machine ip default') \
|
|
|
|
-e ADVERTISED_PORT=9092 \
|
|
|
|
-p "2181:2181" -p "9092:9092" \
|
|
|
|
-d spotify/kafka
|
2015-08-18 16:16:59 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(UNAME), Linux)
|
2015-10-27 17:50:16 +00:00
|
|
|
docker run --name kafka \
|
|
|
|
-e ADVERTISED_HOST=localhost \
|
|
|
|
-e ADVERTISED_PORT=9092 \
|
|
|
|
-p "2181:2181" -p "9092:9092" \
|
|
|
|
-d spotify/kafka
|
2015-08-18 16:16:59 +00:00
|
|
|
endif
|
2015-10-27 17:50:16 +00:00
|
|
|
docker run --name mysql -p "3306:3306" -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql
|
|
|
|
docker run --name memcached -p "11211:11211" -d memcached
|
|
|
|
docker run --name postgres -p "5432:5432" -d postgres
|
|
|
|
docker run --name rabbitmq -p "15672:15672" -p "5672:5672" -d rabbitmq:3-management
|
|
|
|
docker run --name opentsdb -p "4242:4242" -d petergrace/opentsdb-docker
|
|
|
|
docker run --name redis -p "6379:6379" -d redis
|
|
|
|
docker run --name aerospike -p "3000:3000" -d aerospike
|
|
|
|
docker run --name nsq -p "4150:4150" -d nsqio/nsq /nsqd
|
2015-11-13 20:37:24 +00:00
|
|
|
docker run --name mqtt -p "1883:1883" -d ncarlier/mqtt
|
2015-11-18 21:27:10 +00:00
|
|
|
docker run --name riemann -p "5555:5555" -d blalor/riemann
|
2016-01-20 20:11:28 +00:00
|
|
|
docker run --name snmp -p "31161:31161/udp" -d titilambert/snmpsim
|
2015-08-18 16:16:59 +00:00
|
|
|
|
2015-10-28 17:59:19 +00:00
|
|
|
# Run docker containers necessary for CircleCI unit tests
|
2015-10-27 22:22:21 +00:00
|
|
|
docker-run-circle:
|
|
|
|
docker run --name kafka \
|
|
|
|
-e ADVERTISED_HOST=localhost \
|
|
|
|
-e ADVERTISED_PORT=9092 \
|
|
|
|
-p "2181:2181" -p "9092:9092" \
|
|
|
|
-d spotify/kafka
|
|
|
|
docker run --name opentsdb -p "4242:4242" -d petergrace/opentsdb-docker
|
|
|
|
docker run --name aerospike -p "3000:3000" -d aerospike
|
|
|
|
docker run --name nsq -p "4150:4150" -d nsqio/nsq /nsqd
|
2015-11-13 20:37:24 +00:00
|
|
|
docker run --name mqtt -p "1883:1883" -d ncarlier/mqtt
|
2015-11-18 21:27:10 +00:00
|
|
|
docker run --name riemann -p "5555:5555" -d blalor/riemann
|
2016-01-20 20:11:28 +00:00
|
|
|
docker run --name snmp -p "31161:31161/udp" -d titilambert/snmpsim
|
2015-10-27 22:22:21 +00:00
|
|
|
|
2015-10-28 17:59:19 +00:00
|
|
|
# Kill all docker containers, ignore errors
|
2015-10-27 17:50:16 +00:00
|
|
|
docker-kill:
|
2016-01-20 20:11:28 +00:00
|
|
|
-docker kill nsq aerospike redis opentsdb rabbitmq postgres memcached mysql kafka mqtt riemann snmp
|
|
|
|
-docker rm nsq aerospike redis opentsdb rabbitmq postgres memcached mysql kafka mqtt riemann snmp
|
2015-10-27 17:50:16 +00:00
|
|
|
|
2015-10-28 17:59:19 +00:00
|
|
|
# Run full unit tests using docker containers (includes setup and teardown)
|
2016-02-19 21:46:03 +00:00
|
|
|
test: vet docker-kill docker-run
|
2015-10-16 22:13:32 +00:00
|
|
|
# Sleeping for kafka leadership election, TSDB setup, etc.
|
2015-10-27 17:50:16 +00:00
|
|
|
sleep 60
|
2015-10-27 22:22:21 +00:00
|
|
|
# SUCCESS, running tests
|
2015-12-04 18:44:56 +00:00
|
|
|
go test -race ./...
|
2015-07-06 04:46:43 +00:00
|
|
|
|
2015-10-28 17:59:19 +00:00
|
|
|
# Run "short" unit tests
|
2016-02-19 21:46:03 +00:00
|
|
|
test-short: vet
|
2015-12-04 18:44:56 +00:00
|
|
|
go test -short ./...
|
2015-07-06 04:46:43 +00:00
|
|
|
|
2016-02-19 21:46:03 +00:00
|
|
|
vet:
|
|
|
|
go vet ./...
|
|
|
|
|
2016-02-21 17:43:24 +00:00
|
|
|
.PHONY: test test-short vet build default
|