forked from typelevel/spire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
137 lines (103 loc) · 4.61 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
134
135
136
137
# Export SPIRE_DEV_HOST to docker to build SPIRE using a docker container
ifeq ($(SPIRE_DEV_HOST), docker)
docker = docker run -v $(docker_volume_spire) -v $(docker_volume_gopath) -it $(docker_image)
container = container
dev_host_status = "SET"
else
docker =
container =
dev_host_status = "UNSET"
endif
# Enable go modules
export GO111MODULE=on
# Makefile variables
binary_dirs := $(shell find cmd/* functional/tools/* -maxdepth 0 -type d)
docker_volume_gopath := $(shell echo $${GOPATH}/pkg/mod):/root/go/pkg/mod
docker_volume_spire := $(shell echo $${PWD}):/root/spire
docker_image = spire-dev:latest
gopath := $(shell go env GOPATH)
goversion := $(shell go version | cut -f3 -d' ')
goversion-required := $(shell cat .go-version)
gittag := $(shell git tag --points-at HEAD)
gitdirty := $(shell git status -s)
# don't provide the git tag if the git status is dirty.
ifneq ($(gitdirty),)
gittag :=
endif
ldflags := '-X github.com/spiffe/spire/pkg/common/version.gittag=$(gittag)'
utils = github.com/spiffe/spire/tools/spire-plugingen
external_utils = github.com/golang/protobuf/protoc-gen-go \
github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc \
github.com/jteeuwen/go-bindata/go-bindata \
github.com/golang/mock/mockgen \
github.com/AlekSi/gocoverutil \
github.com/mattn/goveralls
# Help message settings
cyan := $(shell which tput > /dev/null && tput setaf 6 || echo "")
reset := $(shell which tput > /dev/null && tput sgr0 || echo "")
bold := $(shell which tput > /dev/null && tput bold || echo "")
target_max_char=25
# Makefile options
.PHONY: all utils container-push cmd go-check build test race-test clean functional vendor help
# Makes sure the go version matches the expected version
go-check:
@[ "$(goversion)" = "go$(goversion-required)" ] || (echo "Expecting go$(goversion-required); got $(goversion)" 1>&2 && exit 1)
# Make targets
##@ Building
build: $(binary_dirs) ## Build SPIRE binaries
$(binary_dirs): go-check
$(docker) /bin/sh -c "cd $@; go build -ldflags $(ldflags)"
all: $(container) build test ## Build and run tests
##@ Testing
test: ## Run tests
$(docker) go test github.com/spiffe/spire/...
race-test: ## Run race tests
$(docker) go test -race github.com/spiffe/spire/...
integration: ## Run integration tests
$(docker) script/e2e_test.sh
functional: ## Run functional tests
$(MAKE) -C functional/ all
##@ Cleaning
clean: ## Go-clean object files
$(docker) go clean github.com/spiffe/spire/...
distclean: clean ## Remove object files, vendor and .cache folders
rm -rf .cache
rm -rf vendor
##@ Container
container: Dockerfile ## Build Docker container for compilation
docker build -t $(docker_image) --no-cache .
container-push: ## Push docker container image
docker tag $(docker_image) spiffe/$(docker_image)
docker push spiffe/$(docker_image)
cmd: ## Opens a shell in docker container
$(docker) /bin/bash
##@ SPIRE images
.PHONY: spire-images
spire-images: spire-server-image spire-agent-image ## Builds SPIRE Server and Agent docker images
.PHONY: spire-server-image
spire-server-image: Dockerfile.server ## Builds SPIRE Server docker image
docker build --build-arg goversion=$(goversion-required) -t spire-server -f Dockerfile.server .
# tag the image for local use (in systems tests, for example). "latest"
# isn't preferred since that can impact image pull policy (.e.g kubelet)
docker tag spire-server:latest spire-server:latest-local
.PHONY: spire-agent-image
spire-agent-image: Dockerfile.agent ## Builds SPIRE Agent docker image
docker build --build-arg goversion=$(goversion-required) -t spire-agent -f Dockerfile.agent .
# tag the image for local use (in systems tests, for example). "latest"
# isn't preferred since that can impact image pull policy (.e.g kubelet)
docker tag spire-agent:latest spire-agent:latest-local
##@ Others
utils: $(utils) $(external_utils) ## Go-get SPIRE utils
$(utils): noop
$(docker) /bin/sh -c "go install $@"
$(external_utils): noop
$(docker) /bin/sh -c "cd tools/external; go install $@"
# Vendor is not needed for building. It is just kept for compatibility with IDEs that does not support modules yet.
vendor: ## Make vendored copy of dependencies.
$(docker) go mod vendor
artifact: ## Build SPIRE artifacts
$(docker) ./build.sh artifact
noop:
help: ## Show this help message.
@awk 'BEGIN {FS = ":.*##"; printf "\n$(bold)Usage:$(reset) make $(cyan)<target>$(reset)\n"} /^[a-zA-Z_-]+:.*?##/ { printf " $(cyan)%-$(target_max_char)s$(reset) %s\n", $$1, $$2 } /^##@/ { printf "\n $(bold)%s$(reset) \n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@printf "\n$(bold)Enviroment variables$(reset)\n $(cyan)%-$(target_max_char)s $(reset) %s\n" SPIRE_DEV_HOST $(dev_host_status)