FROM localhost/base:latest

ARG OPENCODE_VERSION=1.18.8
ARG OPENCODE_SHA256=b72014b8b53427fdb5a628d2433569ee7ccd289bd5c4490636064b24791c1305

USER root

RUN curl -fsSL -o /tmp/opencode.tar.gz \
        "https://github.com/anomalyco/opencode/releases/download/v${OPENCODE_VERSION}/opencode-linux-x64.tar.gz" \
    && echo "${OPENCODE_SHA256}  /tmp/opencode.tar.gz" | sha256sum -c - \
    && tar -xzf /tmp/opencode.tar.gz -C /usr/local/bin \
    && chmod +x /usr/local/bin/opencode \
    && rm -f /tmp/opencode.tar.gz

COPY images/runner/opencode/opencode.json /home/agent-ci/.config/opencode/opencode.json
RUN chown -R agent-ci:agent-ci /home/agent-ci/.config

USER agent-ci
RUN git clone --depth 1 --quiet https://github.com/opendatahub-io/skills-registry.git /tmp/skills-registry \
    && agentic-ci install-plugins --harness opencode \
       --marketplace-json /tmp/skills-registry/.claude-plugin/marketplace.json \
    && rm -rf /tmp/skills-registry

ENV AGENT_TOOL=opencode
ENV OPENCODE_CONFIG_DIR=/home/agent-ci/.config/opencode
WORKDIR /home/agent-ci
ENTRYPOINT ["entrypoint.sh"]
CMD ["opencode"]
