-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile
127 lines (98 loc) · 3.54 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Copyright (C) 2016-2018 Nicolas Lamirault <[email protected]>
# 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 = pihole_exporter
VERSION=$(shell \
grep "const Version" version/version.go \
|awk -F'=' '{print $$2}' \
|sed -e "s/[^0-9.]//g" \
|sed -e "s/ //g")
SHELL = /bin/bash
DIR = $(shell pwd)
DOCKER = docker
GO = go
GOX = gox -os="linux darwin windows freebsd openbsd netbsd"
GOX_ARGS = "-output={{.Dir}}-$(VERSION)_{{.OS}}_{{.Arch}}"
BINTRAY_URI = https://api.bintray.com
BINTRAY_USERNAME = nlamirault
BINTRAY_REPOSITORY= oss
NO_COLOR=\033[0m
OK_COLOR=\033[32;01m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m
MAKE_COLOR=\033[33;01m%-20s\033[0m
MAIN = github.com/nlamirault/pihole_exporter
SRCS = $(shell git ls-files '*.go' | grep -v '^vendor/')
PKGS = $(shell glide novendor)
EXE = $(shell ls pihole_exporter-${VERSION}_*)
PACKAGE=$(APP)-$(VERSION)
ARCHIVE=$(PACKAGE).tar
.DEFAULT_GOAL := help
.PHONY: help
help:
@echo -e "$(OK_COLOR)==== $(APP) [$(VERSION)] ====$(NO_COLOR)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(MAKE_COLOR) : %s\n", $$1, $$2}'
clean: ## Cleanup
@echo -e "$(OK_COLOR)[$(APP)] Cleanup$(NO_COLOR)"
@rm -fr $(EXE) $(APP) $(APP)-*.tar.gz
.PHONY: deps
deps: ## Install dependencies
@echo -e "$(OK_COLOR)[$(APP)] Update dependencies$(NO_COLOR)"
@glide up -u -s -v
.PHONY: build
build: ## Make binary
@echo -e "$(OK_COLOR)[$(APP)] Build $(NO_COLOR)"
@$(GO) build .
.PHONY: test
test: ## Launch unit tests
@echo -e "$(OK_COLOR)[$(APP)] Launch unit tests $(NO_COLOR)"
@$(GO) test -v $$(glide nv)
.PHONY: run
run: ## Start exporter
@echo -e "$(OK_COLOR)[$(APP)] Start the exporter $(NO_COLOR)"
@./$(APP) -log.level DEBUG
.PHONY: lint
lint: ## Launch golint
@$(foreach file,$(SRCS),golint $(file) || exit;)
.PHONY: vet
vet: ## Launch go vet
@$(foreach file,$(SRCS),$(GO) vet $(file) || exit;)
.PHONY: errcheck
errcheck: ## Launch go errcheck
@echo -e "$(OK_COLOR)[$(APP)] Go Errcheck $(NO_COLOR)"
@$(foreach pkg,$(PKGS),errcheck $(pkg) $(glide novendor) || exit;)
.PHONY: coverage
coverage: ## Launch code coverage
@$(foreach pkg,$(PKGS),$(GO) test -cover $(pkg) $(glide novendor) || exit;)
docker-build: ## Build Docker image
@echo -e "$(OK_COLOR)Docker build $(APP):$(VERSION)$(NO_COLOR)"
@docker build -t $(APP):$(VERSION) .
docker-run: ## Run the Docker image
@echo -e "$(OK_COLOR)Docker run $(APP):$(VERSION)$(NO_COLOR)"
@docker run --rm=true \
$(APP):$(VERSION) \
-log.level debug -pihole http://127.0.0.1:9180
gox: ## Make all binaries
@echo -e "$(OK_COLOR)[$(APP)] Create binaries $(NO_COLOR)"
$(GOX) $(GOX_ARGS) github.com/nlamirault/pihole_exporter
.PHONY: binaries
binaries: ## Upload all binaries
@echo -e "$(OK_COLOR)[$(APP)] Upload binaries to Bintray $(NO_COLOR)"
for i in $(EXE); do \
curl -T $$i \
-u$(BINTRAY_USERNAME):$(BINTRAY_APIKEY) \
"$(BINTRAY_URI)/content/$(BINTRAY_USERNAME)/$(BINTRAY_REPOSITORY)/$(APP)/${VERSION}/$$i;publish=1"; \
done
# for goprojectile
.PHONY: gopath
gopath:
@echo `pwd`:`pwd`/vendor