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
|
2017-11-29 16:15:53 +00:00
|
|
|
BINDIR = bin
|
|
|
|
RELEASEDIR = release
|
2017-06-06 11:39:41 +00:00
|
|
|
|
2017-11-29 16:15:53 +00:00
|
|
|
DIRS = $(BINDIR) $(RELEASEDIR)
|
|
|
|
|
|
|
|
GO_SRC := $(shell find . -name '*.go' ! -path '*/vendor/*' ! -path 'tools/*' ! -path 'bin/*' ! -path 'release/*' )
|
|
|
|
GO_DIRS := $(shell find . -type d -name '*.go' ! -path '*/vendor/*' ! -path 'tools/*' ! -path 'bin/*' ! -path 'release/*' )
|
2017-06-06 11:39:41 +00:00
|
|
|
GO_PKGS := $(shell go list ./... | grep -v '/vendor/')
|
2016-05-28 04:19:55 +00:00
|
|
|
|
|
|
|
CONTAINER_NAME ?= wrouesnel/postgres_exporter:latest
|
2017-11-29 16:15:53 +00:00
|
|
|
BINARY := $(shell basename $(shell pwd))
|
|
|
|
VERSION ?= $(shell git describe --dirty 2>/dev/null)
|
|
|
|
VERSION_SHORT ?= $(shell git describe --abbrev=0 2>/dev/null)
|
|
|
|
|
|
|
|
ifeq ($(VERSION),)
|
|
|
|
VERSION := v0.0.0
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(VERSION_SHORT),)
|
|
|
|
VERSION_SHORT := v0.0.0
|
|
|
|
endif
|
|
|
|
|
|
|
|
# By default this list is filtered down to some common platforms.
|
|
|
|
platforms := $(subst /,-,$(shell go tool dist list | grep -e linux -e windows -e darwin | grep -e 386 -e amd64))
|
2018-02-19 12:11:12 +00:00
|
|
|
PLATFORM_BINS_TMP := $(patsubst %,$(BINDIR)/$(BINARY)_$(VERSION_SHORT)_%/$(BINARY),$(platforms))
|
|
|
|
PLATFORM_BINS := $(patsubst $(BINDIR)/$(BINARY)_$(VERSION_SHORT)_windows-%/$(BINARY),$(BINDIR)/$(BINARY)_$(VERSION_SHORT)_windows-%/$(BINARY).exe,$(PLATFORM_BINS_TMP))
|
2017-11-29 16:15:53 +00:00
|
|
|
PLATFORM_DIRS := $(patsubst %,$(BINDIR)/$(BINARY)_$(VERSION_SHORT)_%,$(platforms))
|
|
|
|
PLATFORM_TARS := $(patsubst %,$(RELEASEDIR)/$(BINARY)_$(VERSION_SHORT)_%.tar.gz,$(platforms))
|
|
|
|
|
|
|
|
# These are evaluated on use, and so will have the correct values in the build
|
|
|
|
# rule (https://vic.demuzere.be/articles/golang-makefile-crosscompile/)
|
2018-02-19 12:11:12 +00:00
|
|
|
PLATFORMS_TEMP = $(subst /, ,$(subst -, ,$(patsubst $(BINDIR)/$(BINARY)_$(VERSION_SHORT)_%,%,$@)))
|
2017-11-29 16:15:53 +00:00
|
|
|
GOOS = $(word 1, $(PLATFORMS_TEMP))
|
|
|
|
GOARCH = $(word 2, $(PLATFORMS_TEMP))
|
|
|
|
|
2018-02-19 12:11:12 +00:00
|
|
|
CURRENT_PLATFORM_TMP := $(BINDIR)/$(BINARY)_$(VERSION_SHORT)_$(shell go env GOOS)-$(shell go env GOARCH)/$(BINARY)
|
|
|
|
CURRENT_PLATFORM := $(patsubst $(BINDIR)/$(BINARY)_$(VERSION_SHORT)_windows-%/$(BINARY),$(BINDIR)/$(BINARY)_$(VERSION_SHORT)_windows-%/$(BINARY).exe,$(CURRENT_PLATFORM_TMP))
|
2017-11-29 16:15:53 +00:00
|
|
|
|
|
|
|
CONCURRENT_LINTERS ?=
|
|
|
|
ifeq ($(CONCURRENT_LINTERS),)
|
|
|
|
CONCURRENT_LINTERS = $(shell gometalinter --help | grep -o 'concurrency=\w*' | cut -d= -f2 | cut -d' ' -f1)
|
|
|
|
endif
|
2016-05-28 04:19:55 +00:00
|
|
|
|
2017-06-06 11:39:41 +00:00
|
|
|
LINTER_DEADLINE ?= 30s
|
|
|
|
|
2017-11-29 16:15:53 +00:00
|
|
|
$(shell mkdir -p $(DIRS))
|
|
|
|
|
2017-06-06 11:39:41 +00:00
|
|
|
export PATH := $(TOOLDIR)/bin:$(PATH)
|
|
|
|
SHELL := env PATH=$(PATH) /bin/bash
|
|
|
|
|
2017-11-29 16:15:53 +00:00
|
|
|
all: style lint test binary
|
2016-05-28 04:19:55 +00:00
|
|
|
|
2017-11-29 16:15:53 +00:00
|
|
|
binary: $(BINARY)
|
2017-02-15 06:41:26 +00:00
|
|
|
|
2017-11-29 16:15:53 +00:00
|
|
|
$(BINARY): $(CURRENT_PLATFORM)
|
|
|
|
ln -sf $< $@
|
2016-05-28 04:19:55 +00:00
|
|
|
|
2017-11-29 16:15:53 +00:00
|
|
|
$(PLATFORM_BINS): $(GO_SRC)
|
|
|
|
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -a \
|
|
|
|
-ldflags "-extldflags '-static' -X main.Version=$(VERSION)" \
|
|
|
|
-o $@ .
|
|
|
|
|
|
|
|
$(PLATFORM_DIRS): $(PLATFORM_BINS)
|
|
|
|
|
|
|
|
$(PLATFORM_TARS): $(RELEASEDIR)/%.tar.gz : $(BINDIR)/%
|
|
|
|
tar -czf $@ -C $(BINDIR) $$(basename $<)
|
|
|
|
|
|
|
|
release-bin: $(PLATFORM_BINS)
|
|
|
|
|
|
|
|
release: $(PLATFORM_TARS)
|
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
|
2017-11-29 16:15:53 +00:00
|
|
|
docker: $(CURRENT_PLATFORM)
|
|
|
|
docker build --build-arg=binary=$(CURRENT_PLATFORM) -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-11-29 16:15:53 +00:00
|
|
|
postgres_exporter_integration_test: $(GO_SRC)
|
|
|
|
CGO_ENABLED=0 go test -c -tags integration \
|
|
|
|
-a -ldflags "-extldflags '-static' -X main.Version=$(VERSION)" \
|
|
|
|
-o postgres_exporter_integration_test -cover -covermode count .
|
|
|
|
|
|
|
|
test: tools
|
|
|
|
@mkdir -p $(COVERDIR)
|
|
|
|
@rm -f $(COVERDIR)/*
|
2017-06-06 11:39:41 +00:00
|
|
|
for pkg in $(GO_PKGS) ; do \
|
2017-10-09 01:22:07 +00:00
|
|
|
go test -v -covermode count -coverprofile=$(COVERDIR)/$$(echo $$pkg | tr '/' '-').out $$pkg || exit 1 ; \
|
2017-06-06 11:39:41 +00:00
|
|
|
done
|
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
|
|
|
|
|
2017-11-29 16:15:53 +00:00
|
|
|
clean:
|
|
|
|
[ ! -z $(BINDIR) ] && [ -e $(BINDIR) ] && find $(BINDIR) -print -delete || /bin/true
|
|
|
|
[ ! -z $(COVERDIR) ] && [ -e $(COVERDIR) ] && find $(COVERDIR) -print -delete || /bin/true
|
|
|
|
[ ! -z $(RELEASEDIR) ] && [ -e $(RELEASEDIR) ] && find $(RELEASEDIR) -print -delete || /bin/true
|
|
|
|
rm -f postgres_exporter postgres_exporter_integration_test
|
|
|
|
|
2017-06-06 11:39:41 +00:00
|
|
|
tools:
|
|
|
|
$(MAKE) -C $(TOOLDIR)
|
2017-11-29 16:15:53 +00:00
|
|
|
|
|
|
|
.PHONY: tools style fmt test all release binary clean
|