Skip to content

[BUG] CodeBuild Fails When Entrypoint is in Subdirectory: Incorrect Build Context #398

@DennisTraub

Description

@DennisTraub

Summary

When using agentcore configure with an entrypoint located in a subdirectory (e.g., server/server.py), the Docker build fails during CodeBuild with the error "/server": not found. The root cause is that the generated Dockerfile attempts to COPY a subdirectory that doesn't exist in the Docker build context.

Environment

  • Tool: bedrock-agentcore-starter-toolkit (via uv run agentcore)
  • Platform: Windows
  • Deployment Type: Container

Steps to Reproduce

  1. Create a parent project with agentcore:
uv init --bare
uv add bedrock-agentcore-starter-toolkit
  1. Create a subdirectory for the deployable:
mkdir server && cd server
uv init --bare --no-workspace
uv add mcp
  1. Create a simple MCP server (server/server.py):
from mcp.server.fastmcp import FastMCP

mcp = FastMCP(name="EchoServer", stateless_http=True)

def main():
    mcp.run(transport="streamable-http")

if __name__ == "__main__":
    main()
  1. Return to parent directory and configure agentcore:
cd ..
uv run agentcore configure \
   --entrypoint server/server.py \
   --requirements-file server/pyproject.toml \
   --non-interactive --disable-memory --disable-otel \
   --name test_server --protocol MCP \
   --deployment-type container
  1. Launch the agent:
uv run agentcore launch --agent test_server

Expected Behavior

The CodeBuild project should succeed and the container should be deployed to ECR.

Actual Behavior

The tookit fails with:

🔄 COMPLETED started (total: 12s)
⠋ Launching Bedrock AgentCore...❌ Build failed during COMPLETED phase
❌ CodeBuild failed with status: FAILED

The CodeBuild project fails with:

#6 ERROR: failed to calculate checksum of ref 3dbb0167-26e0-4aa8-afd6-f9e595d75983::wes51ujh9l3i1ahked3byxdc7: "/server": not found
...
------
> [3/6] COPY server server:
------
Dockerfile:15
--------------------
13 \|
14 \|
15 \| >>> COPY server server
16 \|     # Install from pyproject.toml directory
17 \|     RUN cd server && uv pip install .
--------------------
ERROR: failed to build: failed to solve: failed to compute cache key: failed to calculate checksum of ref 3dbb0167-26e0-4aa8-afd6-f9e595d75983::wes51ujh9l3i1ahked3byxdc7: "/server": not found
Docker build failed

Root Cause Analysis

The issue occurs because of a mismatch between the Docker build context and the Dockerfile's COPY instruction:

  1. Build Context: When agentcore detects the entrypoint is in a subdirectory (server/server.py), it sets source_path to the subdirectory:

    source_path: C:\Users\traubd\code\GitHub\code\examples\temp\server
  2. Dockerfile Generation: The generated Dockerfile attempts to copy the subdirectory relative to the build context:

    COPY server server
    RUN cd server && uv pip install .
  3. The Problem: Since the build context is already set to the server directory, there is no server subdirectory to copy. The Dockerfile is trying to copy server/server which doesn't exist.

Proposed Solution

When the source_path is set to a subdirectory, the Dockerfile should copy from the current directory (.) instead of trying to copy a subdirectory that doesn't exist in the build context.

The Dockerfile generation logic should be updated to:

  • Detect when source_path points to a subdirectory
  • Generate COPY . . (or copy specific files) instead of COPY <subdirectory> <subdirectory>
  • Adjust the RUN command to install from the current directory: RUN uv pip install .

Example corrected Dockerfile:

FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
WORKDIR /app

ENV UV_SYSTEM_PYTHON=1 \
    UV_COMPILE_BYTECODE=1 \
    UV_NO_PROGRESS=1 \
    PYTHONUNBUFFERED=1 \
    DOCKER_CONTAINER=1

# Copy and install from current directory (which is already the server directory)
COPY . .
RUN uv pip install .

# Create non-root user
RUN useradd -m -u 1000 bedrock_agentcore
USER bedrock_agentcore

EXPOSE 9000 8000 8080

CMD ["python", "-m", "server"]

Workaround

Currently, users must place their files in the root directory of the project rather than in a subdirectory.

Additional Context

This issue affects common project structures where developers organize their code into subdirectories (e.g., server/, src/, app/) rather than placing everything in the root directory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions