use Cargo Chef to use pre-built Rust backend container image in local testing
This commit is contained in:
parent
13f554ba6d
commit
9086906180
2 changed files with 29 additions and 14 deletions
|
|
@ -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"]
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue