FROM rust:bookworm
WORKDIR /usr/src/rebuilderd
COPY . .
RUN --mount=type=cache,target=/var/cache/buildkit \
    CARGO_HOME=/var/cache/buildkit/cargo \
    CARGO_TARGET_DIR=/var/cache/buildkit/debian/target \
    cargo build --release --locked -p rebuilderd-worker && \
    cp -v /var/cache/buildkit/debian/target/release/rebuilderd-worker /

FROM debian:trixie
RUN apt-get update && apt install -y apt-utils debian-keyring devscripts diffoscope dpkg-dev mmdebstrap sbuild uidmap
COPY --from=0 \
    /usr/src/rebuilderd/worker/rebuilder-debian.sh \
    /usr/local/libexec/rebuilderd/
COPY --from=0 /rebuilderd-worker /usr/local/bin/
ENV REBUILDERD_WORKER_BACKEND=debian=/usr/local/libexec/rebuilderd/rebuilder-debian.sh
ENTRYPOINT ["rebuilderd-worker"]
