Skip to content

Commit 15fd61f

Browse files
tonyxuqqiqi.xu
and
qi.xu
authored
add make docker_test to run tikv test in docker environment (tikv#14678)
close tikv#14677 Add a make option "make docker_test" to run test in docker. Also make necessary changes to enable running test in docker. Signed-off-by: qi.xu <[email protected]> Co-authored-by: qi.xu <[email protected]>
1 parent 5ce3a6b commit 15fd61f

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

CONTRIBUTING.md

+14
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ See the [style doc](https://github.com/rust-lang/fmt-rfcs/blob/master/guide/guid
9797

9898
Please follow this style to make TiKV easy to review, maintain, and develop.
9999

100+
### Run test in docker
101+
102+
Alternatively, you can run test in a docker environment. Simply running the following command, it will build the pingcap/tikv_dev image and run the tikv unittests. And you may re-use the pingcap/tikv_dev image directly for ad-hoc test.
103+
104+
```bash
105+
make docker_test
106+
```
107+
108+
Note that you may find many messages below, which in fact are not errors. They're emitted by rustc or cargo.
109+
110+
```bash
111+
<jemalloc>: Invalid conf pair: prof:true
112+
```
113+
100114
### Build issues
101115

102116
To reduce compilation time and disk usage, TiKV builds do not include full debugging information by default &mdash; only tests package will have line debug info enabled. To change debuginfo, just precede build commands with `RUSTFLAGS=-Cdebuginfo=1` (for line numbers), or `RUSTFLAGS=-Cdebuginfo=2` (for full debuginfo). For example,

Dockerfile.test

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# This Docker image contains a minimal build environment for TiKV
2+
#
3+
# It contains all the tools necessary to reproduce official production builds of TiKV
4+
5+
# We need to use CentOS 7 because many of our users choose this as their deploy machine.
6+
# Since the glibc it uses (2.17) is from 2012 (https://sourceware.org/glibc/wiki/Glibc%20Timeline)
7+
# it is our lowest common denominator in terms of distro support.
8+
9+
# Some commands in this script are structured in order to reduce the number of layers Docker
10+
# generates. Unfortunately Docker is limited to only 125 layers:
11+
# https://github.com/moby/moby/blob/a9507c6f76627fdc092edc542d5a7ef4a6df5eec/layer/layer.go#L50-L53
12+
13+
# We require epel packages, so enable the fedora EPEL repo then install dependencies.
14+
# Install the system dependencies
15+
# Attempt to clean and rebuild the cache to avoid 404s
16+
17+
# To avoid rebuilds we first install all Cargo dependencies
18+
19+
20+
# The prepare image avoid ruining the cache of the builder
21+
FROM centos:7.6.1810 as builder
22+
23+
RUN yum install -y epel-release && \
24+
yum clean all && \
25+
yum makecache
26+
27+
RUN yum install -y centos-release-scl && \
28+
yum install -y \
29+
devtoolset-8 \
30+
perl cmake3 && \
31+
yum clean all
32+
33+
# CentOS gives cmake 3 a weird binary name, so we link it to something more normal
34+
# This is required by many build scripts, including ours.
35+
RUN ln -s /usr/bin/cmake3 /usr/bin/cmake
36+
ENV LIBRARY_PATH /usr/local/lib:$LIBRARY_PATH
37+
ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
38+
39+
# Install protoc
40+
RUN curl -LO "https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip"
41+
RUN unzip protoc-3.15.8-linux-x86_64.zip -d /usr/local/
42+
ENV PATH /usr/local/bin/:$PATH
43+
44+
# Install Rustup
45+
RUN curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path --default-toolchain none -y
46+
ENV PATH /root/.cargo/bin/:$PATH
47+
48+
# Install the Rust toolchain
49+
WORKDIR /tikv
50+
COPY rust-toolchain ./
51+
RUN rustup self update \
52+
&& rustup set profile minimal \
53+
&& rustup default $(cat "rust-toolchain")
54+
55+
RUN cargo install cargo-nextest --locked
56+
57+
ENTRYPOINT ["sh", "-c", "source /opt/rh/devtoolset-8/enable && \"$@\"", "-s"]

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export TIKV_BUILD_GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2> /dev/
137137

138138
export DOCKER_IMAGE_NAME ?= "pingcap/tikv"
139139
export DOCKER_IMAGE_TAG ?= "latest"
140+
export DEV_DOCKER_IMAGE_NAME ?= "pingcap/tikv_dev"
140141

141142
# Turn on cargo pipelining to add more build parallelism. This has shown decent
142143
# speedups in TiKV.
@@ -396,6 +397,14 @@ docker:
396397
--build-arg GIT_BRANCH=${TIKV_BUILD_GIT_BRANCH} \
397398
.
398399

400+
docker_test:
401+
docker build -f Dockerfile.test \
402+
-t ${DEV_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} \
403+
.
404+
docker run -i -v $(shell pwd):/tikv \
405+
${DEV_DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} \
406+
make test
407+
399408
## The driver for script/run-cargo.sh
400409
## ----------------------------------
401410

scripts/test

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}:${LOCAL_DIR}/lib"
2828
export LOG_LEVEL=DEBUG
2929
export RUST_BACKTRACE=full
3030

31+
echo ${TIKV_ENABLE_FEATURES}
3132
cargo $CUSTOM_TEST_COMMAND --workspace \
3233
--exclude fuzz --exclude fuzzer-afl --exclude fuzzer-honggfuzz \
3334
--exclude fuzzer-libfuzzer --exclude fuzz-targets \

0 commit comments

Comments
 (0)