FROM node:26-trixie-slim

USER root

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        curl \
        bash \
        ca-certificates \
        coreutils \
        findutils \
        git \
        grep \
        openssh-client \
        tar \
        docker.io \
        docker-compose \
        python3 \
	python3-pip \
	pipx \
        make \
        g++ \
    && rm -rf /var/lib/apt/lists/*

USER node

ENV HOME=/home/node
ENV PATH="/home/node/.local/bin:/home/node/.opencode/bin:${PATH}"

RUN npm config set prefix ~/.local

WORKDIR /home/node

# Install OpenCode CLI
RUN curl -fsSL https://opencode.ai/install | bash

# Install OpenChamber (web + PWA)
RUN curl -fsSL https://raw.githubusercontent.com/openchamber/openchamber/main/scripts/install.sh | bash

# Install Graphifyy
RUN pipx install graphifyy && graphify install opencode

CMD ["sh", "-c", "rm -f /home/node/.config/openchamber/run/openchamber-*.pid /home/node/.config/openchamber/run/openchamber-*.json && exec openchamber serve --host 0.0.0.0 --port ${OPENCHAMBER_PORT:-5200} --foreground ${UI_PASSWORD:+--ui-password $UI_PASSWORD}"]
