# NetMonitor – clean image: Ubuntu + sshd + Python + app (EMPTY database)
#
#   build : docker build --build-arg ROOT_PASSWORD='...' -t netmonitor:latest .
#   run   : docker run -d --name netmonitor --restart unless-stopped \
#               -p 7080:7080 -p 7022:7022 netmonitor:latest
#
# First login: sysadmin / pas4admin (auto-created on first start)
FROM ubuntu:26.04

ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    NETMONITOR_PORT=7080

# --- system packages ---------------------------------------------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
        python3 \
        python3-pip \
        openssh-server \
        openssh-sftp-server \
    && rm -rf /var/lib/apt/lists/*

# sshd: root + password login, port 7022 (mirrors the existing deployment)
RUN printf 'Port 7022\nPermitRootLogin yes\nPasswordAuthentication yes\n' \
        >> /etc/ssh/sshd_config \
    && mkdir -p /var/run/sshd /var/log

# root password – REQUIRED at build time:
#   docker build --build-arg ROOT_PASSWORD='YourPassword' -t netmonitor:latest .
ARG ROOT_PASSWORD
RUN test -n "$ROOT_PASSWORD" && echo "root:$ROOT_PASSWORD" | chpasswd

# --- NetMonitor app ----------------------------------------------------------
WORKDIR /opt/netmonitor
COPY requirements.txt ./
RUN pip3 install --no-cache-dir --break-system-packages -r requirements.txt

COPY app.py collector.py db.py router_pollers.py snmp_client.py config.json ./
COPY static/ ./static/
COPY docs/ ./docs/
RUN mkdir -p data

# SysV-style service control (container has no systemd)
COPY container/init-netmonitor.sh /etc/init.d/netmonitor
COPY container/entrypoint.sh ./entrypoint.sh
RUN chmod +x /etc/init.d/netmonitor ./entrypoint.sh

EXPOSE 7080 7022
ENTRYPOINT ["/opt/netmonitor/entrypoint.sh"]
