Skip to content

Commit 120e3a9

Browse files
committed
test: dockerized: do not mount anything to containers
Running dockerized tests caused creation of root-owned `.cargo_home` directory on host. Similar problem occurred when mounting cargo registry directory. This commit alters the mechanism of action of dockerized tests. Instead of mounting source directory to container and running `cargo test` there, source files are copied to the testing image during `docker build` phase. This phase is now performed on each `test/dockerized/run.sh' invocation, with newly built images replacing old ones. The built images cache crates.io index and downloaded crates, enabling faster testing.
1 parent 4b3ceea commit 120e3a9

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git
2+
target/

test/dockerized/Dockerfile

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
FROM rust:slim
2-
RUN apt-get update && apt-get install -y pkg-config libssl-dev
2+
3+
RUN apt-get update && apt-get install -y pkg-config libssl-dev git
4+
5+
# Cache dependencies & crates.io index by invoking cargo fetch on freshly cloned repository
6+
WORKDIR /tmp/driver
7+
RUN git clone --depth 1 https://github.com/scylladb/scylla-rust-driver /tmp/driver
8+
RUN cargo fetch
9+
RUN rm -rf /tmp/driver
10+
11+
WORKDIR /driver
12+
COPY . .

test/dockerized/run.sh

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
#!/usr/bin/env bash
22

3-
cd "$(dirname "$0")"
3+
cd "$(dirname "$0")"/../../
44

55
if [[ -z $(docker container ls | grep cluster_scylla) ]]; then
66
echo "Scylla container must be running to execute tests (use 'make up')."
77
exit 1
88
fi
99

10-
if ! [[ $(docker image ls -q scylla_rust_driver_testing) ]]; then
11-
docker build -t scylla_rust_driver_testing .
12-
fi
10+
IMAGE_NAME="scylla_rust_driver_testing"
1311

14-
if [ -z "$CARGO_HOME" ]; then
15-
CARGO_REGISTRY=$HOME/.cargo/registry
12+
# Build a new image with embeded driver source files and deletes the
13+
# previously built image
14+
docker tag "$IMAGE_NAME:latest" "$IMAGE_NAME:previous" &>/dev/null
15+
if docker build -f test/dockerized/Dockerfile -t "$IMAGE_NAME:latest" . ; then
16+
docker rmi "$IMAGE_NAME:previous" &>/dev/null
1617
else
17-
CARGO_REGISTRY=$CARGO_HOME/registry
18+
docker tag "$IMAGE_NAME:previous" "$IMAGE_NAME:latest" &>/dev/null
1819
fi
1920

2021
docker run --name "scylla-rust-driver-testing" \
2122
--network scylla_rust_driver_public \
22-
-v "$(pwd)/../..:/scylla_driver:Z" \
23-
-v "$CARGO_REGISTRY:/usr/local/cargo/registry:z" \
2423
-it --rm \
25-
--env CARGO_HOME=/scylla_driver/.cargo_home \
2624
--env SCYLLA_URI=172.42.0.2:9042 \
2725
--env SCYLLA_URI2=172.42.0.3:9042 \
2826
--env SCYLLA_URI3=172.42.0.4:9042 \
29-
-w /scylla_driver \
30-
scylla_rust_driver_testing \
27+
"$IMAGE_NAME:latest" \
3128
cargo test

0 commit comments

Comments
 (0)