# Extends the official OpenClaw image with what Homebrew needs.
# Brew itself is installed into the mounted volume on first start (see brew-entrypoint.sh),
# so brew and everything it installs survive image updates.

ARG OPENCLAW_VERSION=latest
# Check docs.openclaw.ai/install/docker for the exact official image name.
FROM ghcr.io/openclaw/openclaw:${OPENCLAW_VERSION}

USER root
RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential procps curl file git ca-certificates \
    && rm -rf /var/lib/apt/lists/* \
    && mkdir -p /home/linuxbrew/.linuxbrew \
    && chown -R node:node /home/linuxbrew

COPY --chmod=755 brew-entrypoint.sh /usr/local/bin/brew-entrypoint.sh

USER node
ENV HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew \
    HOMEBREW_NO_AUTO_UPDATE=1 \
    HOMEBREW_NO_ANALYTICS=1 \
    PATH=/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:${PATH}

# Setting ENTRYPOINT resets the base image's CMD, so you must restore it.
# Find the originals with:
#   docker inspect --format '{{json .Config.Entrypoint}} {{json .Config.Cmd}}' <official-image>
# If the base image has its own ENTRYPOINT, add it after brew-entrypoint.sh in the list below.
ENTRYPOINT ["/usr/local/bin/brew-entrypoint.sh"]
CMD ["sh", "brew_entrypoint.sh"]
ENTRYPOINT ["tini", "-s", "--", "node", "/app/docker-entrypoint.mjs"]
CMD ["node", "openclaw.mjs", "gateway"]