# Claude Code Devcontainer
# Based on Microsoft devcontainer image for better devcontainer integration
FROM mcr.microsoft.com/devcontainers/base:ubuntu-24.04

ARG TZ
ENV TZ="$TZ"

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Install additional system packages (base image already includes git, curl, sudo, etc.)
RUN apt-get update && apt-get install -y --no-install-recommends \
  # Modern CLI tools
  fzf \
  ripgrep \
  fd-find \
  tmux \
  zsh \
  # Build tools
  build-essential \
  # Utilities
  jq \
  nano \
  vim \
  unzip \
  # Network tools (for security testing)
  iptables \
  ipset \
  iproute2 \
  dnsutils \
  && apt-get clean && rm -rf /var/lib/apt/lists/*

# Install git-delta
ARG GIT_DELTA_VERSION=0.18.2
RUN ARCH=$(dpkg --print-architecture) && \
  curl -fsSL "https://github.com/dandavison/delta/releases/download/${GIT_DELTA_VERSION}/git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" -o /tmp/git-delta.deb && \
  dpkg -i /tmp/git-delta.deb && \
  rm /tmp/git-delta.deb

# Install uv (Python package manager) via multi-stage copy
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

# Persist command history
RUN mkdir -p /commandhistory && \
  touch /commandhistory/.bash_history && \
  touch /commandhistory/.zsh_history && \
  chown -R vscode /commandhistory

# Set environment variables
ENV DEVCONTAINER=true
ENV SHELL=/bin/zsh
ENV EDITOR=nano
ENV VISUAL=nano

# Create workspace and config directories
RUN mkdir -p /workspace /home/vscode/.claude /opt && \
  chown -R vscode:vscode /workspace /home/vscode/.claude /opt

WORKDIR /workspace

# Switch to non-root user for remaining setup
USER vscode

# Install Claude Code natively
RUN curl -fsSL https://claude.ai/install.sh | bash

# Install Python 3.13 via uv (fast binary download, not source compilation)
RUN uv python install 3.13 --default
ENV PATH="/home/vscode/.local/bin:$PATH"

# Install Oh My Zsh
ARG ZSH_IN_DOCKER_VERSION=1.2.1
RUN sh -c "$(curl -fsSL https://github.com/deluan/zsh-in-docker/releases/download/v${ZSH_IN_DOCKER_VERSION}/zsh-in-docker.sh)" -- \
  -p git \
  -p fzf \
  -x

# Copy zsh configuration
COPY --chown=vscode:vscode .zshrc /home/vscode/.zshrc.custom

# Append custom zshrc to the main one
RUN echo 'source ~/.zshrc.custom' >> /home/vscode/.zshrc

# Copy post_install script
COPY --chown=vscode:vscode post_install.py /opt/post_install.py

# Copy Claude configuration
COPY --chown=vscode:vscode CLAUDE.md /home/vscode/.claude/CLAUDE.md
