FROM rust:1.69-alpine AS builder

ARG DI_VER=1.2.5

RUN apk update && \
    apk add --no-cache build-base curl

WORKDIR /build

# Build dumb-init
RUN curl -Lo - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.tar.gz" | tar -xzf - && \
    cd "dumb-init-${DI_VER}" && \
    make SHELL=/bin/sh && \
    mv dumb-init ..

WORKDIR /build/affy

COPY ./ ./

RUN cargo build --release && \
    [ "$(readelf -d target/release/affy | grep NEEDED | wc -l)" = 0 ]


FROM busybox:1.36.0

COPY --from=builder /build/dumb-init /build/affy/target/release/affy /bin/

WORKDIR /data

ENV TZ=Europe/Brussels

USER www-data:www-data

ENTRYPOINT ["/bin/dumb-init", "--"]
CMD ["/bin/affy"]