Skip to content

Apache DataFusion SQL Query Engine

ARROW-7136: [Rust] Added caching to the docker image

Krisztián Szűcsf1f2df026e9b
diff --git a/.dockerignore b/.dockerignore
index d76d1c56b9..083905c743 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -48,3 +48,13 @@
!ruby/red-plasma/Gemfile
!ruby/red-plasma/lib/plasma/version.rb
!ruby/red-plasma/red-plasma.gemspec
+!rust/Cargo.toml
+!rust/benchmarks/Cargo.toml
+!rust/arrow/Cargo.toml
+!rust/arrow/benches
+!rust/arrow-flight/Cargo.toml
+!rust/parquet/Cargo.toml
+!rust/parquet/build.rs
+!rust/datafusion/Cargo.toml
+!rust/datafusion/benches
+!rust/integration-testing/Cargo.toml
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 15c5e44cfd..89724a0a41 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -64,6 +64,12 @@ jobs:
- name: Free Up Disk Space
shell: bash
run: ci/scripts/util_cleanup.sh
+ - name: Cache Docker Volumes
+ uses: actions/cache@v1
+ with:
+ path: .docker
+ key: debian-10-rust-${{ hashFiles('rust/**.rs') }}
+ restore-keys: debian-10-rust-
- name: Setup Python
uses: actions/setup-python@v1
with:
@@ -75,6 +81,8 @@ jobs:
sudo sysctl -w kernel.core_pattern="core.%e.%p"
ulimit -c unlimited
archery docker run debian-rust
+ - name: Fix Cache Permissions
+ run: sudo chmod -R o+r .docker
- name: Docker Push
if: success() && github.event_name == 'push' && github.repository == 'apache/arrow'
continue-on-error: true
@@ -106,6 +114,12 @@ jobs:
- name: Fetch Submodules and Tags
shell: bash
run: ci/scripts/util_checkout.sh
+ - name: Cache Build Artifacts
+ uses: actions/cache@v1
+ with:
+ path: rust/target
+ key: windows-rust-${{ hashFiles('rust/**.rs') }}
+ restore-keys: windows-rust-
- name: Build
shell: bash
run: ci/scripts/rust_build.sh $(pwd) $(pwd)/build
@@ -138,6 +152,12 @@ jobs:
- name: Fetch Submodules and Tags
shell: bash
run: ci/scripts/util_checkout.sh
+ - name: Cache Build Artifacts
+ uses: actions/cache@v1
+ with:
+ path: rust/target
+ key: macos-10-rust-${{ hashFiles('rust/**.rs') }}
+ restore-keys: macos-10-rust-
- name: Run Clippy
shell: bash
run: ci/scripts/rust_lint.sh $(pwd)
diff --git a/ci/docker/debian-10-rust.dockerfile b/ci/docker/debian-10-rust.dockerfile
index 44f012319f..b23b03c9a1 100644
--- a/ci/docker/debian-10-rust.dockerfile
+++ b/ci/docker/debian-10-rust.dockerfile
@@ -29,17 +29,43 @@ ARG flatbuffers=1.11.0
RUN wget -q -O - https://github.com/google/flatbuffers/archive/v${flatbuffers}.tar.gz | tar -xzf - && \
cd flatbuffers-${flatbuffers} && \
cmake -G "Unix Makefiles" && \
- make install && \
+ make install -j4 && \
cd / && \
rm -rf flatbuffers-${flatbuffers}
-# sadly cargo doesn't have a command to fetch and build the
-# dependencies without building the library itself
ARG rust=nightly-2020-04-22
-RUN rustup default ${rust}
-RUN rustup component add rustfmt --toolchain ${rust}-x86_64-unknown-linux-gnu
-# TODO(kszucs):
-# 1. add the files required to install the dependencies to .dockerignore
-# 2. copy these files to their appropriate path
-# 3. download and compile the dependencies
+# freeze the version for deterministic builds
+RUN rustup default ${rust} && \
+ rustup component add rustfmt --toolchain ${rust}-x86_64-unknown-linux-gnu
+
+# Compile a dummy program, so that the dependencies are compiled and cached on a layer
+# see https://stackoverflow.com/a/58474618/931303 for details
+# We do not compile any of the workspace or we defeat the purpose of caching - we only
+# compile their external dependencies.
+
+ENV CARGO_HOME="/rust/cargo" \
+ CARGO_TARGET_DIR="/rust/target" \
+ RUSTFLAGS="-D warnings"
+
+# The artifact of the steps below is a "${CARGO_TARGET_DIR}" containing
+# compiled dependencies. Create the directories and place an empty lib.rs
+# files.
+COPY rust /arrow/rust
+RUN mkdir \
+ /arrow/rust/arrow-flight/src \
+ /arrow/rust/arrow/src \
+ /arrow/rust/benchmarks/src \
+ /arrow/rust/datafusion/src \
+ /arrow/rust/integration-testing/src \
+ /arrow/rust/parquet/src && \
+ touch \
+ /arrow/rust/arrow-flight/src/lib.rs \
+ /arrow/rust/arrow/src/lib.rs \
+ /arrow/rust/benchmarks/src/lib.rs \
+ /arrow/rust/datafusion/src/lib.rs \
+ /arrow/rust/integration-testing/src/lib.rs \
+ /arrow/rust/parquet/src/lib.rs
+
+# Compile dependencies for the whole workspace
+RUN cd /arrow/rust && cargo build --workspace --lib --all-features
diff --git a/ci/scripts/rust_build.sh b/ci/scripts/rust_build.sh
index 7bbef28760..bdea5e44f6 100755
--- a/ci/scripts/rust_build.sh
+++ b/ci/scripts/rust_build.sh
@@ -23,7 +23,6 @@ source_dir=${1}/rust
export ARROW_TEST_DATA=${arrow_dir}/testing/data
export PARQUET_TEST_DATA=${arrow_dir}/cpp/submodules/parquet-testing/data
-export RUSTFLAGS="-D warnings"
# show activated toolchain
rustup show
diff --git a/ci/scripts/rust_test.sh b/ci/scripts/rust_test.sh
index 8fcb453384..254ea43d29 100755
--- a/ci/scripts/rust_test.sh
+++ b/ci/scripts/rust_test.sh
@@ -21,12 +21,9 @@ set -ex
arrow_dir=${1}
source_dir=${1}/rust
-build_dir=${2}/rust
export ARROW_TEST_DATA=${arrow_dir}/testing/data
export PARQUET_TEST_DATA=${arrow_dir}/cpp/submodules/parquet-testing/data
-export CARGO_TARGET_DIR=${build_dir}
-export RUSTFLAGS="-D warnings"
pushd ${source_dir}
diff --git a/docker-compose.yml b/docker-compose.yml
index 1828adf9f8..82e06d7c3e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -941,11 +941,15 @@ services:
rust: ${RUST}
shm_size: *shm-size
environment:
- CARGO_HOME: /build/cargo
- volumes: *debian-volumes
+ CARGO_HOME: /rust/cargo
+ CARGO_TARGET_DIR: /build/rust
+ volumes: &rust-volumes
+ - .:/arrow:delegated
+ - ${DOCKER_VOLUME_DIRECTORY:-.docker}/${ARCH}-debian-${DEBIAN}-rust:/build:delegated
command: &rust-command >
/bin/bash -c "
echo ${RUST} > /arrow/rust/rust-toolchain &&
+ if [ ! -d "/build/rust" ]; then mv /rust/target /build/rust; fi &&
/arrow/ci/scripts/rust_build.sh /arrow /build &&
/arrow/ci/scripts/rust_test.sh /arrow /build"