blob: 96a7214d705ead7b9d76daf1f4587b2dbad3d2d7 [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
Adrian Villinea360b52024-12-12 15:30:15 +01008LAST_STATE_FILE=".last_state_hash"
9
10# get current state hash
11current_state_hash=$(git status --porcelain | grep -vE '(/\.|/10|\.go$|\.sum$|\.mod$|\.txt$|\.test$)' | sha1sum | awk '{print $1}')
12
13if [ -f "$LAST_STATE_FILE" ]; then
14 last_state_hash=$(cat "$LAST_STATE_FILE")
15else
16 last_state_hash=""
17fi
18
19# compare current state with last state
20if [ "$current_state_hash" = "$last_state_hash" ]; then
21 echo "*** Skipping docker build - no new changes \
22(excluding .go, .txt, .sum, .mod, dotfiles, IP address files) ***"
23 exit 0
24fi
25
Filip Tehlar671cf512023-01-31 10:34:18 +010026export VPP_WS=../..
Dave Wallace5eaa15d2024-06-18 17:10:07 -040027OS_ARCH="$(uname -m)"
28DOCKER_BUILD_DIR="/scratch/docker-build"
29DOCKER_CACHE_DIR="${DOCKER_BUILD_DIR}/docker_cache"
30
31if [ -d "${DOCKER_BUILD_DIR}" ] ; then
32 mkdir -p "${DOCKER_CACHE_DIR}"
33 DOCKER_HST_BUILDER="hst_builder"
34 set -x
35 if ! docker buildx ls --format "{{.Name}}" | grep -q "${DOCKER_HST_BUILDER}"; then
36 docker buildx create --name=${DOCKER_HST_BUILDER} --driver=docker-container --use --bootstrap || true
37 fi
38 set -x
39 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}"
40fi
Filip Tehlar671cf512023-01-31 10:34:18 +010041
42if [ "$1" == "debug" ]; then
43 VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp_debug-native/vpp
adrianvillin85121452024-01-11 11:59:47 +010044elif [ "$1" == "gcov" ]; then
45 VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp_gcov-native/vpp
Filip Tehlar671cf512023-01-31 10:34:18 +010046else
47 VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp-native/vpp
48fi
49echo "Taking build objects from ${VPP_BUILD_ROOT}"
50
Dave Wallacebee28af2024-06-14 14:59:38 -040051export UBUNTU_VERSION=${UBUNTU_VERSION:-"$(lsb_release -rs)"}
Filip Tehlar671cf512023-01-31 10:34:18 +010052echo "Ubuntu version is set to ${UBUNTU_VERSION}"
53
Dave Wallace5eaa15d2024-06-18 17:10:07 -040054export HST_LDPRELOAD=${VPP_BUILD_ROOT}/lib/${OS_ARCH}-linux-gnu/libvcl_ldpreload.so
Filip Tehlar671cf512023-01-31 10:34:18 +010055echo "HST_LDPRELOAD is set to ${HST_LDPRELOAD}"
56
57export PATH=${VPP_BUILD_ROOT}/bin:$PATH
Filip Tehlar229f5fc2022-08-09 14:44:47 +000058
59bin=vpp-data/bin
60lib=vpp-data/lib
61
62mkdir -p ${bin} ${lib} || true
Filip Tehlar671cf512023-01-31 10:34:18 +010063rm -rf vpp-data/bin/* || true
64rm -rf vpp-data/lib/* || true
Filip Tehlar229f5fc2022-08-09 14:44:47 +000065
Filip Tehlar671cf512023-01-31 10:34:18 +010066cp ${VPP_BUILD_ROOT}/bin/* ${bin}
Maros Ondrejickaf643b6f2023-01-17 10:52:20 +010067res+=$?
Dave Wallace5eaa15d2024-06-18 17:10:07 -040068cp -r ${VPP_BUILD_ROOT}/lib/"${OS_ARCH}"-linux-gnu/* ${lib}
Maros Ondrejickaf643b6f2023-01-17 10:52:20 +010069res+=$?
70if [ $res -ne 0 ]; then
71 echo "Failed to copy VPP files. Is VPP built? Try running 'make build' in VPP directory."
72 exit 1
73fi
Filip Tehlar229f5fc2022-08-09 14:44:47 +000074
Filip Tehlar671cf512023-01-31 10:34:18 +010075docker_build () {
76 tag=$1
77 dockername=$2
Adrian Villinaedfd7c2024-07-17 15:03:42 +020078 set -ex
Dave Wallace5eaa15d2024-06-18 17:10:07 -040079 # shellcheck disable=2086
80 docker buildx build ${DOCKER_CACHE_ARGS} \
81 --build-arg UBUNTU_VERSION \
Matus Fabianc4b4cd52024-12-08 15:13:44 +010082 --build-arg OS_ARCH="$OS_ARCH" \
Dave Wallace5eaa15d2024-06-18 17:10:07 -040083 --build-arg http_proxy="$HTTP_PROXY" \
84 --build-arg https_proxy="$HTTP_PROXY" \
85 --build-arg HTTP_PROXY="$HTTP_PROXY" \
86 --build-arg HTTPS_PROXY="$HTTP_PROXY" \
87 -t "$tag" -f docker/Dockerfile."$dockername" .
Adrian Villinaedfd7c2024-07-17 15:03:42 +020088 set +ex
Filip Tehlar671cf512023-01-31 10:34:18 +010089}
90
91docker_build hs-test/vpp vpp
92docker_build hs-test/nginx-ldp nginx
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010093docker_build hs-test/nginx-server nginx-server
Matus Fabian8792e5c2024-08-14 12:38:20 +020094docker_build hs-test/curl curl
Adrian Villin46ab0b22024-09-19 17:19:39 +020095docker_build hs-test/envoy envoy
Adrian Villin7bae9b02024-10-02 15:07:40 +020096docker_build hs-test/nginx-http3 nginx-http3
Matus Fabianc4b4cd52024-12-08 15:13:44 +010097docker_build hs-test/ab ab
98docker_build hs-test/wrk wrk
Filip Tehlare08fdf32023-04-26 18:03:35 +020099
100# cleanup detached images
101images=$(docker images --filter "dangling=true" -q --no-trunc)
102if [ "$images" != "" ]; then
Dave Wallacebee28af2024-06-14 14:59:38 -0400103 # shellcheck disable=SC2086
Filip Tehlare08fdf32023-04-26 18:03:35 +0200104 docker rmi $images
105fi
Adrian Villinea360b52024-12-12 15:30:15 +0100106
107echo "$current_state_hash" > "$LAST_STATE_FILE"