-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
264 lines (212 loc) · 7.06 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# Generate api contracts from protobuf.
.PHONY: gen-proto
gen-proto:
protoc api/v1/runtime/common.proto --go_out=paths=source_relative:.
protoc api/v1/runtime/runtime_agent_api.proto --go_out=paths=source_relative:. --go-grpc_out=require_unimplemented_servers=false:. --go-grpc_opt=paths=source_relative
protoc api/v1/kube/kube_api.proto --go_out=paths=source_relative:. --go-grpc_out=require_unimplemented_servers=false:. --go-grpc_opt=paths=source_relative
UNAME_M ?= $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
ARCH = x86_64
LINUX_ARCH = x86
GO_ARCH = amd64
endif
ifeq ($(UNAME_M),aarch64)
ARCH = arm64
LINUX_ARCH = arm64
GO_ARCH = arm64
endif
ifeq ($(UNAME_M),arm64)
ARCH = arm64
LINUX_ARCH = arm64
GO_ARCH = arm64
endif
LAST_GIT_TAG ?= $(shell $(CMD_GIT) describe --tags --match 'v*' 2>/dev/null)
VERSION ?= $(if $(RELEASE_TAG),$(RELEASE_TAG),$(LAST_GIT_TAG))
ifeq ($(VERSION),)
VERSION = local-$(shell date +%s)
endif
CMD_TR ?= tr
CMD_CUT ?= cut
CMD_CP ?= cp
CMD_AWK ?= awk
CMD_SED ?= sed
CMD_GIT ?= git
CMD_CLANG ?= clang
CMD_LLC ?= llc
CMD_STRIP ?= llvm-strip
CMD_RM ?= rm
CMD_INSTALL ?= install
CMD_MKDIR ?= mkdir
CMD_TOUCH ?= touch
CMD_PKGCONFIG ?= pkg-config
BPF_VCPU ?= v2
CMD_GO ?= go
KVISOR_EBPF_OBJ_CORE_HEADERS = $(shell find cmd/agent/ebpf/c -name *.h)
KVISOR_EBPF_OBJ_SRC = ./cmd/agent/ebpf/c/tracee.bpf.c
OUTPUT_DIR_BPF = ./dist
OUTPUT_DIR_BIN = ./bin
$(OUTPUT_DIR_BIN):
@$(CMD_MKDIR) -p $@
$(OUTPUT_DIR_BPF):
@$(CMD_MKDIR) -p $@
STATIC ?= 1
GO_TAGS_EBPF = core,ebpf
CGO_EXT_LDFLAGS_EBPF =
ifeq ($(STATIC), 1)
CGO_EXT_LDFLAGS_EBPF += -static
GO_TAGS_EBPF := $(GO_TAGS_EBPF),netgo
endif
.PHONY: builder-image
builder-image: $(OUTPUT_DIR_BPF)/builder-image.txt
$(OUTPUT_DIR_BPF)/builder-image.txt: $(OUTPUT_DIR_BPF)
echo $(GO_ARCH)
docker build -t ghcr.io/castai/kvisor/kvisor-builder:latest --build-arg TARGETARCH=$(GO_ARCH) . -f Dockerfile.builder
touch $(OUTPUT_DIR_BPF)/builder-image.txt
CMD_DOCKER_BUILDER=docker run --rm \
-v $$(pwd)/.cache/go-build:/home/.cache/go-build \
-v $$(pwd)/.cache/go-mod:/home/go/pkg/mod \
-v $$(pwd):/app \
-w /app ghcr.io/castai/kvisor/kvisor-builder:latest
CMD_DOCKER_BUILDER_LOCAL=docker run --rm -it --privileged --cap-add SYS_ADMIN --pid host --net host --name kvisor-builder \
-v $$(pwd)/.cache/go-build:/home/.cache/go-build \
-v $$(pwd)/.cache/go-mod:/home/go/pkg/mod \
-v $$(pwd):/app \
-v /sys/kernel/debug:/sys/kernel/debug \
-w /app ghcr.io/castai/kvisor/kvisor-builder:latest
.PHONY: gen-args-types
gen-args-types:
go generate ./pkg/ebpftracer/decoder
.PHONY: gen-bpf
gen-bpf:
go generate ./pkg/ebpftracer
go generate ./pkg/ebpftracer/debug
.PHONY: gen-bpf-docker
gen-bpf-docker: builder-image
$(CMD_DOCKER_BUILDER) make gen-bpf
GO_ENV_EBPF =
GO_ENV_EBPF += GOOS=linux
GO_ENV_EBPF += CC=$(CMD_CLANG)
GO_ENV_EBPF += GOARCH=$(GO_ARCH)
GO_ENV_EBPF += CGO_ENABLED=0
GO_DEBUG_FLAG = -s -w
# Build kvisor binary and docker image.
.PHONY: git-config
git-config:
git config --global --add safe.directory /app
.PHONY: kvisor-agent
kvisor-agent: $(OUTPUT_DIR_BIN)/kvisor-agent-$(GO_ARCH)
$(OUTPUT_DIR_BIN)/kvisor-agent-$(GO_ARCH): \
#
$(GO_ENV_EBPF) $(CMD_GO) build \
-tags $(GO_TAGS_EBPF) \
-ldflags="$(GO_DEBUG_FLAG) \
-extldflags \"$(CGO_EXT_LDFLAGS_EBPF)\" \
-X main.Version=\"$(VERSION)\" \
" \
-v -o $@ \
./cmd/agent/daemon/
.PHONY: clean-kvisor-agent
clean-kvisor-agent:
#
$(CMD_RM) -rf $(OUTPUT_DIR_BIN)/kvisor-agent-$(GO_ARCH)
.PHONY: kvisor-image-scanner
kvisor-image-scanner: $(OUTPUT_DIR_BIN)/kvisor-image-scanner-$(GO_ARCH)
$(OUTPUT_DIR_BIN)/kvisor-image-scanner-$(GO_ARCH): \
#
$(GO_ENV_EBPF) $(CMD_GO) build \
-tags $(GO_TAGS_EBPF) \
-ldflags="$(GO_DEBUG_FLAG) \
-extldflags \"$(CGO_EXT_LDFLAGS_EBPF)\" \
-X main.Version=\"$(VERSION)\" \
" \
-v -o $@ \
./cmd/imagescan/
.PHONY: clean-kvisor-image-scanner
clean-kvisor-image-scanner:
#
$(CMD_RM) -rf $(OUTPUT_DIR_BIN)/kvisor-image-scanner-$(GO_ARCH)
.PHONY: kvisor-linter
kvisor-linter: $(OUTPUT_DIR_BIN)/kvisor-linter-$(GO_ARCH)
$(OUTPUT_DIR_BIN)/kvisor-linter-$(GO_ARCH): \
#
$(GO_ENV_EBPF) $(CMD_GO) build \
-tags $(GO_TAGS_EBPF) \
-ldflags="$(GO_DEBUG_FLAG) \
-extldflags \"$(CGO_EXT_LDFLAGS_EBPF)\" \
-X main.Version=\"$(VERSION)\" \
" \
-v -o $@ \
./cmd/linter/
.PHONY: clean-kvisor-linter
clean-kvisor-linter:
#
$(CMD_RM) -rf $(OUTPUT_DIR_BIN)/kvisor-linter-$(GO_ARCH)
GO_ENV_SERVER =
GO_ENV_SERVER += GOOS=linux
GO_ENV_SERVER += GOARCH=$(GO_ARCH)
GO_ENV_SERVER += CGO_ENABLED=0
IMAGE_TAG ?= local
IMAGE_REPO ?= ghcr.io/castai/kvisor/kvisor
# Agent build.
.PHONY: kvisor-agent-docker
kvisor-agent-docker:
make kvisor-agent
.PHONY: kvisor-agent-docker-image
kvisor-agent-docker-image: clean-kvisor-agent kvisor-agent-docker
docker build -t $(IMAGE_REPO)-agent:$(IMAGE_TAG) . -f Dockerfile.agent
.PHONY: kvisor-agent-push-deploy
kvisor-agent-push-deploy: kvisor-agent-docker-image
docker push $(IMAGE_REPO)-agent:$(IMAGE_TAG)
# Controller build.
.PHONY: clean-kvisor-controller
clean-kvisor-controller:
$(CMD_RM) -rf $(OUTPUT_DIR_BIN)/kvisor-controller-$(GO_ARCH)
.PHONY: kvisor-controller
kvisor-controller: $(OUTPUT_DIR_BIN)/kvisor-controller-$(GO_ARCH)
$(OUTPUT_DIR_BIN)/kvisor-controller-$(GO_ARCH):
$(GO_ENV_SERVER) $(CMD_GO) build \
-ldflags="$(GO_DEBUG_FLAG) \
-X main.Version=\"$(VERSION)\" \
" \
-v -o $@ \
./cmd/controller
.PHONY: kvisor-controller-docker-image
kvisor-controller-docker-image: clean-kvisor-controller kvisor-controller
docker build -t $(IMAGE_REPO)-controller:$(IMAGE_TAG) . -f Dockerfile.controller
.PHONY: kvisor-controller-push-deploy
kvisor-controller-push-deploy: kvisor-controller-docker-image
docker push $(IMAGE_REPO)-controller:$(IMAGE_TAG)
# Scanners build.
.PHONY: kvisor-scanners-docker
kvisor-scanners-docker:
make kvisor-agent
.PHONY: kvisor-scanners-docker-image
kvisor-scanners-docker-image: clean-kvisor-image-scanner kvisor-image-scanner clean-kvisor-linter kvisor-linter
docker build -t $(IMAGE_REPO)-scanners:$(IMAGE_TAG) . -f Dockerfile.scanners
.PHONY: kvisor-scanners-push-deploy
kvisor-scanners-push-deploy: kvisor-scanners-docker-image
docker push $(IMAGE_REPO)-scanners:$(IMAGE_TAG)
# Event generator build.
.PHONY: clean-kvisor-event-generator
clean-kvisor-event-generator:
$(CMD_RM) -rf $(OUTPUT_DIR_BIN)/kvisor-event-generator
.PHONY: kvisor-event-generator
kvisor-event-generator: $(OUTPUT_DIR_BIN)/kvisor-event-generator
$(OUTPUT_DIR_BIN)/kvisor-event-generator:
$(GO_ENV_SERVER) $(CMD_GO) build \
-ldflags="$(GO_DEBUG_FLAG) \
-X main.Version=\"$(VERSION)\" \
" \
-v -o $@ \
./cmd/event-generator
.PHONY: kvisor-event-generator-docker-image
kvisor-event-generator-docker-image: clean-kvisor-event-generator kvisor-event-generator
docker build -t $(IMAGE_REPO)-event-generator:$(IMAGE_TAG) . -f Dockerfile.event-generator
.PHONY: kvisor-event-generator-push-deploy
kvisor-event-generator-push-deploy: kvisor-event-generator-docker-image
docker push $(IMAGE_REPO)-event-generator:$(IMAGE_TAG)
.PHONY: builder-image-enter
builder-image-enter: builder-image
$(CMD_DOCKER_BUILDER_LOCAL)
test:
go test `go list ./... | grep -v /e2e` -short ./...