FROM rust:alpine3.21
ENV RUSTFLAGS="-C target-feature=-crt-static"
WORKDIR /usr/src/rebuilderd
RUN apk add --no-cache musl-dev pkgconfig
COPY . .
RUN --mount=type=cache,target=/var/cache/buildkit \
    CARGO_HOME=/var/cache/buildkit/cargo \
    CARGO_TARGET_DIR=/var/cache/buildkit/alpine/target \
    cargo build --release --locked -p rebuilderd-worker && \
    cp -v /var/cache/buildkit/alpine/target/release/rebuilderd-worker /

FROM alpine:3.21
RUN apk add --no-cache libgcc
COPY --from=0 /rebuilderd-worker /usr/local/bin/
ENV REBUILDERD_WORKER_BACKEND=alpine=/usr/local/libexec/rebuilderd/rebuilder-alpine.sh
ENTRYPOINT ["rebuilderd-worker"]
