# PentestAgent Kali Linux Image
# Full penetration testing environment

FROM kalilinux/kali-last-release

LABEL maintainer="Masic"
LABEL description="PentestAgent with Kali Linux tools"

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV TOKENIZERS_PARALLELISM=false

# Prevent post-install scripts from trying to start services inside the container
RUN printf '#!/bin/sh\nexit 101\n' > /usr/sbin/policy-rc.d && chmod +x /usr/sbin/policy-rc.d

# Update and install Kali tools
RUN apt-get update && apt-get install -y --no-install-recommends \
    # Python (python3-full includes venv with ensurepip)
    python3-full \
    python3-pip \
    # Kali meta-packages (selective for size)
    kali-tools-web \
    kali-tools-information-gathering \
    kali-tools-vulnerability \
    kali-tools-exploitation \
    # Additional tools
    nmap \
    nikto \
    dirb \
    gobuster \
    sqlmap \
    wpscan \
    hydra \
    john \
    hashcat \
    metasploit-framework \
    burpsuite \
    zaproxy \
    nuclei \
    ffuf \
    # Network tools
    openvpn \
    wireguard \
    proxychains4 \
    tor \
    # Utilities
    curl \
    wget \
    git \
    vim \
    tmux \
    jq \
    xclip \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && rm -f /usr/sbin/policy-rc.d

# Create app directory
WORKDIR /app

# Install Python dependencies using virtual environment (PEP 668 compliance)
COPY pyproject.toml README.md ./
RUN python3 -m venv /opt/venv && \
    /opt/venv/bin/pip install --no-cache-dir --upgrade pip wheel setuptools

# Install heavy dependencies first (helps with CI memory limits)
RUN /opt/venv/bin/pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu
RUN /opt/venv/bin/pip install --no-cache-dir sentence-transformers faiss-cpu
RUN mkdir -p pentestagent && touch pentestagent/__init__.py && \
    /opt/venv/bin/pip install --no-cache-dir -e ".[rag]"

# Add venv to PATH
ENV PATH="/opt/venv/bin:$PATH"

# Copy application code
COPY . .

# Copy common wordlists
RUN mkdir -p /wordlists && \
    cp -r /usr/share/wordlists/* /wordlists/ 2>/dev/null || true

# Set permissions
RUN chmod +x /app/scripts/*.sh 2>/dev/null || true

# Entry point
COPY docker-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
CMD ["python3", "-m", "pentestagent"]
