ARG UBUNTU_VER=24.04

FROM ubuntu:${UBUNTU_VER}

ARG 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
    && curl -fsSL https://deb.nodesource.com/setup_lts.x | 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

# Set system-wide git configs
RUN git config --system user.name "ameer" && \
    git config --system user.email "ameer@ahkhan.me"

# Copy utility scripts to /bin/ for independent execution
COPY scripts/bin/configure-china-mirrors /bin/configure-china-mirrors
COPY scripts/bin/update-apt-cache /bin/update-apt-cache
COPY scripts/bin/setup-user-home /bin/setup-user-home
RUN chmod +x /bin/configure-china-mirrors /bin/update-apt-cache /bin/setup-user-home

# Copy entrypoint script to root
COPY scripts/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENV LOG_FILE=/dev/null

EXPOSE 22

CMD ["/entrypoint.sh"]
