Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 49 additions & 5 deletions Dockerfile.unit
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ RUN INSTALL_PKGS=" \
libtool \
python3.11 \
" && \
dnf install -y $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS || \
dnf install -y --setopt=tsflags=nodocs --nobest $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS || true && \
dnf clean all && \
ln -s /usr/bin/python3.11 /usr/bin/python

Expand All @@ -26,9 +27,39 @@ ENV CARGO_HOME=$HOME/.cargo
ENV PATH=$CARGO_HOME/bin:$PATH

RUN mkdir -p /src

WORKDIR /src
COPY . /src

# Copy files needed for compilation (excluding large unnecessary directories)
# This list matches what's needed for unit tests only

# Essential build files
COPY Makefile Cargo.toml Cargo.lock rust-toolchain.toml build.rs deny.toml ./
COPY .cargo .cargo

# Source code (required)
COPY src src
COPY lib lib
COPY vdev vdev

# Build dependencies
COPY proto proto
COPY patch patch
COPY thirdparty thirdparty

# Test files (required for unit tests)
COPY tests tests

# Benchmark files (needed for Cargo.toml validation even with --tests)
COPY benches benches

# NOT copying:
# - .vscode/ - editor config
# - website/ - documentation website
# - docs/ - documentation source
# - distribution/ - packaging files
# - scripts/ - helper scripts not needed for tests
# - rfcs/ - design documents
# - regression/ - regression test data

# Initialize git repository for build scripts that need git metadata
RUN cd /src && \
Expand All @@ -43,9 +74,22 @@ RUN chmod +x /src/thirdparty/protoc/protoc-linux-x86_64
ENV PROTOC=/src/thirdparty/protoc/protoc-linux-x86_64
ENV PATH=/src/thirdparty/protoc:$PATH

RUN mkdir -p $CARGO_HOME && chmod -R 777 /src $CARGO_HOME $HOME
RUN mkdir -p $CARGO_HOME
RUN mkdir -p ~/.cargo/bin && \
for plugin in nextest deny; do \
ln -s /src/thirdparty/cargo-${plugin}/cargo-${plugin}-linux-x86_64 ~/.cargo/bin/cargo-${plugin}; \
done

# Download all dependencies (cached unless Cargo.lock changes)
RUN cargo fetch --locked

# Build all test binaries (cached unless source changes)
RUN cargo build --workspace --tests --no-default-features --features "ocp-logging"

# Pre-compile nextest test binaries to avoid recompilation when running tests
# This ensures 'make test' doesn't need to rebuild anything
RUN cargo nextest run --no-run --workspace --no-default-features --features "ocp-logging"

# Fix permissions for CI environments that run as non-root user
# Must be done AFTER all builds to ensure target directory is accessible
RUN chmod -R 777 /src $CARGO_HOME $HOME