-
Notifications
You must be signed in to change notification settings - Fork 46
/
Makefile
79 lines (63 loc) · 2.48 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
SHELL = /bin/bash
OS = $(shell uname -s)
# Project variables
PACKAGE = github.com/martonsereg/scheduler
BINARY_NAME = scheduler
IMAGE = martonsereg/scheduler
TAG = v0.3
# Build variables
BUILD_DIR ?= build
BUILD_PACKAGE = ${PACKAGE}/cmd/scheduler
VERSION ?= $(shell git rev-parse --abbrev-ref HEAD)
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null)
BUILD_DATE ?= $(shell date +%FT%T%z)
LDFLAGS += -X main.Version=${VERSION} -X main.CommitHash=${COMMIT_HASH} -X main.BuildDate=${BUILD_DATE}
export CGO_ENABLED ?= 0
ifeq (${VERBOSE}, 1)
GOARGS += -v
endif
DEP_VERSION = 0.5.0
GOLANG_VERSION = 1.11
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./client/*")
.PHONY: clean
clean: ## Clean the working area and the project
rm -rf bin/ ${BUILD_DIR}/ vendor/
rm -rf ${BINARY_NAME}
bin/dep: bin/dep-${DEP_VERSION}
@ln -sf dep-${DEP_VERSION} bin/dep
bin/dep-${DEP_VERSION}:
@mkdir -p bin
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | INSTALL_DIRECTORY=bin DEP_RELEASE_TAG=v${DEP_VERSION} sh
@mv bin/dep $@
.PHONY: vendor
vendor: bin/dep ## Install dependencies
bin/dep ensure -v -vendor-only
.PHONY: build
build: GOARGS += -tags "${GOTAGS}" -ldflags "${LDFLAGS}" -o ${BUILD_DIR}/${BINARY_NAME}
build: ## Build a binary
ifneq (${IGNORE_GOLANG_VERSION_REQ}, 1)
@printf "${GOLANG_VERSION}\n$$(go version | awk '{sub(/^go/, "", $$3);print $$3}')" | sort -t '.' -k 1,1 -k 2,2 -k 3,3 -g | head -1 | grep -q -E "^${GOLANG_VERSION}$$" || (printf "Required Go version is ${GOLANG_VERSION}\nInstalled: `go version`" && exit 1)
endif
go build ${GOARGS} ${BUILD_PACKAGE}
.PHONY: docker-image
docker-image: ## Builds docker image for the scheduler
docker build --rm -t $(IMAGE):$(TAG) .
.PHONY: docker-push
docker-push: ## Pushes the docker image to docker hub
docker push $(IMAGE):$(TAG)
.PHONY: fmt
fmt:
@gofmt -s -w ${GOFILES_NOVENDOR}
.PHONY: test
test:
set -o pipefail; go list ./... | xargs -n1 go test ${GOARGS} -v -parallel 1 2>&1 | tee test.txt
.PHONY: list
list: ## List all make targets
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
.PHONY: help
.DEFAULT_GOAL := help
help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# Variable outputting/exporting rules
var-%: ; @echo $($*)
varexport-%: ; @echo $*=$($*)