# syntax=docker/dockerfile:1.4
FROM node:22-slim AS conformance-fixtures
WORKDIR /fixtures
COPY --from=shared_tests / ./tests/
COPY --from=repo_tools / ./tools/
RUN npm ci --prefix tools \
&& npm --prefix tools run conformance:yaml-to-json
FROM rust:slim
WORKDIR /app
RUN rustup component add rustfmt clippy
# Pre-build dependencies with a stub library so Cargo can resolve and compile
# the dependency graph before the real source is available. This layer is
# cached until Cargo.toml / Cargo.lock change.
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "" > src/lib.rs \
&& cargo build \
&& rm -rf src
COPY . .
COPY --from=conformance-fixtures /fixtures/tests/ ./tests/
CMD ["sh", "-ec", "count=\"${LITEGUARD_TESTS_COUNT:-1}\"; case \"$count\" in ''|*[!0-9]*) echo 'LITEGUARD_TESTS_COUNT must be a positive integer' >&2; exit 1 ;; esac; if [ \"$count\" -lt 1 ]; then echo 'LITEGUARD_TESTS_COUNT must be a positive integer' >&2; exit 1; fi; cargo fmt --check; cargo clippy -- -D warnings; i=1; while [ \"$i\" -le \"$count\" ]; do echo \"==> cargo test run $i/$count\"; cargo test; i=$((i + 1)); done"]