This repository has been archived by the owner on Apr 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
114 lines (87 loc) · 3.27 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
SHELL := /usr/bin/env bash
PROJECTNAME ?= extended-ceph-exporter
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
VERSION := $(shell cat VERSION)
TOPDIR := $(shell pwd)
# 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/)
CONTAINER_IMAGE_NAME ?= docker.io/koorinc/extended-ceph-exporter
CONTAINER_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)
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
crossbuild: promu
$(PROMU) crossbuild
$(PROMU) crossbuild tarballs
docker: crossbuild
$(MAKE) docker-build
docker-build:
@echo ">> building docker image"
docker build \
--build-arg BUILD_DATE="$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--build-arg REVISION="$(shell git rev-parse HEAD)" \
-t "$(CONTAINER_IMAGE_NAME):$(CONTAINER_IMAGE_TAG)" \
.
docker tag "$(CONTAINER_IMAGE_NAME):$(CONTAINER_IMAGE_TAG)" "$(CONTAINER_IMAGE_NAME):latest"
docker-publish:
docker push "$(CONTAINER_IMAGE_NAME):$(CONTAINER_IMAGE_TAG)"
docker push "$(CONTAINER_IMAGE_NAME):latest"
format:
go fmt $(pkgs)
helm-doc:
GO111MODULE=on go install github.com/norwoodj/helm-docs/cmd/helm-docs@v1.11.0
helm-docs --chart-search-root=./charts
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: tree
@echo ">> building release tarball"
@$(PROMU) tarball --prefix $(TARBALL_DIR) $(BIN_DIR)
clean:
rm -rf $(PROJECTNAME) $(PROJECTNAME).spec $(PROJECTNAME)-$(VERSION).tar.gz
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 docker-publish format promu style tarball test test-short vet