# CheetahClaws — server image (Web UI + bridges)
#
# Targets headless deployments: home server, cloud VM, container hosts.
# Default CMD launches the web UI on 0.0.0.0:8080; configured Telegram /
# WeChat / Slack bridges auto-start in the same process.
#
# Build:    docker build -t cheetahclaws:latest .
# Compose:  see docker-compose.yml

FROM python:3.13-slim AS runtime

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

# git: occasionally invoked by the agent for status/log inside /workspace.
# tini: PID-1 signal handling (clean Ctrl-C / docker stop).
RUN apt-get update \
 && apt-get install -y --no-install-recommends git tini \
 && rm -rf /var/lib/apt/lists/*

# Non-root user. UID 1000 matches the typical first Linux user; override at
# runtime with `--user "${UID}:${GID}"` when host UIDs differ so files
# written into mounted /workspace remain owner-readable on the host.
RUN useradd --create-home --uid 1000 --shell /bin/bash cheetah

WORKDIR /opt/cheetahclaws
COPY --chown=cheetah:cheetah pyproject.toml requirements.txt ./
COPY --chown=cheetah:cheetah . .

# Install with the [web] extra so chat-UI deps (sqlalchemy, bcrypt, PyJWT)
# are present. Use editable install so version metadata + entry point match
# the source tree.
RUN pip install --no-cache-dir -e '.[web]'

USER cheetah

# Persist config, sessions, history. Mount this in compose to survive
# container recreation.
VOLUME ["/home/cheetah/.cheetahclaws"]

# Workspace where the agent reads/writes files. Mount your project from
# the host onto this path.
WORKDIR /workspace

EXPOSE 8080

# Healthcheck: web server's /api/config returns 200 once it's up.
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD python -c "import urllib.request,sys; \
sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8080/api/config', timeout=3).status == 200 else 1)" \
  || exit 1

ENTRYPOINT ["/usr/bin/tini", "--", "cheetahclaws"]
CMD ["--web", "--host", "0.0.0.0", "--port", "8080"]
