# The tool runner as an AgentCore Runtime container, with Python, boto3, the AWS CLI, and the
# scenario examples' skills. AgentCore runs Linux ARM64 only.
#
# Copy-only, with no RUN, so building it for ARM64 on an x86-64 machine needs no emulation.
# build-image.sh downloads the Python packages' ARM64 wheels on the host and stages them as deps/.
#
# The base image is pinned to a version tag and its digest. build-image.sh names the image after a
# hash of this file, so the image's name changes when the base does. To pick up Debian's and
# Python's later fixes, `docker buildx imagetools inspect public.ecr.aws/docker/library/python:<tag>`
# prints a newer tag's digest on its Digest: line. Change both the tag and the digest here.
FROM --platform=linux/arm64 public.ecr.aws/docker/library/python:3.12.16-slim-bookworm@sha256:935c3c5b12357a7e10caa9c1e6ca5692344d97cf229832ef584be2cec9fc03df

# The CA bundle is Amazon Linux 2023's, from that distribution's latest image when the image is
# built, as in the image/ folder of claude-managed-agents-tool-runner.zip. build-image.sh names the image after that image's
# digest too, so a new Amazon Linux 2023 release rebuilds it.
COPY --from=public.ecr.aws/amazonlinux/amazonlinux:2023 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /etc/ssl/certs/ca-certificates.crt

COPY deps/ /opt/cma/lib/
COPY --chmod=755 aws /usr/local/bin/aws
COPY --chmod=755 cma-tool-runner /opt/cma/bin/cma-tool-runner
# One folder for each scenario, such as /opt/skills/invoice-reconciliation. An agent names its own.
COPY skills/ /opt/skills/
# The working directory of a session that names none.
COPY --chown=65534:65534 workspace/ /mnt/workspace/
COPY --chown=65534:65534 workspace/ /workspace/

ENV PYTHONPATH=/opt/cma/lib PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
# AgentCore reaches the container on 0.0.0.0:8080.
ENV CMA_TOOL_RUNNER_BIND=0.0.0.0:8080
ENV HOME=/workspace
USER 65534:65534
WORKDIR /workspace
EXPOSE 8080
ENTRYPOINT ["/opt/cma/bin/cma-tool-runner", "agentcore"]
