Skip to content

Commit 3caf6c1

Browse files
authored
KAFKA-20379 ducker-ak has no option to skip the gradlew systemTestLibs build step (#22034)
This PR adds an option to skip the gradle build while running system tests. #### Why Add --skip-build support to ducker-ak test. Currently when someone wants to skip the build it (e.g., it is already builded in the CI) it cannot be skip because: https://github.com/apache/kafka/blob/acd37fc30c5fdbbae772144c73b4f2c7e1c21d27/tests/docker/ducker-ak#L607 is always called in the `ducker_test` method in the script. #### Tested 1. SKIP_BUILD=true ./tests/docker/ducker-ak test ./tests/kafkatest/tests/core/produce_bench_test.py => build is skipped 2. ./tests/docker/ducker-ak test ./tests/kafkatest/tests/core/produce_bench_test.py => build is NOT skipped 3. ./tests/docker/ducker-ak test --skip-build ./tests/kafkatest/tests/core/produce_bench_test.py => build is skipped 4. SKIP_BUILD=true ./tests/docker/run_tests.sh => build is skipped 5. ./tests/docker/run_tests.sh => build is NOT skipped 6. ... (more) Again as previous `--memory` option, `--skip-build` option has same priority (i.e., CLI > ENV > default option). Reviewers: Federico Valeri <fedevaleri@gmail.com>, Chia-Ping Tsai <chia7712@gmail.com>
1 parent ef5c8dc commit 3caf6c1

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

tests/docker/ducker-ak

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Usage: ${script_path} [command] [options]
7777
help|-h|--help
7878
Display this help message
7979
80-
up [-n|--num-nodes NUM_NODES] [-f|--force] [docker-image]
80+
up [-n|--num-nodes NUM_NODES] [-f|--force] [-c|--clean-build] [docker-image]
8181
[-C|--custom-ducktape DIR] [-e|--expose-ports ports] [-j|--jdk JDK_VERSION] [--ipv6]
8282
[--memory MEMORY_LIMIT]
8383
Bring up a cluster with the specified amount of nodes (defaults to ${default_num_nodes}).
@@ -102,17 +102,30 @@ up [-n|--num-nodes NUM_NODES] [-f|--force] [docker-image]
102102
Defaults to ${default_docker_run_memory_limit}. Can also be set via the DUCKER_RUN_MEMORY
103103
environment variable. The --memory flag takes precedence over the environment variable.
104104
105+
If -c|--clean-build is passed, a clean rebuild of the native image tarball (releaseTarGz) is
106+
forced during prepare_native_dir, even if the tarball already exists. Can also be triggered via
107+
the CLEAN_BUILD environment variable (e.g., CLEAN_BUILD=true).
108+
105109
Note that port 5678 will be automatically exposed for ducker01 node and will be mapped to 5678
106110
on your local machine to enable debugging in VS Code.
107111
108-
test [-d|--debug] [test-name(s)] [-- [ducktape args]]
112+
test [-d|--debug] [-s|--skip-build] [-c|--clean-build] [test-name(s)] [-- [ducktape args]]
109113
Run a test or set of tests inside the currently active Ducker nodes.
110114
For example, to run the system test produce_bench_test, you would run:
111115
./tests/docker/ducker-ak test ./tests/kafkatest/tests/core/produce_bench_test.py
112116
113117
If --debug is passed, the tests will wait for remote VS Code debugger to connect on port 5678:
114118
./tests/docker/ducker-ak test --debug ./tests/kafkatest/tests/core/produce_bench_test.py
115119
120+
If -s|--skip-build is passed, the gradle build step (gradlew systemTestLibs) will be skipped.
121+
This is useful when test artifacts are already built (e.g., in CI). Can also be set via the
122+
SKIP_BUILD environment variable (e.g., SKIP_BUILD=true).
123+
124+
If -c|--clean-build is passed, a clean rebuild of system test libraries is performed
125+
(gradlew clean systemTestLibs). This only rebuilds test libraries, not the native image
126+
tarball (releaseTarGz), which is handled by 'ducker-ak up --clean-build'.
127+
Can also be triggered via the CLEAN_BUILD environment variable (e.g., CLEAN_BUILD=true).
128+
116129
To pass arguments to underlying ducktape invocation, pass them after `--`, e.g.:
117130
./tests/docker/ducker-ak test ./tests/kafkatest/tests/core/produce_bench_test.py -- --test-runner-timeout 1800000
118131
@@ -379,8 +392,8 @@ prepare_native_dir() {
379392

380393
if [ "$kafka_mode" == "native" ]; then
381394
kafka_tarball_filename=(core/build/distributions/kafka*SNAPSHOT.tgz)
382-
if [ ! -e "${kafka_tarball_filename[0]}" ]; then
383-
echo "Kafka tarball not present. Building Kafka tarball for native image."
395+
if [[ "${clean_build}" == "true" ]] || [ ! -e "${kafka_tarball_filename[0]}" ]; then
396+
echo "Kafka tarball not present or clean build requested. Building Kafka tarball for native image."
384397
./gradlew clean releaseTarGz
385398
fi
386399

@@ -401,12 +414,14 @@ ducker_up() {
401414
-n|--num-nodes) set_once num_nodes "${2}" "number of nodes"; shift 2;;
402415
-j|--jdk) set_once jdk_version "${2}" "the OpenJDK base image"; shift 2;;
403416
-e|--expose-ports) set_once expose_ports "${2}" "the ports to expose"; shift 2;;
417+
-c|--clean-build) set_once clean_build "true" "clean build"; shift;;
404418
-m|--kafka_mode) set_once kafka_mode "${2}" "the mode in which kafka will run"; shift 2;;
405419
--memory) set_once docker_run_memory_limit "${2}" "the container memory limit"; shift 2;;
406420
--ipv6) set_once ipv6 "true" "enable IPv6"; shift;;
407421
*) set_once image_name "${1}" "container image name"; shift;;
408422
esac
409423
done
424+
[[ -n "${clean_build}" ]] || clean_build="${CLEAN_BUILD:-}"
410425
[[ -n "${num_nodes}" ]] || num_nodes="${default_num_nodes}"
411426
[[ -n "${jdk_version}" ]] || jdk_version="${default_jdk}"
412427
[[ -n "${kafka_mode}" ]] || kafka_mode="${default_kafka_mode}"
@@ -580,9 +595,13 @@ ducker_test() {
580595
die "ducker_test: the ducker01 instance appears to be down. Did you run 'ducker up'?"
581596
declare -a test_name_args=()
582597
local debug=0
598+
local skip_build="${SKIP_BUILD:-}"
599+
local clean_build="${CLEAN_BUILD:-}"
583600
while [[ $# -ge 1 ]]; do
584601
case "${1}" in
585602
-d|--debug) debug=1; shift;;
603+
-s|--skip-build) skip_build=true; shift;;
604+
-c|--clean-build) clean_build=true; shift;;
586605
--) shift; break;;
587606
*) test_name_args+=("${1}"); shift;;
588607
esac
@@ -603,9 +622,17 @@ ducker_test() {
603622
fi
604623
done
605624

606-
must_pushd "${kafka_dir}"
607-
( (test -f ./gradlew || gradle) && ./gradlew systemTestLibs ) || die "ducker_test: Failed to build system test libraries, please check the error log."
608-
must_popd
625+
if [[ "${skip_build}" == "true" ]]; then
626+
echo "ducker_test: skipping gradle build (--skip-build or SKIP_BUILD is set)."
627+
elif [[ "${clean_build}" == "true" ]]; then
628+
must_pushd "${kafka_dir}"
629+
( (test -f ./gradlew || gradle) && ./gradlew clean systemTestLibs ) || die "ducker_test: Failed to build system test libraries, please check the error log."
630+
must_popd
631+
else
632+
must_pushd "${kafka_dir}"
633+
( (test -f ./gradlew || gradle) && ./gradlew systemTestLibs ) || die "ducker_test: Failed to build system test libraries, please check the error log."
634+
must_popd
635+
fi
609636
if [[ "${debug}" -eq 1 ]]; then
610637
local ducktape_cmd="python3 -m debugpy --listen 0.0.0.0:${debugpy_port} --wait-for-client /usr/local/bin/ducktape"
611638
else

tests/docker/run_tests.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1919
KAFKA_NUM_CONTAINERS=${KAFKA_NUM_CONTAINERS:-14}
2020
TC_PATHS=${TC_PATHS:-./kafkatest/}
21-
REBUILD=${REBUILD:f}
21+
REBUILD=${REBUILD:-f}
2222

2323
# Auto-detect container runtime if not set
2424
if [[ -z "${CONTAINER_RUNTIME}" ]]; then
@@ -41,10 +41,7 @@ else
4141
fi
4242

4343
if [ "$REBUILD" == "t" ]; then
44-
./gradlew clean systemTestLibs
45-
if [ "$KAFKA_MODE" == "native" ]; then
46-
./gradlew clean releaseTarGz
47-
fi
44+
export CLEAN_BUILD=true
4845
fi
4946

5047
if ${SCRIPT_DIR}/ducker-ak ssh | grep -q '(none)'; then

0 commit comments

Comments
 (0)