FROM alpine:3.21

ENV FIREFOX_HOMEPAGE="https://www.google.com" \
    RDP_PASSWORD="changeme"

# Install packages
RUN apk add --no-cache \
    openbox \
    xrdp \
    mesa-dri-gallium \
    mesa-gl \
    font-noto \
    font-noto-emoji \
    dbus \
    firefox \
    bash \
    supervisor \
    xterm \
    x11vnc \
    xset \
    xvfb

# Create user
RUN adduser -D -s /bin/bash openbox && \
    echo "openbox:${RDP_PASSWORD}" | chpasswd

# Configure XRDP - proxy mode to existing VNC session
COPY config/xrdp.ini /etc/xrdp/xrdp.ini
RUN mkdir -p /run/xrdp && \
    chmod 0755 /run/xrdp

# OpenBox config
RUN mkdir -p /home/openbox/.config/openbox

COPY config/menu.xml /home/openbox/.config/openbox/menu.xml
COPY config/autostart.sh /home/openbox/.config/openbox/autostart
COPY config/rc.xml /home/openbox/.config/openbox/rc.xml

# Startup scripts
COPY scripts/start.sh /usr/local/bin/start.sh
COPY scripts/set-password.sh /usr/local/bin/set-password.sh

RUN chmod +x /home/openbox/.config/openbox/autostart && \
    chmod +x /usr/local/bin/start.sh && \
    chmod +x /usr/local/bin/set-password.sh && \
    chown -R openbox:openbox /home/openbox

# Supervisor config
COPY config/supervisord.conf /etc/supervisord.conf

EXPOSE 3389 5900

CMD ["/usr/local/bin/start.sh"]
