ARG UBUNTU_VER

FROM ubuntu:${UBUNTU_VER}

ENV DEBIAN_FRONTEND=noninteractive

# Enable autocompletion and install packages in optimized layers
RUN rm /etc/apt/apt.conf.d/docker-* && \
    echo 'if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion; fi' >> /root/.bashrc

RUN apt update && apt install -y \
        # Basic utilities
        curl wget nano lsb-release sudo bash-completion jq git screen cron \
        # Basic networking tools  
        net-tools iputils-ping iproute2 iptables dnsutils \
        # Network diagnostic and probing tools
        tcpdump traceroute netcat-openbsd nmap telnet whois mtr-tiny socat \
        # Network performance tools
        iperf3 speedtest-cli \
        # Network configuration utilities
        bridge-utils vlan \
        # VPN and tunneling tools
        wireguard-tools openvpn stunnel4 \
        # Packet analysis tools
        tshark \
        # Programming languages and runtimes
        python3 python3-pip python3-venv python3-dev python-is-python3 \
        # Development tools
        software-properties-common build-essential \
        # Remote access
        openssh-server \
        # Localization
        locales

# Install Node.js using official NodeSource repository
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - && \
    apt-get install -y nodejs

# Configure locales
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
RUN locale-gen en_US.UTF-8

# Configure SSH
RUN mkdir -p /var/run/sshd

# Allow non-root users to run sudo command without password
RUN echo "ALL ALL=NOPASSWD:ALL" > /etc/sudoers.d/01-allow-sudo

COPY scripts/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENV LOG_FILE=/dev/null

# Reset DEBIAN_FRONTEND
ENV DEBIAN_FRONTEND=""

EXPOSE 22

CMD ["/entrypoint.sh"]
