forked from tinkerbell/tink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.mk
95 lines (81 loc) · 3.27 KB
/
rules.mk
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
# Only use the recipes defined in these makefiles
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
# Delete target files if there's an error
# This avoids a failure to then skip building on next run if the output is created by shell redirection for example
# Not really necessary for now, but just good to have already if it becomes necessary later.
.DELETE_ON_ERROR:
# Treat the whole recipe as a one shell script/invocation instead of one-per-line
.ONESHELL:
# Use bash instead of plain sh
SHELL := bash
.SHELLFLAGS := -o pipefail -euc
binaries := cmd/tink-cli/tink-cli cmd/tink-controller/tink-controller cmd/tink-server/tink-server cmd/tink-worker/tink-worker cmd/virtual-worker/virtual-worker
version := $(shell git rev-parse --short HEAD)
tag := $(shell git tag --points-at HEAD)
ifneq (,$(tag))
version := $(tag)-$(version)
endif
LDFLAGS := -ldflags "-X main.version=$(version)"
export CGO_ENABLED := 0
.PHONY: server cli worker virtual-worker test $(binaries)
cli: cmd/tink-cli/tink-cli
controller: cmd/tink-controller/tink-controller
server: cmd/tink-server/tink-server
worker : cmd/tink-worker/tink-worker
virtual-worker : cmd/virtual-worker/virtual-worker
crossbinaries := $(addsuffix -linux-,$(binaries))
crossbinaries := $(crossbinaries:=amd64) $(crossbinaries:=arm64)
.PHONY: crosscompile $(crossbinaries)
%-amd64: FLAGS=GOOS=linux GOARCH=amd64
%-arm64: FLAGS=GOOS=linux GOARCH=arm64
$(binaries) $(crossbinaries):
$(FLAGS) go build $(LDFLAGS) -o $@ ./$(@D)
.PHONY: tink-cli-image tink-controller-image tink-server-image tink-worker-image virtual-worker-image
tink-cli-image: cmd/tink-cli/tink-cli-linux-amd64
docker build -t tink-cli cmd/tink-cli/
tink-controller-image: cmd/tink-controller/tink-controller-linux-amd64
docker build -t tink-controller cmd/tink-controller/
tink-server-image: cmd/tink-server/tink-server-linux-amd64
docker build -t tink-server cmd/tink-server/
tink-worker-image: cmd/tink-worker/tink-worker-linux-amd64
docker build -t tink-worker cmd/tink-worker/
virtual-worker-image: cmd/virtual-worker/virtual-worker-linux-amd64
docker build -t virtual-worker cmd/virtual-worker/
.PHONY: run-stack
run-stack:
docker-compose up --build
ifeq ($(origin GOBIN), undefined)
GOBIN := ${PWD}/bin
export GOBIN
PATH := ${GOBIN}:${PATH}
export PATH
endif
toolsBins := $(addprefix bin/,$(notdir $(shell awk -F'"' '/^\s*_/ {print $$2}' tools.go | sed 's|/v[[:digit:]]\+||')))
# installs cli tools defined in tools.go
$(toolsBins): go.mod go.sum tools.go
$(toolsBins): CMD=$(shell grep -w '$(@F)' tools.go | awk -F'"' '{print $$2}')
$(toolsBins):
go install $(CMD)
.PHONY: protomocks
protomocks: bin/moq
go generate ./protos/...
gofumpt -s -w ./protos/*/mock.go
.PHONY: check-protomocks
check-protomocks:
@git diff --no-ext-diff --quiet --exit-code -- protos/*/mock.go || (
echo "Mock files need to be regenerated!";
git diff --no-ext-diff --exit-code --stat -- protos/*/mock.go
)
.PHONY: pbfiles
pbfiles: buf.gen.yaml buf.lock $(shell git ls-files 'protos/*/*.proto') $(toolsBins)
buf generate
gofumpt -w protos/*/*.pb.*
.PHONY: check-pbfiles
check-pbfiles: pbfiles
@git diff --no-ext-diff --quiet --exit-code -- protos/*/*.pb.* || (
echo "Protobuf files need to be regenerated!";
git diff --no-ext-diff --exit-code --stat -- protos/*/*.pb.*
)
e2etest-setup: $(toolsBins)
setup-envtest use