-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
71 lines (59 loc) · 2.2 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
PACKAGE_NAME := github.com/munnerz/k8s-api-pager-demo
REGISTRY := quay.io/munnerz
IMAGE_NAME := pager
IMAGE_TAGS := latest
GOPATH ?= $HOME/go
HACK_DIR ?= hack
BUILD_TAG := build
# Get a list of all binaries to be built
CMDS := $(shell find ./cmd/ -maxdepth 1 -type d -exec basename {} \; | grep -v cmd)
# Path to dockerfiles directory
DOCKERFILES := $(HACK_DIR)/build/dockerfiles
# A list of all types.go files in pkg/apis
TYPES_FILES = $(shell find pkg/apis -name types.go)
# docker_build_controller, docker_build_apiserver etc
DOCKER_BUILD_TARGETS = $(addprefix docker_build_, $(CMDS))
# docker_push_controller, docker_push_apiserver etc
DOCKER_PUSH_TARGETS = $(addprefix docker_push_, $(CMDS))
.PHONY: verify build docker_build push generate generate_verify $(CMDS) go_test go_fmt $(DOCKER_BUILD_TARGETS) $(DOCKER_PUSH_TARGETS)
# Alias targets
###############
verify: generate_verify go_verify
build: $(CMDS) docker_build
docker_build: $(DOCKER_BUILD_TARGETS)
docker_push: $(DOCKER_PUSH_TARGETS)
push: build docker_push
# Code generation
#################
# This target runs all required generators against our API types.
generate: $(TYPES_FILES)
$(HACK_DIR)/update-codegen.sh
generate_verify:
$(HACK_DIR)/verify-codegen.sh
# Go targets
#################
go_verify: go_fmt go_test
$(CMDS):
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags '-w' -o $(DOCKERFILES)/pager-$@_linux_amd64 ./cmd/$@
go_test:
go test $$(go list ./... | grep -v '/vendor/')
go_fmt:
@set -e; \
GO_FMT=$$(git ls-files *.go | grep -v 'vendor/' | xargs gofmt -d); \
if [ -n "$${GO_FMT}" ] ; then \
echo "Please run go fmt"; \
echo "$$GO_FMT"; \
exit 1; \
fi
# Docker targets
################
$(DOCKER_BUILD_TARGETS):
$(eval DOCKER_BUILD_CMD := $(subst docker_build_,,$@))
docker build -t $(REGISTRY)/$(IMAGE_NAME)-$(DOCKER_BUILD_CMD):$(BUILD_TAG) -f $(DOCKERFILES)/$(DOCKER_BUILD_CMD)/Dockerfile $(DOCKERFILES)
$(DOCKER_PUSH_TARGETS):
$(eval DOCKER_PUSH_CMD := $(subst docker_push_,,$@))
set -e; \
for tag in $(IMAGE_TAGS); do \
docker tag $(REGISTRY)/$(IMAGE_NAME)-$(DOCKER_PUSH_CMD):$(BUILD_TAG) $(REGISTRY)/$(IMAGE_NAME)-$(DOCKER_PUSH_CMD):$${tag} ; \
docker push $(REGISTRY)/$(IMAGE_NAME)-$(DOCKER_PUSH_CMD):$${tag}; \
done