FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
    xfce4 \
    xfce4-goodies \
    dbus-x11 \
    tigervnc-standalone-server \
    tigervnc-common \
    novnc \
    websockify \
    sudo \
    wget \
    curl \
    nano \
    git \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# ubuntu:24.04 already ships a default "ubuntu" user (uid 1000); just grant it passwordless sudo
RUN echo "ubuntu ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu \
    && chmod 0440 /etc/sudoers.d/ubuntu

# Keep these outside /home/ubuntu: that directory is replaced by a named
# volume at runtime (for persistence), which would otherwise shadow them.
COPY scripts/xstartup /opt/vnc/xstartup
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /opt/vnc/xstartup /usr/local/bin/entrypoint.sh

USER ubuntu
WORKDIR /home/ubuntu

EXPOSE 5901 6901

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
