ARG CODE_QUEUE_MGR_RUST_IMAGE=rust:1.85-bookworm
FROM ${CODE_QUEUE_MGR_RUST_IMAGE} AS build

WORKDIR /build
ENV CARGO_BUILD_JOBS=1
COPY src/components/microservices/code-queue-mgr/Cargo.toml ./Cargo.toml
COPY src/components/microservices/code-queue-mgr/Cargo.lock ./Cargo.lock
RUN mkdir -p src-rs \
  && printf 'fn main() { println!("dependency cache"); }\n' > src-rs/main.rs \
  && cargo build --release \
  && rm -rf src-rs
COPY src/components/microservices/code-queue-mgr/src-rs ./src-rs
RUN touch src-rs/main.rs && cargo build --release

FROM debian:bookworm-slim

RUN apt-get update \
  && apt-get install -y --no-install-recommends ca-certificates \
  && rm -rf /var/lib/apt/lists/*

COPY --from=build /build/target/release/code-queue-mgr /usr/local/bin/code-queue-mgr

EXPOSE 4278
CMD ["code-queue-mgr"]
