diff --git a/backend/Dockerfile.test-rust b/backend/Dockerfile.test-rust index e7efda7..6f1ed46 100644 --- a/backend/Dockerfile.test-rust +++ b/backend/Dockerfile.test-rust @@ -1,16 +1,31 @@ -# Rust testing environment for CI/CD -ARG REGISTRY_HOST=localhost -ARG OWNER_REPO=owner/repo -FROM ${REGISTRY_HOST}/${OWNER_REPO}/rust:1.75-slim +# planner: produce recipe.json +FROM rust:1.89-slim AS planner +WORKDIR /app +RUN apt-get update && apt-get install -y --no-install-recommends pkg-config libssl-dev ca-certificates postgresql-client curl && rm -rf /var/lib/apt/lists/* +RUN cargo install --locked cargo-chef +COPY . . +RUN cargo chef prepare --recipe-path recipe.json -# Install additional tools needed for testing -RUN apt-get update && apt-get install -y \ - postgresql-client \ - curl \ - && rm -rf /var/lib/apt/lists/* +# deps: compile only external crates +FROM rust:1.89-slim AS deps +WORKDIR /app +RUN apt-get update && apt-get install -y --no-install-recommends pkg-config libssl-dev ca-certificates postgresql-client curl && 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 -# Set working directory +# builder: compile local workspace crates using cached deps +FROM rust:1.89-slim AS builder +WORKDIR /app +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 . . +RUN cargo build --release --locked + +# runtime: minimal test environment +FROM rust:1.89-slim AS runtime +RUN apt-get update && apt-get install -y --no-install-recommends postgresql-client curl && rm -rf /var/lib/apt/lists/* WORKDIR /workspace/backend - -# Keep container running for testing -CMD ["sleep", "infinity"] \ No newline at end of file +CMD ["sleep", "infinity"] \ No newline at end of file diff --git a/local-test-pod.yaml b/local-test-pod.yaml index 49f2b11..9261206 100644 --- a/local-test-pod.yaml +++ b/local-test-pod.yaml @@ -17,7 +17,7 @@ spec: - containerPort: 5432 - name: backend - image: rust:1.89-slim + image: localhost/sharenet-test-rust:latest workingDir: /app/backend env: - name: DATABASE_URL