FROM codercom/enterprise-base:ubuntu

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

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 GO_RELEASE="$(curl -fsSL 'https://go.dev/VERSION?m=text' | head -n 1)" && \
    curl -fsSL "https://go.dev/dl/${GO_RELEASE}.linux-${GO_ARCH}.tar.gz" -o /tmp/go.tar.gz && \
    tar -C /usr/local -xzf /tmp/go.tar.gz && \
    rm /tmp/go.tar.gz

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

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

ENV OPENCODE_INSTALL_DIR=/opt/opencode
RUN curl -fsSL https://opencode.ai/install | bash && \
    chown -R coder:coder ${OPENCODE_INSTALL_DIR}

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="/usr/local/go/bin:/home/coder/go/bin:/opt/bun/bin:/opt/opencode/bin:${PATH}"
