Optimize backend test container to save space
Some checks failed
Podman Rootless Demo / test-backend (push) Failing after 8m40s
Podman Rootless Demo / test-frontend (push) Has been skipped
Podman Rootless Demo / build-backend (push) Has been skipped
Podman Rootless Demo / build-frontend (push) Has been skipped
Podman Rootless Demo / deploy-prod (push) Has been skipped

This commit is contained in:
continuist 2025-09-21 12:09:52 -04:00
parent 870dcd3b1c
commit 9506b4b09c

View file

@ -21,12 +21,21 @@ RUN cargo chef cook --release --recipe-path recipe.json
FROM base AS test-build
COPY --from=deps /usr/local/cargo /usr/local/cargo
COPY --from=deps /usr/local/rustup /usr/local/rustup
COPY --from=deps /app/target /app/target
# Copy only release artifacts to save space
COPY --from=deps /app/target/release /app/target/release
COPY . .
# 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 --from=test-build /app /app
# 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
WORKDIR /app
CMD ["cargo", "test", "--workspace", "--locked", "--", "--test-threads=1"]