# The tool runner as an AgentCore Runtime container, with git, gh, and the credential helper that
# gets them a token. AgentCore runs Linux ARM64 only.
#
# Copy-only, with no RUN, so building it for ARM64 on an x86 machine needs no emulation. The base
# image already has git and curl. build-image.sh stages the files this copies.
#
# The base image is named by digest, resolved 2026-10-23 for the buildpack-deps:bookworm-scm
# multi-arch index. README.md says how to move to a newer one. build-image.sh reads the name from
# the line that starts ARG BASE_IMAGE=.
ARG BASE_IMAGE=public.ecr.aws/docker/library/buildpack-deps:bookworm-scm@sha256:1314fd2a9c83b257b37132883b3c8e326d3909211bdcb419c9757399ebc34bf3
FROM --platform=linux/arm64 ${BASE_IMAGE}

# The base image's users plus `runner`, uid 10001, whose home is /home/runner.
COPY passwd /etc/passwd
COPY group /etc/group
# Tells git, for every user, to run the credential helper for github.com.
COPY gitconfig /etc/gitconfig
COPY --chmod=755 cma-tool-runner git-credential-cma /opt/cma/bin/
# /opt/cma/bin is not on PATH, so `gh` is the wrapper, which runs the real one.
COPY --chmod=755 gh-cli /opt/cma/bin/gh
COPY --chmod=755 gh /usr/local/bin/gh
COPY --chown=10001:10001 empty/ /home/runner/
# The working directory of a session that names none.
COPY --chown=10001:10001 empty/ /mnt/workspace/

# AgentCore reaches the container on 0.0.0.0:8080.
ENV CMA_TOOL_RUNNER_BIND=0.0.0.0:8080
ENV HOME=/home/runner
USER 10001:10001
WORKDIR /mnt/workspace
EXPOSE 8080
ENTRYPOINT ["/opt/cma/bin/cma-tool-runner", "agentcore"]
