-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
102 lines (80 loc) · 3.03 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
PROJECTNAME ?= ancientt
DESCRIPTION ?= ancientt - A tool to automate network testing tools, like iperf3, in dynamic environments such as Kubernetes and more to come dynamic environments.
MAINTAINER ?= Alexander Trost <[email protected]>
HOMEPAGE ?= https://github.com/galexrt/ancientt
GO111MODULE ?= on
GO ?= go
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(PREFIX)/.bin
TARBALL_DIR ?= $(PREFIX)/.tarball
PACKAGE_DIR ?= $(PREFIX)/.package
ARCH ?= amd64
PACKAGE_ARCH ?= linux-amd64
# The GOHOSTARM and PROMU parts have been taken from the prometheus/promu repository
# which is licensed under Apache License 2.0 Copyright 2018 The Prometheus Authors
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)
ifeq (arm, $(GOHOSTARCH))
GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM)
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM)
else
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)
endif
PROMU_VERSION ?= 0.14.0
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
PROMU := $(FIRST_GOPATH)/bin/promu
# END copied code
pkgs = $(shell go list ./... | grep -v /vendor/ | grep -v /test/)
DOCKER_IMAGE_NAME ?= ancientt
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
go.check:
ifneq ($(shell $(GO) version | grep -q -E '\bgo($(GO_SUPPORTED_VERSIONS))\b' && echo 0 || echo 1), 0)
$(error unsupported go version. Please make install one of the following supported version: '$(GO_SUPPORTED_VERSIONS)')
endif
all: format style vet test build
build: promu
@echo ">> building binaries"
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX)
check_license:
@OUTPUT="$$($(PROMU) check licenses)"; \
if [[ $$OUTPUT ]]; then \
echo "Found go files without license header:"; \
echo "$$OUTPUT"; \
exit 1; \
else \
echo "All files with license header"; \
fi
docker:
@echo ">> building docker image"
docker build \
--build-arg BUILD_DATE="$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--build-arg VCS_REF="$(shell git rev-parse HEAD)" \
-t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" \
.
format:
go fmt $(pkgs)
promu:
$(eval PROMU_TMP := $(shell mktemp -d))
curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
mkdir -p $(FIRST_GOPATH)/bin
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
rm -r $(PROMU_TMP)
style:
@echo ">> checking code style"
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
tarball:
@echo ">> building release tarball"
@$(PROMU) tarball --prefix $(TARBALL_DIR) $(BIN_DIR)
test:
@$(GO) test $(pkgs)
test-short:
@echo ">> running short tests"
@$(GO) test -short $(pkgs)
vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)
docs: pkg/config/config.go
@echo ">> generating docs"
$(GO) run ./cmd/docgen/ api pkg/config/*.go > docs/config-structure.md
.PHONY: all build docker docs format go.check style test test-short vet