forked from stackrox/collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
211 lines (171 loc) · 6.47 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
ARCH := $(shell arch)
ifeq ($(ARCH),x86_64)
ARCHDIR=
ARCHEXTN=
else ifeq ($(ARCH),amd64)
ARCHDIR=
ARCHEXTN=
else
ARCHDIR=/$(ARCH)
ARCHEXTN=.$(ARCH)
endif
BASE_PATH = .
include Makefile-constants.mk
MOD_VER_FILE=$(CURDIR)/kernel-modules/kobuild-tmp/MODULE_VERSION.txt
LOCAL_SSH_PORT ?= 2222
DEV_SSH_SERVER_KEY ?= $(CURDIR)/.collector_dev_ssh_host_ed25519_key
export COLLECTOR_VERSION := $(COLLECTOR_TAG)
export MODULE_VERSION := $(shell cat $(CURDIR)/kernel-modules/MODULE_VERSION)
dev-build: image integration-tests-process-network
.PHONY: tag
tag:
@echo "$(COLLECTOR_TAG)"
.PHONY: container-dockerfile
container-dockerfile:
envsubst '$${COLLECTOR_VERSION} $${MODULE_VERSION}' \
< $(CURDIR)/collector/container/Dockerfile.template > \
$(CURDIR)/collector/container/Dockerfile.gen
.PHONY: builder
builder:
ifdef BUILD_BUILDER_IMAGE
docker build \
--cache-from quay.io/stackrox-io/collector-builder:cache \
--cache-from quay.io/stackrox-io/collector-builder:$(COLLECTOR_BUILDER_TAG) \
-t quay.io/stackrox-io/collector-builder:$(COLLECTOR_BUILDER_TAG) \
-f "$(CURDIR)/builder/Dockerfile" \
.
else
docker pull quay.io/stackrox-io/collector-builder:$(COLLECTOR_BUILDER_TAG)
endif
collector: builder
make -C collector container/bin/collector
.PHONY: unittest
unittest:
make -C collector unittest ||\
( .openshift-ci/slack/notify-if-needed.sh "unittest" $$? )
.PHONY: build-kernel-modules
build-kernel-modules:
make -C kernel-modules build-container
$(MOD_VER_FILE): build-kernel-modules
rm -rf kernel-modules/kobuild-tmp/
mkdir -p kernel-modules/kobuild-tmp/versions-src
cp kernel-modules/MODULE_VERSION $(MOD_VER_FILE)
.PHONY: $(CURDIR)/$(COLLECTOR_BUILD_CONTEXT)/bundle.tar.gz
$(CURDIR)/$(COLLECTOR_BUILD_CONTEXT)/bundle.tar.gz:
$(CURDIR)/collector/container/create-bundle.sh $(CURDIR)/collector/container $(CURDIR)/$(COLLECTOR_BUILD_CONTEXT)/
.PHONY: build-drivers
build-drivers:
make -C kernel-modules drivers
image: collector unittest container-dockerfile $(MOD_VER_FILE) $(CURDIR)/$(COLLECTOR_BUILD_CONTEXT)/bundle.tar.gz
make -C collector txt-files
docker build --build-arg collector_version="$(COLLECTOR_TAG)" \
--build-arg module_version="$(shell cat $(MOD_VER_FILE))" \
-f collector/container/Dockerfile.gen \
-t quay.io/stackrox-io/collector:$(COLLECTOR_TAG) \
$(COLLECTOR_BUILD_CONTEXT)
image-dev: COLLECTOR_BUILD_CONTEXT=collector/container/devel
image-dev: collector unittest container-dockerfile $(MOD_VER_FILE) $(CURDIR)/$(COLLECTOR_BUILD_CONTEXT)/bundle.tar.gz
make -C collector txt-files
docker build --build-arg collector_version="$(COLLECTOR_TAG)" \
--build-arg module_version="$(shell cat $(MOD_VER_FILE))" \
--build-arg BASE_REGISTRY=quay.io \
--build-arg BASE_IMAGE=centos/centos \
--build-arg BASE_TAG=stream8 \
-f collector/container/Dockerfile.gen \
-t quay.io/stackrox-io/collector:$(COLLECTOR_TAG) \
$(COLLECTOR_BUILD_CONTEXT)
image-dev-full: image-dev build-drivers
docker tag quay.io/stackrox-io/collector:$(COLLECTOR_TAG) quay.io/stackrox-io/collector:$(COLLECTOR_TAG)-slim
docker build \
--target=probe-layer-1 \
--tag quay.io/stackrox-io/collector:$(COLLECTOR_TAG)-full \
--build-arg collector_repo=quay.io/stackrox-io/collector \
--build-arg collector_version=$(COLLECTOR_TAG) \
--build-arg module_version=$(shell cat $(CURDIR)/kernel-modules/MODULE_VERSION) \
--build-arg max_layer_size=300 \
--build-arg max_layer_depth=1 \
$(CURDIR)/kernel-modules/container
.PHONY: integration-tests
integration-tests:
make -C integration-tests tests
.PHONY: integration-tests-benchmark
integration-tests-benchmark:
make -C integration-tests benchmark ||\
( .openshift-ci/slack/notify-if-needed.sh "benchmark" $$? )
.PHONY: integration-tests-baseline
integration-tests-baseline:
make -C integration-tests baseline ||\
( .openshift-ci/slack/notify-if-needed.sh "benchmark-baseline" $$? )
.PHONY: integration-tests-process-network
integration-tests-process-network:
make -C integration-tests process-network ||\
( .openshift-ci/slack/notify-if-needed.sh "process-network" $$? )
.PHONY: integration-tests-missing-proc-scrape
integration-tests-missing-proc-scrape:
make -C integration-tests missing-proc-scrape ||\
( .openshift-ci/slack/notify-if-needed.sh "missing-proc-scrape" $$? )
.PHONY: integration-tests-repeat-network
integration-tests-repeat-network:
make -C integration-tests repeat-network ||\
( .openshift-ci/slack/notify-if-needed.sh "repeat-network" $$? )
.PHONY: integration-tests-image-label-json
integration-tests-image-label-json:
make -C integration-tests image-label-json ||\
( .openshift-ci/slack/notify-if-needed.sh "image-label-json" $$? )
.PHONY: integration-tests-report
integration-tests-report:
make -C integration-tests report
.PHONY: ci-integration-tests
ci-integration-tests: integration-tests-repeat-network \
integration-tests-process-network \
integration-tests-missing-proc-scrape \
integration-tests-image-label-json \
integration-tests-report
.PHONY: ci-benchmarks
ci-benchmarks: integration-tests-baseline \
integration-tests-benchmark
.PHONY: ci-all-tests
ci-all-tests: ci-benchmarks ci-integration-tests
$(DEV_SSH_SERVER_KEY):
ifeq (,$(wildcard $(DEV_SSH_SERVER_KEY)))
ssh-keygen -t ed25519 -N '' -f $(DEV_SSH_SERVER_KEY) < /dev/null
endif
.PHONY: start-dev
start-dev: builder teardown-dev $(DEV_SSH_SERVER_KEY)
docker run -d \
--name collector_remote_dev \
--cap-add sys_ptrace -p127.0.0.1:$(LOCAL_SSH_PORT):22 \
-v $(DEV_SSH_SERVER_KEY):/etc/sshkeys/ssh_host_ed25519_key:ro \
quay.io/stackrox-io/collector-builder:$(COLLECTOR_BUILDER_TAG)
.PHONY: teardown-dev
teardown-dev:
-docker rm -fv collector_remote_dev
.PHONY: clean
clean: teardown-dev
make -C collector clean
.PHONY: shfmt-check
shfmt-check:
shfmt -d $(CURDIR)
.PHONY: shfmt-format
shfmt-format:
shfmt -w $(CURDIR)
.PHONY: shellcheck-all
shellcheck-all:
./utilities/shellcheck-all/shellcheck-all.sh
.PHONY: shellcheck-all-dockerized
shellcheck-all-dockerized:
docker build -t -f Dockerfile$(ARCHEXTN) shellcheck-all $(CURDIR)/utilities/shellcheck-all
docker run --rm -v "$(CURDIR):/scripts" shellcheck-all:latest
# This defines a macro that can be used to add pre-commit targets
# to check staged files (check-<linter name>) or all files (check-<linter name>-all)
define linter
check-$(1):
pre-commit run $(1)
check-$(1)-all:
pre-commit run --all-files $(1)
endef
$(eval $(call linter,flake8))
$(eval $(call linter,clang-format))
$(eval $(call linter,shellcheck))
$(eval $(call linter,shfmt))
$(eval $(call linter,circleci_validate))