# vibn-dev — per-project AI development container.
#
# Ships with Node.js (LTS), Python 3.12, and Go 1.23 pre-installed so the AI
# can start running code immediately without a mise install step.
#
# Spec is in AI_PATH_B_EXECUTION_PLAN.md §3.

FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive \
    LANG=C.UTF-8 \
    LC_ALL=C.UTF-8 \
    TZ=UTC

# Core OS packages + shell/git/ripgrep/tini/supervisor.
# Language toolchains installed below.
RUN apt-get update && apt-get install -y --no-install-recommends \
        bash coreutils ca-certificates curl wget git openssh-client \
        ripgrep jq nano vim less procps lsof net-tools dnsutils \
        build-essential pkg-config \
        sudo tini supervisor unzip xz-utils \
        python3 python3-pip python3-venv \
    && rm -rf /var/lib/apt/lists/*


# Playwright System Dependencies (for headless Chromium)
RUN apt-get update && apt-get install -y --no-install-recommends \
        libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
        libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 \
        libgbm1 libasound2t64 libpangocairo-1.0-0 libpango-1.0-0 libcairo2 \
        && rm -rf /var/lib/apt/lists/*

# Node.js LTS (via NodeSource)
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

# Go 1.23 — scrape latest patch version from go.dev/dl
RUN GO_TAR=$(curl -fsSL https://go.dev/dl/ | grep -oE 'go1\.23\.[0-9]+\.linux-amd64\.tar\.gz' | head -1) \
    && curl -fsSL "https://go.dev/dl/${GO_TAR}" | tar -C /usr/local -xz \
    && echo 'export PATH=/usr/local/go/bin:$PATH' >> /etc/profile.d/go.sh

# vibn user — the AI runs as this, NOT root.
RUN userdel -r ubuntu 2>/dev/null || true \
    && useradd --create-home --shell /bin/bash --uid 1000 vibn \
    && mkdir -p /workspace /home/vibn/.cache /home/vibn/.local /var/log/vibn-dev \
    && chown -R vibn:vibn /workspace /home/vibn /var/log/vibn-dev \
    && echo 'vibn ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/vibn

# Toolchain env for vibn user
RUN echo 'export PATH=/usr/local/go/bin:$PATH' >> /home/vibn/.bashrc \
    && echo 'export PATH="$HOME/.local/bin:$PATH"' >> /home/vibn/.bashrc

COPY supervisord.conf /etc/supervisor/conf.d/vibn-dev.conf

WORKDIR /workspace
USER vibn

# Keep-alive. Commands run via docker exec.
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["tail", "-f", "/dev/null"]
