forked from Netflix/titus-executor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (111 loc) · 4.59 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
138
139
140
141
142
143
144
145
# Builds the Titus Executor
export
# variables for order-only dependencies
include hack/make/dependencies.mk
# configuration for docker run
include hack/make/docker.mk
SHELL := /usr/bin/env bash -eu -o pipefail
LOCAL_DIRS = $(shell go list ./...)
TEST_FLAGS ?= -v -parallel 2
TEST_OUTPUT ?= test.xml
TEST_DOCKER_OUTPUT ?= test-standalone-docker.xml
GOBIN ?= $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/bin
PATH := $(PATH):$(GOBIN)
GOBIN_TOOL = $(shell which gobin || echo $(GOBIN)/gobin)
GOLANGCI_LINT_TIMEOUT := 2m
ifdef FAST
GOLANGCI_LINT_ARGS = --fast
endif
SHORT_CIRCUIT_QUITELITE := true
.PHONY: all
all: validate-docker test build
.PHONY: clean
clean:
rm -rf build/
rm -f $(TEST_OUTPUT) $(TEST_DOCKER_OUTPUT)
.PHONY: tini/src
tini/src:
git submodule update --init --recursive
.PHONY: build
build: tini/src vpc/service/db/migrations/bindata.go | $(clean) $(builder)
mkdir -p $(PWD)/build/distributions
$(DOCKER_RUN) -v $(PWD):$(PWD) -u $(UID):$(GID) -w $(PWD) \
-e "BUILD_HOST=$(JENKINS_URL)" -e "BUILD_JOB=$(JOB_NAME)" -e BUILD_NUMBER -e BUILD_ID -e ITERATION -e BUILDKITE_BRANCH \
-e ENABLE_DEV -e GOCACHE=$(PWD)/.cache \
titusoss/titus-executor-builder
.PHONY: build-standalone
build-standalone: tini/src
hack/builder/titus-executor-builder.sh
.PHONY: test
test: test-local test-standalone
TEST_DIRS = $(shell go list -f 'TEST-{{.ImportPath}}' ./...)
.PHONY: $(TEST_DIRS)
$(TEST_DIRS): | $(clean)
$(eval import_path := $(subst TEST-,,$@))
CGO_ENABLED=0 go test -o test-darwin/$(import_path).test -c $(import_path)
$(RM) test-darwin/$(import_path).test
.PHONY: build-tests-darwin
build-tests-darwin: $(TEST_DIRS)
.PHONY: cross-linux
cross-linux:
gox -osarch="linux/amd64" -output="build/bin/{{.OS}}-{{.Arch}}/{{.Dir}}" -verbose ./cmd/...
.PHONY: test-local
test-local: | $(clean)
CGO_ENABLED=0 go test $(TEST_FLAGS) -covermode=count -coverprofile=coverage-local.out -coverpkg=github.com/Netflix/... ./... \
| tee /dev/stderr > test-local.log
# run standalone tests against the docker container runtime
.PHONY: test-standalone
test-standalone: titus-agent | $(clean) $(builder)
./hack/tests-with-dind.sh
## Source code
.PHONY: validate
validate: metalinter
.PHONY: validate-docker
validate-docker: | $(builder)
$(DOCKER_RUN) -v $(PWD):/builds -w /builds titusoss/titus-executor-builder make -j lint
.PHONY: fmt
fmt: $(GOBIN_TOOL)
$(GOBIN_TOOL) -m -run golang.org/x/tools/cmd/goimports -w $(shell go list -f '{{.Dir}}' ./...)
.PHONY: golangci-lint
golangci-lint: $(GOBIN_TOOL)
GOOS=linux $(GOBIN_TOOL) -run github.com/golangci/golangci-lint/cmd/[email protected] run --timeout $(GOLANGCI_LINT_TIMEOUT) $(GOLANGCI_LINT_ARGS)
.PHONY: lint
lint: golangci-lint
.PHONY: metalinter
metalinter: lint
$(warning call the lint target)
## Support docker images
.PHONY: builder
builder:
@echo '---> Building titusoss/titus-executor-builder'
$(DOCKER) build -t titusoss/titus-executor-builder hack/builder
.PHONY: push-builder
push-builder: builder
$(DOCKER) push titusoss/titus-executor-builder
.PHONY: titus-agent
titus-agent: build
@echo '---> Building Titus Agent Docker-in-Docker image'
@$(DOCKER_BUILD) -t titusoss/titus-agent -f hack/agent/Dockerfile .
.PHONY: push-titus-agent
push-titus-agent: titus-agent
$(DOCKER) push titusoss/titus-agent
## Protobuf and source code generation
PROTO_DIR = vendor/github.com/Netflix/titus-api-definitions/src/main/proto
PROTOS := $(PROTO_DIR)/netflix/titus/titus_base.proto $(PROTO_DIR)/netflix/titus/titus_agent_api.proto $(PROTO_DIR)/netflix/titus/agent.proto $(PROTO_DIR)/netflix/titus/titus_vpc_api.proto $(PROTO_DIR)/netflix/titus/titus_job_api.proto
PROTO_MAP := Mnetflix/titus/titus_base.proto=github.com/Netflix/titus-executor/api/netflix/titus
.PHONY: protogen
protogen: $(GOBIN_TOOL) | $(clean) $(clean-proto-defs)
mkdir -p api
protoc --plugin=protoc-gen-titusgo=$(shell $(GOBIN_TOOL) -m -p github.com/golang/protobuf/protoc-gen-go) -I$(PROTO_DIR)/ -Ivpc/proto --titusgo_out=plugins=grpc:api/ $(PROTOS)
mkdir -p vpc/api
protoc --plugin=protoc-gen-titusgo=$(shell $(GOBIN_TOOL) -m -p github.com/golang/protobuf/protoc-gen-go) -I$(PROTO_DIR)/ -Ivpc/proto --titusgo_out=plugins=grpc,$(PROTO_MAP):vpc/api/ vpc/proto/vpc.proto
.PHONY: clean-proto-defs
clean-proto-defs: | $(clean)
rm -rf api/netflix/titus
rm -rf vpc/api
$(GOBIN_TOOL):
go get github.com/myitcv/gobin
go install github.com/myitcv/gobin
vpc/service/db/migrations/bindata.go: vpc/service/db/migrations/generate.go vpc/service/db/migrations/*.sql
go generate ./vpc/service/db/migrations/
make fmt