FROM docker:29-cli@sha256:5a7af0dcb0e46c803efe9b45371dd21cb500e5b4453250394ac6f06d49b6e6f1 AS dockercli
FROM aquasec/trivy:0.76.2@sha256:8f6bb947dbc528902e11f2f5be52f7b519f6a39d5d148f41166f2040499768fb AS scanner
FROM jenkins/inbound-agent:jdk21@sha256:25a3704f7de4d3d0becc441f5683a227556658df1473865ee94c5232355678ab

USER root
RUN apt-get update \
 && apt-get install -y --no-install-recommends python3 python3-venv git openssh-client ca-certificates curl \
 && rm -rf /var/lib/apt/lists/*
COPY --from=dockercli /usr/local/bin/docker /usr/local/bin/docker
COPY --from=dockercli /usr/local/libexec/docker/cli-plugins/ /usr/local/libexec/docker/cli-plugins/
COPY --from=scanner /usr/local/bin/trivy /usr/local/bin/trivy
COPY agent/requirements.txt /tmp/requirements.txt
RUN python3 -m venv /opt/delivery-tools \
 && /opt/delivery-tools/bin/pip install --no-cache-dir -r /tmp/requirements.txt
ENV PATH="/opt/delivery-tools/bin:${PATH}" \
    ANSIBLE_COLLECTIONS_PATH=/opt/ansible-collections \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1
COPY ansible/requirements.yml /tmp/collections.yml
RUN ansible-galaxy collection install -r /tmp/collections.yml -p /opt/ansible-collections \
 && chmod -R a+rX /opt/ansible-collections \
 && mkdir -p /opt/delivery-tools/inventory \
 && dpkg-query -W > /opt/delivery-tools/inventory/debian-packages.txt \
 && pip freeze > /opt/delivery-tools/inventory/python-packages.txt
USER jenkins
