blob: 0f5c0a43630d2b5d4327859dc8933ec715c97c40 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001#!/usr/bin/env bash
2
Dave Wallacebee28af2024-06-14 14:59:38 -04003if [ "$(lsb_release -is)" != Ubuntu ]; then
Maros Ondrejickaf643b6f2023-01-17 10:52:20 +01004 echo "Host stack test framework is supported only on Ubuntu"
5 exit 1
6fi
7
Dave Wallacebee28af2024-06-14 14:59:38 -04008if [ -z "$(which ab)" ]; then
Maros Ondrejicka2ddb2fd2023-02-15 17:44:46 +01009 echo "Host stack test framework requires apache2-utils to be installed"
10 echo "It is recommended to run 'sudo make install-dep'"
11 exit 1
12fi
13
Dave Wallacebee28af2024-06-14 14:59:38 -040014if [ -z "$(which wrk)" ]; then
Maros Ondrejicka2ddb2fd2023-02-15 17:44:46 +010015 echo "Host stack test framework requires wrk to be installed"
16 echo "It is recommended to run 'sudo make install-dep'"
17 exit 1
18fi
19
Filip Tehlar671cf512023-01-31 10:34:18 +010020export VPP_WS=../..
Dave Wallace5eaa15d2024-06-18 17:10:07 -040021OS_ARCH="$(uname -m)"
22DOCKER_BUILD_DIR="/scratch/docker-build"
23DOCKER_CACHE_DIR="${DOCKER_BUILD_DIR}/docker_cache"
24
25if [ -d "${DOCKER_BUILD_DIR}" ] ; then
26 mkdir -p "${DOCKER_CACHE_DIR}"
27 DOCKER_HST_BUILDER="hst_builder"
28 set -x
29 if ! docker buildx ls --format "{{.Name}}" | grep -q "${DOCKER_HST_BUILDER}"; then
30 docker buildx create --name=${DOCKER_HST_BUILDER} --driver=docker-container --use --bootstrap || true
31 fi
32 set -x
33 DOCKER_CACHE_ARGS="--builder=${DOCKER_HST_BUILDER} --load --cache-to type=local,dest=${DOCKER_CACHE_DIR},mode=max --cache-from type=local,src=${DOCKER_CACHE_DIR}"
34fi
Filip Tehlar671cf512023-01-31 10:34:18 +010035
36if [ "$1" == "debug" ]; then
37 VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp_debug-native/vpp
adrianvillin85121452024-01-11 11:59:47 +010038elif [ "$1" == "gcov" ]; then
39 VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp_gcov-native/vpp
Filip Tehlar671cf512023-01-31 10:34:18 +010040else
41 VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp-native/vpp
42fi
43echo "Taking build objects from ${VPP_BUILD_ROOT}"
44
Dave Wallacebee28af2024-06-14 14:59:38 -040045export UBUNTU_VERSION=${UBUNTU_VERSION:-"$(lsb_release -rs)"}
Filip Tehlar671cf512023-01-31 10:34:18 +010046echo "Ubuntu version is set to ${UBUNTU_VERSION}"
47
Dave Wallace5eaa15d2024-06-18 17:10:07 -040048export HST_LDPRELOAD=${VPP_BUILD_ROOT}/lib/${OS_ARCH}-linux-gnu/libvcl_ldpreload.so
Filip Tehlar671cf512023-01-31 10:34:18 +010049echo "HST_LDPRELOAD is set to ${HST_LDPRELOAD}"
50
51export PATH=${VPP_BUILD_ROOT}/bin:$PATH
Filip Tehlar229f5fc2022-08-09 14:44:47 +000052
53bin=vpp-data/bin
54lib=vpp-data/lib
55
56mkdir -p ${bin} ${lib} || true
Filip Tehlar671cf512023-01-31 10:34:18 +010057rm -rf vpp-data/bin/* || true
58rm -rf vpp-data/lib/* || true
Filip Tehlar229f5fc2022-08-09 14:44:47 +000059
Filip Tehlar671cf512023-01-31 10:34:18 +010060cp ${VPP_BUILD_ROOT}/bin/* ${bin}
Maros Ondrejickaf643b6f2023-01-17 10:52:20 +010061res+=$?
Dave Wallace5eaa15d2024-06-18 17:10:07 -040062cp -r ${VPP_BUILD_ROOT}/lib/"${OS_ARCH}"-linux-gnu/* ${lib}
Maros Ondrejickaf643b6f2023-01-17 10:52:20 +010063res+=$?
64if [ $res -ne 0 ]; then
65 echo "Failed to copy VPP files. Is VPP built? Try running 'make build' in VPP directory."
66 exit 1
67fi
Filip Tehlar229f5fc2022-08-09 14:44:47 +000068
Filip Tehlar671cf512023-01-31 10:34:18 +010069docker_build () {
70 tag=$1
71 dockername=$2
Dave Wallacebee28af2024-06-14 14:59:38 -040072 set -x
Dave Wallace5eaa15d2024-06-18 17:10:07 -040073 # shellcheck disable=2086
74 docker buildx build ${DOCKER_CACHE_ARGS} \
75 --build-arg UBUNTU_VERSION \
76 --build-arg http_proxy="$HTTP_PROXY" \
77 --build-arg https_proxy="$HTTP_PROXY" \
78 --build-arg HTTP_PROXY="$HTTP_PROXY" \
79 --build-arg HTTPS_PROXY="$HTTP_PROXY" \
80 -t "$tag" -f docker/Dockerfile."$dockername" .
Dave Wallacebee28af2024-06-14 14:59:38 -040081 set +x
Filip Tehlar671cf512023-01-31 10:34:18 +010082}
83
84docker_build hs-test/vpp vpp
85docker_build hs-test/nginx-ldp nginx
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010086docker_build hs-test/nginx-server nginx-server
Filip Tehlar31eaea92023-06-15 10:06:57 +020087docker_build hs-test/build build
88if [ "$HST_EXTENDED_TESTS" = true ] ; then
89 docker_build hs-test/nginx-http3 nginx-http3
Matus Fabianb7a9ed72024-05-10 16:20:40 +020090 docker_build hs-test/curl curl
Filip Tehlar31eaea92023-06-15 10:06:57 +020091fi
Filip Tehlare08fdf32023-04-26 18:03:35 +020092
93# cleanup detached images
94images=$(docker images --filter "dangling=true" -q --no-trunc)
95if [ "$images" != "" ]; then
Dave Wallacebee28af2024-06-14 14:59:38 -040096 # shellcheck disable=SC2086
Filip Tehlare08fdf32023-04-26 18:03:35 +020097 docker rmi $images
98fi