2015-08-24 17:27:14 +00:00
|
|
|
|
2017-08-01 08:18:28 +00:00
|
|
|
COVERDIR = .coverage
|
2017-06-06 11:39:41 +00:00
|
|
|
TOOLDIR = tools
|
|
|
|
|
|
|
|
GO_SRC := $(shell find . -name '*.go' ! -path '*/vendor/*' ! -path 'tools/*' )
|
|
|
|
GO_DIRS := $(shell find . -type d -name '*.go' ! -path '*/vendor/*' ! -path 'tools/*' )
|
|
|
|
GO_PKGS := $(shell go list ./... | grep -v '/vendor/')
|
2016-05-28 04:19:55 +00:00
|
|
|
|
|
|
|
CONTAINER_NAME ?= wrouesnel/postgres_exporter:latest
|
2017-02-24 13:19:07 +00:00
|
|
|
VERSION ?= $(shell git describe --dirty)
|
2016-05-28 04:19:55 +00:00
|
|
|
|
2017-06-06 11:39:41 +00:00
|
|
|
CONCURRENT_LINTERS ?= $(shell cat /proc/cpuinfo | grep processor | wc -l)
|
|
|
|
LINTER_DEADLINE ?= 30s
|
|
|
|
|
|
|
|
export PATH := $(TOOLDIR)/bin:$(PATH)
|
|
|
|
SHELL := env PATH=$(PATH) /bin/bash
|
|
|
|
|
|
|
|
all: style lint test postgres_exporter
|
2016-05-28 04:19:55 +00:00
|
|
|
|
2017-02-15 06:41:26 +00:00
|
|
|
# Cross compilation (e.g. if you are on a Mac)
|
|
|
|
cross: docker-build docker
|
|
|
|
|
2016-03-12 10:07:31 +00:00
|
|
|
# Simple go build
|
2016-05-28 04:19:55 +00:00
|
|
|
postgres_exporter: $(GO_SRC)
|
2017-02-24 13:19:07 +00:00
|
|
|
CGO_ENABLED=0 go build -a -ldflags "-extldflags '-static' -X main.Version=$(VERSION)" -o postgres_exporter .
|
2016-05-28 04:19:55 +00:00
|
|
|
|
2016-11-16 16:09:20 +00:00
|
|
|
postgres_exporter_integration_test: $(GO_SRC)
|
|
|
|
CGO_ENABLED=0 go test -c -tags integration \
|
2017-02-24 13:19:07 +00:00
|
|
|
-a -ldflags "-extldflags '-static' -X main.Version=$(VERSION)" -o postgres_exporter_integration_test -cover -covermode count .
|
2016-11-16 16:09:20 +00:00
|
|
|
|
2016-05-28 04:19:55 +00:00
|
|
|
# Take a go build and turn it into a minimal container
|
|
|
|
docker: postgres_exporter
|
2016-09-08 14:55:40 +00:00
|
|
|
docker build -t $(CONTAINER_NAME) .
|
2016-05-28 04:19:55 +00:00
|
|
|
|
2017-06-06 11:39:41 +00:00
|
|
|
style: tools
|
|
|
|
gometalinter --disable-all --enable=gofmt --vendor
|
2017-02-24 13:19:07 +00:00
|
|
|
|
2017-06-06 11:39:41 +00:00
|
|
|
lint: tools
|
|
|
|
@echo Using $(CONCURRENT_LINTERS) processes
|
|
|
|
gometalinter -j $(CONCURRENT_LINTERS) --deadline=$(LINTER_DEADLINE) --disable=gotype --disable=gocyclo $(GO_DIRS)
|
2017-02-24 13:19:07 +00:00
|
|
|
|
2017-06-06 11:39:41 +00:00
|
|
|
fmt: tools
|
2017-02-24 13:19:07 +00:00
|
|
|
gofmt -s -w $(GO_SRC)
|
2016-05-28 04:19:55 +00:00
|
|
|
|
2017-08-01 08:43:46 +00:00
|
|
|
run-tests: tools
|
|
|
|
mkdir -p $(COVERDIR)
|
2017-08-01 07:54:27 +00:00
|
|
|
rm -f $(COVERDIR)/*
|
2017-06-06 11:39:41 +00:00
|
|
|
for pkg in $(GO_PKGS) ; do \
|
2017-06-06 13:45:48 +00:00
|
|
|
go test -v -covermode count -coverprofile=$(COVERDIR)/$$(echo $$pkg | tr '/' '-').out $$pkg ; \
|
2017-06-06 11:39:41 +00:00
|
|
|
done
|
2017-08-01 08:43:46 +00:00
|
|
|
|
|
|
|
test: run-tests
|
2017-06-06 14:25:54 +00:00
|
|
|
gocovmerge $(shell find $(COVERDIR) -name '*.out') > cover.test.out
|
2015-08-24 17:27:14 +00:00
|
|
|
|
2016-11-16 16:09:20 +00:00
|
|
|
test-integration: postgres_exporter postgres_exporter_integration_test
|
2017-02-24 13:19:07 +00:00
|
|
|
tests/test-smoke "$(shell pwd)/postgres_exporter" "$(shell pwd)/postgres_exporter_integration_test_script $(shell pwd)/postgres_exporter_integration_test $(shell pwd)/cover.integration.out"
|
2016-05-28 07:03:38 +00:00
|
|
|
|
2017-06-06 14:25:54 +00:00
|
|
|
cover.out: tools
|
|
|
|
gocovmerge cover.*.out > cover.out
|
|
|
|
|
2016-09-08 14:55:40 +00:00
|
|
|
# Do a self-contained docker build - we pull the official upstream container
|
|
|
|
# and do a self-contained build.
|
2017-02-15 06:50:17 +00:00
|
|
|
docker-build:
|
2016-03-12 10:07:31 +00:00
|
|
|
docker run -v $(shell pwd):/go/src/github.com/wrouesnel/postgres_exporter \
|
2016-09-08 14:55:40 +00:00
|
|
|
-v $(shell pwd):/real_src \
|
|
|
|
-e SHELL_UID=$(shell id -u) -e SHELL_GID=$(shell id -g) \
|
2016-05-28 04:19:55 +00:00
|
|
|
-w /go/src/github.com/wrouesnel/postgres_exporter \
|
2017-06-06 11:39:41 +00:00
|
|
|
golang:1.8-wheezy \
|
2016-09-08 14:55:40 +00:00
|
|
|
/bin/bash -c "make >&2 && chown $$SHELL_UID:$$SHELL_GID ./postgres_exporter"
|
|
|
|
docker build -t $(CONTAINER_NAME) .
|
2016-03-12 10:07:31 +00:00
|
|
|
|
2017-02-15 06:41:26 +00:00
|
|
|
push:
|
|
|
|
docker push $(CONTAINER_NAME)
|
|
|
|
|
2017-06-06 11:39:41 +00:00
|
|
|
tools:
|
|
|
|
$(MAKE) -C $(TOOLDIR)
|
|
|
|
|
|
|
|
clean:
|
2017-08-01 08:43:46 +00:00
|
|
|
rm -rf postgres_exporter postgres_exporter_integration_test $(COVERDIR)
|
2017-06-06 11:39:41 +00:00
|
|
|
|
|
|
|
.PHONY: tools docker-build docker lint fmt test vet push cross clean
|