2022-08-09 14:44:47 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-06-14 14:59:38 -04:00
|
|
|
if [ "$(lsb_release -is)" != Ubuntu ]; then
|
2023-01-17 10:52:20 +01:00
|
|
|
echo "Host stack test framework is supported only on Ubuntu"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-12-13 09:12:07 +01:00
|
|
|
export UBUNTU_VERSION=${UBUNTU_VERSION:-"$(lsb_release -rs)"}
|
|
|
|
echo "Ubuntu version is set to ${UBUNTU_VERSION}"
|
|
|
|
|
2024-12-12 15:30:15 +01:00
|
|
|
LAST_STATE_FILE=".last_state_hash"
|
|
|
|
|
2024-12-13 09:12:07 +01:00
|
|
|
# get current state hash and ubuntu version
|
2024-12-12 15:30:15 +01:00
|
|
|
current_state_hash=$(git status --porcelain | grep -vE '(/\.|/10|\.go$|\.sum$|\.mod$|\.txt$|\.test$)' | sha1sum | awk '{print $1}')
|
2024-12-13 09:12:07 +01:00
|
|
|
current_state_hash=$current_state_hash$UBUNTU_VERSION
|
2024-12-12 15:30:15 +01:00
|
|
|
|
|
|
|
if [ -f "$LAST_STATE_FILE" ]; then
|
|
|
|
last_state_hash=$(cat "$LAST_STATE_FILE")
|
|
|
|
else
|
|
|
|
last_state_hash=""
|
|
|
|
fi
|
|
|
|
|
2024-12-13 09:12:07 +01:00
|
|
|
# compare current state with last state and check FORCE_BUILD
|
|
|
|
if [ "$current_state_hash" = "$last_state_hash" ] && [ "$2" = "false" ]; then
|
2024-12-12 15:30:15 +01:00
|
|
|
echo "*** Skipping docker build - no new changes \
|
|
|
|
(excluding .go, .txt, .sum, .mod, dotfiles, IP address files) ***"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-01-31 10:34:18 +01:00
|
|
|
export VPP_WS=../..
|
2024-06-18 17:10:07 -04:00
|
|
|
OS_ARCH="$(uname -m)"
|
|
|
|
DOCKER_BUILD_DIR="/scratch/docker-build"
|
|
|
|
DOCKER_CACHE_DIR="${DOCKER_BUILD_DIR}/docker_cache"
|
|
|
|
|
|
|
|
if [ -d "${DOCKER_BUILD_DIR}" ] ; then
|
|
|
|
mkdir -p "${DOCKER_CACHE_DIR}"
|
|
|
|
DOCKER_HST_BUILDER="hst_builder"
|
|
|
|
set -x
|
|
|
|
if ! docker buildx ls --format "{{.Name}}" | grep -q "${DOCKER_HST_BUILDER}"; then
|
|
|
|
docker buildx create --name=${DOCKER_HST_BUILDER} --driver=docker-container --use --bootstrap || true
|
|
|
|
fi
|
|
|
|
set -x
|
|
|
|
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}"
|
|
|
|
fi
|
2023-01-31 10:34:18 +01:00
|
|
|
|
|
|
|
if [ "$1" == "debug" ]; then
|
|
|
|
VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp_debug-native/vpp
|
2024-01-11 11:59:47 +01:00
|
|
|
elif [ "$1" == "gcov" ]; then
|
|
|
|
VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp_gcov-native/vpp
|
2023-01-31 10:34:18 +01:00
|
|
|
else
|
|
|
|
VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp-native/vpp
|
|
|
|
fi
|
|
|
|
echo "Taking build objects from ${VPP_BUILD_ROOT}"
|
|
|
|
|
2024-06-18 17:10:07 -04:00
|
|
|
export HST_LDPRELOAD=${VPP_BUILD_ROOT}/lib/${OS_ARCH}-linux-gnu/libvcl_ldpreload.so
|
2023-01-31 10:34:18 +01:00
|
|
|
echo "HST_LDPRELOAD is set to ${HST_LDPRELOAD}"
|
|
|
|
|
|
|
|
export PATH=${VPP_BUILD_ROOT}/bin:$PATH
|
2022-08-09 14:44:47 +00:00
|
|
|
|
|
|
|
bin=vpp-data/bin
|
|
|
|
lib=vpp-data/lib
|
|
|
|
|
|
|
|
mkdir -p ${bin} ${lib} || true
|
2023-01-31 10:34:18 +01:00
|
|
|
rm -rf vpp-data/bin/* || true
|
|
|
|
rm -rf vpp-data/lib/* || true
|
2022-08-09 14:44:47 +00:00
|
|
|
|
2023-01-31 10:34:18 +01:00
|
|
|
cp ${VPP_BUILD_ROOT}/bin/* ${bin}
|
2023-01-17 10:52:20 +01:00
|
|
|
res+=$?
|
2024-06-18 17:10:07 -04:00
|
|
|
cp -r ${VPP_BUILD_ROOT}/lib/"${OS_ARCH}"-linux-gnu/* ${lib}
|
2023-01-17 10:52:20 +01:00
|
|
|
res+=$?
|
|
|
|
if [ $res -ne 0 ]; then
|
|
|
|
echo "Failed to copy VPP files. Is VPP built? Try running 'make build' in VPP directory."
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-08-09 14:44:47 +00:00
|
|
|
|
2023-01-31 10:34:18 +01:00
|
|
|
docker_build () {
|
|
|
|
tag=$1
|
|
|
|
dockername=$2
|
2024-07-17 15:03:42 +02:00
|
|
|
set -ex
|
2024-06-18 17:10:07 -04:00
|
|
|
# shellcheck disable=2086
|
|
|
|
docker buildx build ${DOCKER_CACHE_ARGS} \
|
|
|
|
--build-arg UBUNTU_VERSION \
|
2024-12-08 15:13:44 +01:00
|
|
|
--build-arg OS_ARCH="$OS_ARCH" \
|
2024-06-18 17:10:07 -04:00
|
|
|
--build-arg http_proxy="$HTTP_PROXY" \
|
|
|
|
--build-arg https_proxy="$HTTP_PROXY" \
|
|
|
|
--build-arg HTTP_PROXY="$HTTP_PROXY" \
|
|
|
|
--build-arg HTTPS_PROXY="$HTTP_PROXY" \
|
|
|
|
-t "$tag" -f docker/Dockerfile."$dockername" .
|
2024-07-17 15:03:42 +02:00
|
|
|
set +ex
|
2023-01-31 10:34:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
docker_build hs-test/vpp vpp
|
|
|
|
docker_build hs-test/nginx-ldp nginx
|
2023-02-27 13:22:45 +01:00
|
|
|
docker_build hs-test/nginx-server nginx-server
|
2024-08-14 12:38:20 +02:00
|
|
|
docker_build hs-test/curl curl
|
2024-09-19 17:19:39 +02:00
|
|
|
docker_build hs-test/envoy envoy
|
2024-10-02 15:07:40 +02:00
|
|
|
docker_build hs-test/nginx-http3 nginx-http3
|
2024-12-08 15:13:44 +01:00
|
|
|
docker_build hs-test/ab ab
|
|
|
|
docker_build hs-test/wrk wrk
|
2023-04-26 18:03:35 +02:00
|
|
|
|
|
|
|
# cleanup detached images
|
|
|
|
images=$(docker images --filter "dangling=true" -q --no-trunc)
|
|
|
|
if [ "$images" != "" ]; then
|
2024-06-14 14:59:38 -04:00
|
|
|
# shellcheck disable=SC2086
|
2023-04-26 18:03:35 +02:00
|
|
|
docker rmi $images
|
|
|
|
fi
|
2024-12-12 15:30:15 +01:00
|
|
|
|
|
|
|
echo "$current_state_hash" > "$LAST_STATE_FILE"
|