# The CMA tool runner, as an AgentCore Runtime container. AgentCore runs Linux ARM64 only.
#
# Copy-only on purpose: there is no RUN, so building it for arm64 on an x86 host needs no
# emulation. The binary next to this file is already compiled for aarch64.
#
# Debian because the binary is linked against Debian bookworm's glibc, and bookworm-slim because
# the tools a model runs need bash and coreutils.
#
# The base image is pinned to a dated tag and its digest, so Debian's later fixes reach the image
# only when you change both. `docker buildx imagetools inspect
# public.ecr.aws/docker/library/debian:<tag>` prints a newer tag's digest on its Digest: line.
FROM --platform=linux/arm64 public.ecr.aws/docker/library/debian:bookworm-20261104-slim@sha256:734a72b3d6142a71993b4bc580ca01d8ca687f77a2c422d96a961d3376b179bc

# The tool runner's connection back to CMA is TLS, and the slim image has no CA bundle of its own.
# It takes Amazon Linux 2023's, from that distribution's latest image when you build, so a root
# that Amazon Linux stops trusting leaves this image at its next build. COPY --from only copies
# the file, so the build still runs nothing.
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 --chown=65534:65534 cma-tool-runner /opt/cma/bin/cma-tool-runner
COPY LICENSE NOTICE THIRD-PARTY-NOTICES /opt/cma/
# The working directory of a session that names none. A runtime that mounts session storage at
# /mnt/workspace replaces this empty one.
COPY --chown=65534:65534 workspace/ /mnt/workspace/
COPY --chown=65534:65534 workspace/ /workspace/

# 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
# The AgentCore mode: only InvokeAgentRuntime reaches this container's port.
ENTRYPOINT ["/opt/cma/bin/cma-tool-runner", "agentcore"]
