sharenet/backend/Dockerfile.test-rust
continuist 1c542bfca7
All checks were successful
Podman Rootless Demo / test-backend (push) Successful in 9m10s
Podman Rootless Demo / test-frontend (push) Successful in 12s
Podman Rootless Demo / build-backend (push) Successful in 5m21s
Podman Rootless Demo / build-frontend (push) Successful in 2m21s
Podman Rootless Demo / deploy-prod (push) Successful in 36s
Copy over migrations folder into container
2025-09-21 12:23:50 -04:00

44 lines
No EOL
1.8 KiB
Text

# Base stage with consistent working directory
FROM docker.io/rust:1.89-slim AS base
WORKDIR /app
# Planner: produce recipe.json
FROM base AS planner
RUN apt-get update && apt-get install -y --no-install-recommends pkg-config libssl-dev ca-certificates && rm -rf /var/lib/apt/lists/*
RUN cargo install --locked cargo-chef
COPY . .
COPY migrations /app/migrations
RUN cargo chef prepare --recipe-path recipe.json
# Deps: compile only external crates
FROM base AS deps
RUN apt-get update && apt-get install -y --no-install-recommends pkg-config libssl-dev ca-certificates && rm -rf /var/lib/apt/lists/*
RUN cargo install --locked cargo-chef
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
# Test-build: compile workspace with pre-built dependencies
FROM base AS test-build
COPY --from=deps /usr/local/cargo /usr/local/cargo
COPY --from=deps /usr/local/rustup /usr/local/rustup
# Copy only release artifacts to save space
COPY --from=deps /app/target/release /app/target/release
COPY . .
COPY --from=planner /app/migrations /app/migrations
# Clean up incremental compilation artifacts before test build
RUN rm -rf /app/target/debug/incremental
RUN cargo test --workspace --locked --no-run
# Clean up after test build to save space
RUN rm -rf /app/target/debug/incremental /app/target/debug/build /app/target/debug/deps
# Runner: minimal runtime for test execution
FROM base AS runner
# Copy only necessary artifacts for test execution
COPY --from=test-build /app/target /app/target
COPY --from=test-build /app/Cargo.toml /app/Cargo.toml
COPY --from=test-build /app/Cargo.lock /app/Cargo.lock
COPY --from=test-build /app/crates /app/crates
COPY --from=test-build /app/migrations /app/migrations
WORKDIR /app
CMD ["cargo", "test", "--workspace", "--locked", "--", "--test-threads=1"]