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

WORKDIR /build
ENV CARGO_BUILD_JOBS=1
COPY src/components/microservices/auth-broker/Cargo.toml ./Cargo.toml
COPY src/components/microservices/auth-broker/Cargo.lock ./Cargo.lock
RUN mkdir -p src \
  && printf 'fn main() { println!("dependency cache"); }\n' > src/main.rs \
  && cargo build --release \
  && rm -rf src
COPY src/components/microservices/auth-broker/src ./src
RUN touch src/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/auth-broker /usr/local/bin/auth-broker

EXPOSE 4291
CMD ["auth-broker"]
