-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
133 lines (107 loc) · 3.98 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
128
129
130
131
132
133
###################### PlayNet Makefile ######################
#
# This Makefile is used to manage the PlayNet command-line template
# All possible tools have to reside under their respective folders in cmd/
# and are being autodetected.
# 'make full' would then process them all while 'make toolname' would only
# handle the specified one(s).
# Edit this file with care, as it is also being used by our CI/CD Pipeline
# For usage information check README.md
#
# Parts of this makefile are based upon github.com/kolide/kit
#
NAME := democracy.bot
REPO := playnet-public
GIT_HOST := github.com
REGISTRY := quay.io
IMAGE := playnet/$(NAME)
PATH := $(GOPATH)/bin:$(PATH)
TOOLS_DIR := cmd
VERSION = $(shell git describe --tags --always --dirty)
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
REVISION = $(shell git rev-parse HEAD)
REVSHORT = $(shell git rev-parse --short HEAD)
USER = $(shell whoami)
MAKEFLAGS += --no-print-directory
SUBDIRS := $(patsubst $(TOOLS_DIR)/%,%,$(wildcard $(TOOLS_DIR)/*))
# if SINGLE_TOOL=1 the targets will work without specifying full/toolname
# set to != 1 if never more than one
SINGLE_TOOL := $(words $(SUBDIRS))
$(if $(findstring full,$(MAKECMDGOALS)), $(eval SINGLE_TOOL=2),)
TARGETS ?= default
-include .env
include helpers/make_version
include helpers/make_gohelpers
include helpers/make_dockerbuild
include helpers/make_db
### MAIN STEPS ###
default: .build-all
# install required tools and dependencies
deps:
go get -u golang.org/x/tools/cmd/goimports
go get -u github.com/golang/lint/golint
go get -u github.com/kisielk/errcheck
go get -u github.com/golang/dep/cmd/dep
ifdef BUILD_DEB
go get -u github.com/bborbe/debian_utils/bin/create_debian_package
endif
dep ensure
# test entire repo
test:
@go test -cover -race $(shell go list ./... | grep -v /vendor/)
# install passed in tool project
install:
$(if $(TOOL),GOBIN=$(GOPATH)/bin go install $(TOOLS_DIR)/$(TOOL)/*.go, \
$(if $(filter-out 1,$(SINGLE_TOOL)),, GOBIN=$(GOPATH)/bin go install $(TOOLS_DIR)/$(strip $(SUBDIRS))/*.go))
# build passed in tool project
build: .pre-build
$(if $(TOOL),GOBIN=$(GOPATH)/bin go build -i -o build/$(TOOL) -ldflags ${KIT_VERSION} ./$(TOOLS_DIR)/$(TOOL)/, \
$(if $(filter-out 1,$(SINGLE_TOOL)),, GOBIN=$(GOPATH)/bin go build -i -o build/$(strip $(SUBDIRS)) -ldflags ${KIT_VERSION} ./$(TOOLS_DIR)/$(strip $(SUBDIRS))/))
# execute targets for all tool projects
full:
$(eval MAKE_TARGETS=$(strip $(subst full,,$(MAKECMDGOALS))))
$(eval TARGETS=$(strip $(filter-out $(SUBDIRS),$(MAKE_TARGETS))))
@for dir in $(SUBDIRS); do \
make $$dir $(TARGETS); \
done
# run specified tool binary
run: build
@$(if $(TOOL),./build/$(TOOL) \
-logtostderr \
-v=2, \
$(if $(filter-out 1,$(SINGLE_TOOL)),, ./build/$(strip $(SUBDIRS)) \
-logtostderr \
-v=2))
# run specified tool from code
dev:
@$(if $(TOOL),go run -ldflags ${KIT_VERSION} $(TOOLS_DIR)/$(TOOL)/*.go \
-logtostderr \
-v=4 -debug, \
$(if $(filter-out 1,$(SINGLE_TOOL)),, go run -ldflags ${KIT_VERSION} $(TOOLS_DIR)/$(strip $(SUBDIRS))/*.go \
-logtostderr \
-v=4 -debug))
# build the docker image
docker: build-in-docker
TOOL=$(NAME) make build-image
# upload the docker image
upload:
docker push $(REGISTRY)/$(IMAGE)
### HELPER STEPS ###
# execute targets on single tool projects
$(SUBDIRS):
@echo ""
$(eval TARGETS=$(strip $(filter-out $(SUBDIRS),$(MAKECMDGOALS))))
TOOL=$@ make $(TARGETS)
# clean local vendor folder
clean:
rm -rf build
docker rmi -f $(shell docker images -q --filter=reference=$(REGISTRY)/$(IMAGE)*)
build-docker-bin:
$(if $(TOOL),GOBIN=$(GOPATH)/bin CGO_ENABLED=0 GOOS=linux go build -i -o build/$(TOOL) -ldflags ${KIT_VERSION_DOCKER} -a -installsuffix cgo ./$(TOOLS_DIR)/$(TOOL)/, )
.pre-build:
@mkdir -p build
.build-all:
make full build
update-deployment: docker upload clean restart-deployment
restart-deployment:
kubectl delete po -n bot -lapp=democracy