FROM rust:1.95 AS builder
WORKDIR /git
# Copy manifest to leverage Docker layer caching when dependencies exist
COPY Cargo.toml .
# Copy the rest of the source code
COPY . .
# Build the static library from source
RUN cargo build --release
FROM debian:stable-slim AS runtime
# Install minimal runtime dependencies (none required for a staticlib, but include a small toolset for debugging if needed)
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /git
# Copy the static library from the builder stage
COPY --from=builder /git/target/release/libgitcore.a /usr/local/lib/libgitcore.a
# Default to an interactive shell so the container can be used as a library package
CMD ["/bin/bash"]
# Ignore VCS and build artifacts to speed up Docker build .git .target .github/ Documentation/ po/ *.log *.tmp *.swp *.bak
Concerns: Assumes the Rust crate is configured to build a static library (crate-type = ["staticlib"]). If Cargo.toml does not specify staticlib, cargo build may produce a rlib or dynamic lib, causing the COPY step to fail., The runtime image contains only a static library and no runnable binary or headers, which means there is no straightforward end-to-end functional test other than inspecting the library artifact (e.g., using nm/ar). This makes smoke testing less comprehensive for real-world usage., The final image lacks build tools or a sample consumer (headers or an example FFI integration). If consumers expect headers or a small example to verify integration, those are currently absent. Smoke [FAIL]: sh -c 'set -e; if command -v nm >/dev/null 2>&1; then echo SYMBOLS_FIRST_5_IN_LIB; nm -g /usr/local/lib/libgitcore.a | head -n 5; else echo NM_MISSING; fi Output: sh: 1: Syntax error: Unterminated quoted string Smoke [FAIL]: sh -c 'set -e; if command -v ar >/dev/null 2>&1; then echo ARCHIVE_MEMBERS_FIRST_5; ar -t /usr/local/lib/libgitcore.a | head -n 5; else echo AR_MISSING; fi Output: sh: 1: Syntax error: Unterminated quoted string
FROM rust:1.95 AS builder
WORKDIR /git
# Copy manifest to leverage Docker layer caching when dependencies exist
COPY Cargo.toml .
# Copy the rest of the source code
COPY . .
# Build the static library from source
RUN cargo build --release
FROM debian:stable-slim AS runtime
# Install minimal runtime dependencies (staticlib does not require runtime, but include tools for inspection)
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates binutils \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /git
# Copy the static library from the builder stage
COPY --from=builder /git/target/release/libgitcore.a /usr/local/lib/libgitcore.a
# Default to an interactive shell so the container can be used as a library package
CMD ["/bin/bash"]
Concerns: Relies on the crate being configured to produce a static library named libgitcore.a; if the crate type is not staticlib, the COPY step will fail at build time., Runtime image does not include headers or bindings for using the static library from C/Rust; consumers would need to supply headers or a Rust wrapper to actually link against the library., No explicit Cargo.lock handling is shown; caching behavior depends on the manifest alone, which is common but could affect reproducibility if dependencies change. Smoke [PASS]: set -e; ar -t /usr/local/lib/libgitcore.a > /tmp/archive_contents.txt; if [ -s /tmp/archive_contents.txt ]; then echo OK; else echo FAIL; exit 1; fi Smoke [PASS]: set -e; first=$(ar -t /usr/local/lib/libgitcore.a | head -n1); ar -x /usr/local/lib/libgitcore.a "$first"; if [ -f "$first" ]; then nm -g --defined-only "$first" | head -n 5; else exit 1; fi Smoke [PASS]: set -e; first=$(ar -t /usr/local/lib/libgitcore.a | head -n1); ar -x /usr/local/lib/libgitcore.a "$first"; if [ -f "$first" ]; then readelf -h "$first" >/dev/null 2>&1 && echo OK; else exit 1; fi