Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Dave Wallace | bee28af | 2024-06-14 14:59:38 -0400 | [diff] [blame] | 3 | if [ "$(lsb_release -is)" != Ubuntu ]; then |
Maros Ondrejicka | f643b6f | 2023-01-17 10:52:20 +0100 | [diff] [blame] | 4 | echo "Host stack test framework is supported only on Ubuntu" |
| 5 | exit 1 |
| 6 | fi |
| 7 | |
Adrian Villin | ea360b5 | 2024-12-12 15:30:15 +0100 | [diff] [blame^] | 8 | LAST_STATE_FILE=".last_state_hash" |
| 9 | |
| 10 | # get current state hash |
| 11 | current_state_hash=$(git status --porcelain | grep -vE '(/\.|/10|\.go$|\.sum$|\.mod$|\.txt$|\.test$)' | sha1sum | awk '{print $1}') |
| 12 | |
| 13 | if [ -f "$LAST_STATE_FILE" ]; then |
| 14 | last_state_hash=$(cat "$LAST_STATE_FILE") |
| 15 | else |
| 16 | last_state_hash="" |
| 17 | fi |
| 18 | |
| 19 | # compare current state with last state |
| 20 | if [ "$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 |
| 24 | fi |
| 25 | |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 26 | export VPP_WS=../.. |
Dave Wallace | 5eaa15d | 2024-06-18 17:10:07 -0400 | [diff] [blame] | 27 | OS_ARCH="$(uname -m)" |
| 28 | DOCKER_BUILD_DIR="/scratch/docker-build" |
| 29 | DOCKER_CACHE_DIR="${DOCKER_BUILD_DIR}/docker_cache" |
| 30 | |
| 31 | if [ -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}" |
| 40 | fi |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 41 | |
| 42 | if [ "$1" == "debug" ]; then |
| 43 | VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp_debug-native/vpp |
adrianvillin | 8512145 | 2024-01-11 11:59:47 +0100 | [diff] [blame] | 44 | elif [ "$1" == "gcov" ]; then |
| 45 | VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp_gcov-native/vpp |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 46 | else |
| 47 | VPP_BUILD_ROOT=${VPP_WS}/build-root/build-vpp-native/vpp |
| 48 | fi |
| 49 | echo "Taking build objects from ${VPP_BUILD_ROOT}" |
| 50 | |
Dave Wallace | bee28af | 2024-06-14 14:59:38 -0400 | [diff] [blame] | 51 | export UBUNTU_VERSION=${UBUNTU_VERSION:-"$(lsb_release -rs)"} |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 52 | echo "Ubuntu version is set to ${UBUNTU_VERSION}" |
| 53 | |
Dave Wallace | 5eaa15d | 2024-06-18 17:10:07 -0400 | [diff] [blame] | 54 | export HST_LDPRELOAD=${VPP_BUILD_ROOT}/lib/${OS_ARCH}-linux-gnu/libvcl_ldpreload.so |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 55 | echo "HST_LDPRELOAD is set to ${HST_LDPRELOAD}" |
| 56 | |
| 57 | export PATH=${VPP_BUILD_ROOT}/bin:$PATH |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 58 | |
| 59 | bin=vpp-data/bin |
| 60 | lib=vpp-data/lib |
| 61 | |
| 62 | mkdir -p ${bin} ${lib} || true |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 63 | rm -rf vpp-data/bin/* || true |
| 64 | rm -rf vpp-data/lib/* || true |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 65 | |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 66 | cp ${VPP_BUILD_ROOT}/bin/* ${bin} |
Maros Ondrejicka | f643b6f | 2023-01-17 10:52:20 +0100 | [diff] [blame] | 67 | res+=$? |
Dave Wallace | 5eaa15d | 2024-06-18 17:10:07 -0400 | [diff] [blame] | 68 | cp -r ${VPP_BUILD_ROOT}/lib/"${OS_ARCH}"-linux-gnu/* ${lib} |
Maros Ondrejicka | f643b6f | 2023-01-17 10:52:20 +0100 | [diff] [blame] | 69 | res+=$? |
| 70 | if [ $res -ne 0 ]; then |
| 71 | echo "Failed to copy VPP files. Is VPP built? Try running 'make build' in VPP directory." |
| 72 | exit 1 |
| 73 | fi |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 74 | |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 75 | docker_build () { |
| 76 | tag=$1 |
| 77 | dockername=$2 |
Adrian Villin | aedfd7c | 2024-07-17 15:03:42 +0200 | [diff] [blame] | 78 | set -ex |
Dave Wallace | 5eaa15d | 2024-06-18 17:10:07 -0400 | [diff] [blame] | 79 | # shellcheck disable=2086 |
| 80 | docker buildx build ${DOCKER_CACHE_ARGS} \ |
| 81 | --build-arg UBUNTU_VERSION \ |
Matus Fabian | c4b4cd5 | 2024-12-08 15:13:44 +0100 | [diff] [blame] | 82 | --build-arg OS_ARCH="$OS_ARCH" \ |
Dave Wallace | 5eaa15d | 2024-06-18 17:10:07 -0400 | [diff] [blame] | 83 | --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 Villin | aedfd7c | 2024-07-17 15:03:42 +0200 | [diff] [blame] | 88 | set +ex |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | docker_build hs-test/vpp vpp |
| 92 | docker_build hs-test/nginx-ldp nginx |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 93 | docker_build hs-test/nginx-server nginx-server |
Matus Fabian | 8792e5c | 2024-08-14 12:38:20 +0200 | [diff] [blame] | 94 | docker_build hs-test/curl curl |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 95 | docker_build hs-test/envoy envoy |
Adrian Villin | 7bae9b0 | 2024-10-02 15:07:40 +0200 | [diff] [blame] | 96 | docker_build hs-test/nginx-http3 nginx-http3 |
Matus Fabian | c4b4cd5 | 2024-12-08 15:13:44 +0100 | [diff] [blame] | 97 | docker_build hs-test/ab ab |
| 98 | docker_build hs-test/wrk wrk |
Filip Tehlar | e08fdf3 | 2023-04-26 18:03:35 +0200 | [diff] [blame] | 99 | |
| 100 | # cleanup detached images |
| 101 | images=$(docker images --filter "dangling=true" -q --no-trunc) |
| 102 | if [ "$images" != "" ]; then |
Dave Wallace | bee28af | 2024-06-14 14:59:38 -0400 | [diff] [blame] | 103 | # shellcheck disable=SC2086 |
Filip Tehlar | e08fdf3 | 2023-04-26 18:03:35 +0200 | [diff] [blame] | 104 | docker rmi $images |
| 105 | fi |
Adrian Villin | ea360b5 | 2024-12-12 15:30:15 +0100 | [diff] [blame^] | 106 | |
| 107 | echo "$current_state_hash" > "$LAST_STATE_FILE" |