FROM codercom/enterprise-base:ubuntu

ARG DEBIAN_FRONTEND=noninteractive
ARG TEA_VERSION=
ARG TEA_ARCH=amd64
ARG NODE_VERSION=22

USER root

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y \
      build-essential ca-certificates curl git jq sudo unzip wget zip && \
    rm -rf /var/lib/apt/lists/*

RUN curl -fsSL https://get.docker.com | sh

RUN tea_version="${TEA_VERSION}" && \
    if [ -z "$tea_version" ]; then \
      tea_version="$(curl -fsSL https://gitea.com/api/v1/repos/gitea/tea/releases/latest | jq -r .tag_name)"; \
    fi && \
    tea_version="${tea_version#v}" && \
    curl -fsSL "https://dl.gitea.com/tea/${tea_version}/tea-${tea_version}-linux-${TEA_ARCH}" \
      -o /usr/local/bin/tea && \
    chmod 755 /usr/local/bin/tea

RUN curl -fsSL "https://deb.nodesource.com/setup_${NODE_VERSION}.x" | bash - && \
    apt-get install -y nodejs && \
    rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
    apt-get install -y python3 python3-dev python3-pip python3-venv && \
    rm -rf /var/lib/apt/lists/* && \
    update-alternatives --install /usr/bin/python python /usr/bin/python3 1

ENV UV_INSTALL_DIR=/opt/uv/bin
RUN curl -LsSf https://astral.sh/uv/install.sh | sh

ENV BUN_INSTALL=/opt/bun
RUN curl -fsSL https://bun.sh/install | bash && \
    chown -R coder:coder ${BUN_INSTALL}

ENV CLAUDE_HOME=/opt/claude
RUN mkdir -p ${CLAUDE_HOME} && \
    env HOME=${CLAUDE_HOME} bash -c 'curl -fsSL https://claude.ai/install.sh | bash' && \
    ln -s ${CLAUDE_HOME}/.local/bin/claude /usr/local/bin/claude && \
    chown -R coder:coder ${CLAUDE_HOME}

USER coder

ENV PATH="/opt/bun/bin:/opt/uv/bin:${PATH}"
