forked from galexrt/srcds_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
111 lines (90 loc) · 3.28 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
PROJECTNAME ?= srcds_exporter
DESCRIPTION ?= srcds_exporter - Expose metrics such as player count, current map and current players from SRCDS servers.
MAINTAINER ?= Alexander Trost <[email protected]>
HOMEPAGE ?= https://github.com/galexrt/srcds_exporter
GO111MODULE ?= on
GO ?= go
PROMU ?= promu
FPM ?= fpm
CWD ?= $(shell pwd)
BIN_DIR ?= $(CWD)/.bin
TARBALL_DIR ?= $(CWD)/.tarball
PACKAGE_DIR ?= $(CWD)/.package
ARCH ?= amd64
PACKAGE_ARCH ?= linux-amd64
PREFIX ?= .
# 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.13.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 ?= srcds_exporter
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
all: format style vet test build
build: promu
@echo ">> building binaries"
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
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)
package-%: build
mkdir -p -m0755 $(PACKAGE_DIR)/usr/bin $(PACKAGE_DIR)/etc/sysconfig $(PACKAGE_DIR)/etc/srcds_exporter
mkdir -p $(PACKAGE_DIR)/etc/sysconfig
cp .build/srcds_exporter $(PACKAGE_DIR)/usr/bin
cp srcds.example.yaml $(PACKAGE_DIR)/etc/srcds_exporter
cd $(PACKAGE_DIR) && $(FPM) -s dir -t $(patsubst package-%, %, $@) \
--deb-user root --deb-group root \
--name $(PROJECTNAME) \
--version $(VERSION) \
--architecture $(PACKAGE_ARCH) \
--description "$(DESCRIPTION)" \
--maintainer "$(MAINTAINER)" \
--url $(HOMEPAGE) \
usr/ etc/
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: promu
@echo ">> building release tarball"
@$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
test:
@$(GO) test $(pkgs)
test-short:
@echo ">> running short tests"
@$(GO) test -short $(pkgs)
vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)
.PHONY: all build crossbuild docker format package promu style tarball test vet