-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
186 lines (154 loc) · 5.92 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
ARCH ?= $(shell arch)
SUDO ?= $(shell which sudo 2>/dev/null)
USER ?= $(shell whoami)
CURRENT_DATE_TAG ?= $(shell date +%Y%m%d-%H%M)
PKG_VERSION ?= $(shell cat VERSION)
# bmake Settings
MAKE_SYS_PATH ?= /usr/share/mk
export MAKESYSPATH = ${MAKE_SYS_PATH}
# Container Settings
NOCONTAINER ?=
BUILD_CONTAINER_IMAGE ?=
NO_CACHE ?=
CONTAINER_ENGINE ?= docker
CONTAINER_REPOSITORY ?= ghcr.io/elastic/ebpf-builder
CONTAINER_PULL_TAG ?= 20221121-1315
CONTAINER_LOCAL_TAG ?= ebpf-builder:${USER}-latest
IMAGEPACK_REPOSITORY ?= ghcr.io/elastic/ebpf-imagepack
IMAGEPACK_PULL_TAG ?= 20231006-0053
TESTBIN_SRC = $(wildcard testing/test_bins/*.c)
TESTBIN_PROGS = $(patsubst testing/test_bins/%.c,testing/test_bins/bin/${ARCH}/%,$(TESTBIN_SRC))
ifdef BUILD_CONTAINER_IMAGE
CONTAINER_IMAGE = ${CONTAINER_LOCAL_TAG}
else
CONTAINER_IMAGE ?= ${CONTAINER_REPOSITORY}:${CONTAINER_PULL_TAG}
CONTAINER_RELEASE_IMAGE ?= ${CONTAINER_REPOSITORY}:${CURRENT_DATE_TAG}
endif
ifdef NOCONTAINER
CONTAINER_RUN_CMD =
else
ifeq ($(CONTAINER_ENGINE),podman)
EXTRA_FLAGS = --userns=keep-id
else
EXTRA_FLAGS =
endif
CONTAINER_RUN_CMD = ${CONTAINER_ENGINE} run --platform linux/${ARCH} --rm -v${PWD}:${PWD} -w${PWD} -u$(shell id -u):$(shell id -g) ${EXTRA_FLAGS} -e NOCONTAINER=TRUE ${CONTAINER_IMAGE}
endif
PWD = $(shell pwd)
BUILD_DIR ?= ${PWD}/artifacts-${ARCH}
PKG_DIR ?= ${BUILD_DIR}/package
MDATA_DIR ?= ${BUILD_DIR}/package/share/elastic/ebpf
CMAKE_FLAGS = -DARCH=${ARCH}
ARTIFACTS_PATH ?= ${PWD}/artifacts-${ARCH}
# Debug settings
ifdef DEBUG
CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-g -O0"
endif
# Directories to search recursively for c/cpp source files to clang-format
FORMAT_DIRS = GPL/ non-GPL/ testing/test_bins
.PHONY = build package clean container format test-format release-container update-kims kip
build:
ifdef NOCONTAINER
mkdir -p ${BUILD_DIR}/
cmake ${EXTRA_CMAKE_FLAGS} ${CMAKE_FLAGS} -B${BUILD_DIR} -S${PWD}
cmake --build ${BUILD_DIR} --parallel $(shell nproc)
@echo -e "\n++ Build Successful at `date` ++\n"
else
ifdef BUILD_CONTAINER_IMAGE
${MAKE} container
endif
${CONTAINER_RUN_CMD} \
${MAKE} build DEBUG=${DEBUG} ARCH=${ARCH} EXTRA_CMAKE_FLAGS=${EXTRA_CMAKE_FLAGS}
endif
package:
ifdef NOCONTAINER
@echo "Packaging ebpf version: ${PKG_VERSION}"
cmake --install ${BUILD_DIR} --prefix ${PKG_DIR}
mkdir -p ${MDATA_DIR}
cp VERSION ${MDATA_DIR}
cp NOTICE.txt ${MDATA_DIR}
cp LICENSE.txt ${MDATA_DIR}
cd ${PKG_DIR} && tar -czf ${BUILD_DIR}/elastic-ebpf-${PKG_VERSION}-SNAPSHOT.tar.gz *
@echo -e "\n++ Packaging Successful at `date` ++\n"
else
ifdef BUILD_CONTAINER_IMAGE
${MAKE} container
endif
${CONTAINER_RUN_CMD} \
${MAKE} package DEBUG=${DEBUG} ARCH=${ARCH} EXTRA_CMAKE_FLAGS=${EXTRA_CMAKE_FLAGS}
endif
container:
${CONTAINER_ENGINE} buildx build ${NO_CACHE} --progress plain --platform=linux/${ARCH} -t ${CONTAINER_LOCAL_TAG} -f docker/Dockerfile.builder .
tag-container:
${CONTAINER_ENGINE} tag ${CONTAINER_LOCAL_TAG} ${CONTAINER_IMAGE}
@echo -e "\n++ Tagged image as ${CONTAINER_IMAGE} ++\n"
release-container:
${CONTAINER_ENGINE} buildx build ${NO_CACHE} --progress plain --platform linux/amd64 \
-t ${CONTAINER_RELEASE_IMAGE}-amd64 -f docker/Dockerfile.builder .
${CONTAINER_ENGINE} buildx build ${NO_CACHE} --progress plain --platform linux/arm64 \
-t ${CONTAINER_RELEASE_IMAGE}-arm64 -f docker/Dockerfile.builder .
${CONTAINER_ENGINE} push ${CONTAINER_RELEASE_IMAGE}-arm64
${CONTAINER_ENGINE} push ${CONTAINER_RELEASE_IMAGE}-amd64
${CONTAINER_ENGINE} manifest create ${CONTAINER_RELEASE_IMAGE} \
--amend ${CONTAINER_RELEASE_IMAGE}-arm64 \
--amend ${CONTAINER_RELEASE_IMAGE}-amd64
${CONTAINER_ENGINE} manifest annotate ${CONTAINER_RELEASE_IMAGE} ${CONTAINER_RELEASE_IMAGE}-arm64 --arch arm64
${CONTAINER_ENGINE} manifest annotate ${CONTAINER_RELEASE_IMAGE} ${CONTAINER_RELEASE_IMAGE}-amd64 --arch amd64
${CONTAINER_ENGINE} manifest push ${CONTAINER_RELEASE_IMAGE}
${CONTAINER_ENGINE} manifest rm ${CONTAINER_RELEASE_IMAGE}
@echo -e "\n++ Successfully released image: ${CONTAINER_RELEASE_IMAGE} ++\n"
format:
ifdef NOCONTAINER
sh -c 'find ${FORMAT_DIRS} -name "*.cpp" -o -name "*.c" -o -name "*.h" -o -name "*.cpp" | xargs clang-format -i'
else
ifdef BUILD_CONTAINER_IMAGE
${MAKE} container
endif
${CONTAINER_RUN_CMD} ${MAKE} format
endif
test-format:
ifdef NOCONTAINER
sh -c 'find ${FORMAT_DIRS} -name "*.cpp" -o -name "*.c" -o -name "*.h" -o -name "*.cpp" | xargs clang-format -i --dry-run -Werror'
else
ifdef BUILD_CONTAINER_IMAGE
@${MAKE} container
endif
${CONTAINER_RUN_CMD} ${MAKE} test-format
endif
# Update kernel images from gcs
update-kims:
@mkdir -p LargeFiles
gsutil -m rsync -d -r gs://ebpf-ci-kernel-images LargeFiles
# Build Containerized Kernel Image Pack(s)
build-kips:
for dir in $(shell ls ./LargeFiles); do \
${CONTAINER_ENGINE} build -t ${IMAGEPACK_REPOSITORY}:$${dir}-${CURRENT_DATE_TAG} -f docker/Dockerfile.imagepack --build-arg IMGPACK_FILTER=$${dir} ./LargeFiles/$${dir}; \
done
publish-kips:
@${MAKE} build-kips CURRENT_DATE_TAG=${CURRENT_DATE_TAG}
@for dir in $(shell ls ./LargeFiles); do \
${CONTAINER_ENGINE} push ${IMAGEPACK_REPOSITORY}:$${dir}-${CURRENT_DATE_TAG}; \
done
get-kernel-images:
mkdir -p ./kernel-images/
ifndef IMG_FILTER
@echo Must set IMG_FILTER
exit 1
endif
${CONTAINER_ENGINE} run --rm -v${PWD}/kernel-images:/kernel-images ${IMAGEPACK_REPOSITORY}:${IMG_FILTER}-${IMAGEPACK_PULL_TAG} cp -r /kernel-img-repository/${IMG_FILTER} ./kernel-images/
${SUDO} chown -fR ${USER}:${USER} .
run-multikernel-test: get-kernel-images
ifndef IMG_FILTER
@echo Must set IMG_FILTER
exit 1
endif
go install github.com/florianl/bluebox@b8590fb1850f56df6e6d7786931fcabdc1e9173d
cd testing && ./run_tests.sh ${ARCH} ${ARTIFACTS_PATH} ${PWD}/kernel-images/${IMG_FILTER}/${ARCH}/*
testbins: testbinpath $(TESTBIN_PROGS)
testbinpath:
mkdir -p testing/test_bins/bin/${ARCH}
testing/test_bins/bin/${ARCH}/%: testing/test_bins/%.c
$(CC) -g -static -o $@ $<
clean:
${SUDO} rm -rf artifacts-*
rm -r testing/test_bins/bin/*