FROM codercom/code-server:latest

USER root

# Install Node.js 18+ and npm
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
    && apt-get install -y nodejs

# Install Claude Code globally as root
RUN npm install -g @anthropic-ai/claude-code

# Install Ollama
RUN curl -fsSL https://ollama.com/install.sh | sh

# Install Python and dependencies
RUN apt-get update && apt-get install -y \
    python3 \
    python3-pip \
    python3-venv \
    python3-full \
    pipx \
    # Dependencies for CairoSVG and Pillow (PIL)
    libcairo2-dev \
    libfreetype6-dev \
    libffi-dev \
    libjpeg-dev \
    libpng-dev \
    libz-dev \
    python3-dev \
    pkg-config \
    # Additional dependencies for advanced image processing
    libwebp-dev \
    libtiff5-dev \
    libopenjp2-7-dev \
    liblcms2-dev \
    libxml2-dev \
    libxslt1-dev \
    # PDF generation dependencies
    weasyprint \
    fonts-roboto \
    # Git for git-based plugins
    git \
    # For lxml
    zlib1g-dev \
    # Required for some plugins
    build-essential \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Switch to non-root user (coder)
USER coder

# Set up a virtual environment for mkdocs
RUN mkdir -p /home/coder/.venv
RUN python3 -m venv /home/coder/.venv/mkdocs

# Install mkdocs-material in the virtual environment with all extras
RUN /home/coder/.venv/mkdocs/bin/pip install "mkdocs-material[imaging,recommended,git]" 

# Install additional useful MkDocs plugins
RUN /home/coder/.venv/mkdocs/bin/pip install \
    mkdocs-minify-plugin \
    mkdocs-git-revision-date-localized-plugin \
    mkdocs-glightbox \
    mkdocs-redirects \
    mkdocs-awesome-pages-plugin \
    mkdocs-blog-plugin \
    mkdocs-rss-plugin \
    mkdocs-meta-descriptions-plugin \
    mkdocs-swagger-ui-tag \
    mkdocs-macros-plugin \
    mkdocs-material-extensions \
    mkdocs-section-index \
    mkdocs-table-reader-plugin \
    mkdocs-pdf-export-plugin \
    mkdocs-mermaid2-plugin \
    pymdown-extensions \
    pygments \
    pillow \
    cairosvg

# Add the virtual environment bin to PATH
ENV PATH="/home/coder/.venv/mkdocs/bin:${PATH}"

# Add shell configuration to activate the virtual environment in .bashrc
RUN echo 'export PATH="/home/coder/.venv/mkdocs/bin:$PATH"' >> ~/.bashrc
RUN echo 'export PATH="/home/coder/.local/bin:$PATH"' >> ~/.bashrc

# Create a convenience script to simplify running mkdocs commands
RUN mkdir -p /home/coder/.local/bin \
    && echo '#!/bin/bash\ncd /home/coder/mkdocs\nmkdocs "$@"' > /home/coder/.local/bin/run-mkdocs \
    && chmod +x /home/coder/.local/bin/run-mkdocs

WORKDIR /home/coder