FROM alpine:3.23 AS builder
LABEL maintainer="tabledevil"
RUN apk add --no-cache clamav clamav-libunrar freshclam python3 py3-pip bash
# fangfrisch needs Python; PEP 668 on modern Alpine blocks system-pip, use venv.
RUN python3 -m venv /opt/fangfrisch && /opt/fangfrisch/bin/pip install fangfrisch
RUN mkdir -m 0770 -p /var/lib/fangfrisch && chgrp clamav /var/lib/fangfrisch
ADD fangfrisch.conf /etc/fangfrisch.conf
USER clamav
RUN /opt/fangfrisch/bin/fangfrisch --conf /etc/fangfrisch.conf initdb
RUN /opt/fangfrisch/bin/fangfrisch --conf /etc/fangfrisch.conf refresh
RUN freshclam


FROM alpine:3.23
ARG PUID=1001
ARG PGID=1001
LABEL maintainer="tabledevil"
LABEL docker.cmd="docker run -it --rm -v /folder/to/scan:/data:ro --network=none tabledevil/clamav scan"
RUN apk add --no-cache clamav clamav-daemon clamav-clamdscan bash clamav-libunrar
COPY --from=builder /var/lib/clamav /var/lib/clamav
ADD clamd.conf /etc/clamav/clamd.conf
ADD start.sh /start.sh
RUN chmod +x /start.sh
RUN chown root /usr/bin/freshclam
RUN chmod u+s /usr/bin/freshclam
RUN mkdir -p /tmp && chown clamav:clamav /tmp
RUN addgroup -g ${PGID} user && \
    adduser -D -u ${PUID} -G user user && \
    adduser user clamav
ENTRYPOINT ["/start.sh"]
CMD ["shell"]
