FROM ubuntu:22.04

LABEL maintainer="alexz"
LABEL description="OpenConnect SSO VPN in Docker with noVNC"
LABEL version="1.0.0"

ENV DEBIAN_FRONTEND=noninteractive

# VNC/noVNC settings
ENV DISPLAY=:1
ENV VNC_PORT=5901
ENV NOVNC_PORT=6092

# Python/Playwright settings
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
ENV VIRTUAL_ENV=/opt/venv
ENV PATH=/opt/venv/bin:$PATH

# Install dependencies (no systemd)
RUN apt-get update && apt-get install -y \
    dbus \
    dbus-x11 \
    libgtk-3-0 \
    libglib2.0-0 \
    libstdc++6 \
    iptables \
    libxml2 \
    zlib1g \
    policykit-1 \
    xdg-utils \
    libwebkit2gtk-4.0-37 \
    tigervnc-standalone-server \
    tigervnc-common \
    novnc \
    websockify \
    openbox \
    xterm \
    procps \
    net-tools \
    curl \
    iproute2 \
    iputils-ping \
    nano \
    x11vnc \
    xvfb \
    fluxbox \
    xdotool \
    oathtool \
    openconnect \
    python3 \
    python3-pip \
    python3-venv \
    vpnc-scripts \
    libasound2 \
    libnss3 \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libxcomposite1 \
    libxrandr2 \
    libgbm1 \
    libxdamage1 \
    libpango-1.0-0 \
    fonts-liberation \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Install openconnect-sso with playwright
RUN python3 -m venv "$VIRTUAL_ENV" && \
    pip install --no-cache-dir openconnect-sso[full] playwright keyring keyrings.alt && \
    python -m playwright install --with-deps chromium

RUN mkdir -p /opt/scripts /shared

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

EXPOSE 5901 6092

CMD ["/opt/scripts/entrypoint.sh"]
