aws / aws/bedrock-agentcore-starter-toolkit

direct_code_deploy ignores the project .dockerignore (only the bundled template is honored)

Open
#549 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
508
Forks
155
Avg merge
8h 50m
Merged PRs (30d)
4

Description

## Summary

For `direct_code_deploy`, the source-packaging step ignores the project's own `.dockerignore` (and `.gitignore`). The ignore patterns are read **only** from the toolkit's bundled `utils/runtime/templates/dockerignore.template`, so there is no supported way to exclude project-specific directories from the uploaded `code.zip`. Any large directory not enumerated in the bundled template (e.g. `.claude/`, caches, data dirs, extra virtualenvs with non-standard names) gets packaged and uploaded.

## Where

Two code paths compute the ignore list for direct code deploy, and both hardcode the bundled template:

- `utils/runtime/package.py` → `CodeZipPackager._get_ignore_patterns()` (local zip build)
- `services/codebuild.py` → `CodeBuildService._parse_dockerignore()` — docstring even states: *"Always uses the dockerignore.template to ensure consistent file filtering during zip creation, regardless of source_path configuration."*

```python
def _get_ignore_patterns(self) -> List[str]:
# reads files("bedrock_agentcore_starter_toolkit")
# .joinpath("utils/runtime/templates/dockerignore.template")
# ...no project-level .dockerignore is consulted or merged
```

The `.dockerignore` that `operations/runtime/configure.py` / `utils/runtime/container.py` generate is only consumed by **container** deployments (Docker build context) — it is not read by the direct-code-deploy zip packagers.

There is no CLI flag (`agentcore deploy --help` has no ignore/exclude option), no `.bedrock_agentcore.yaml` key, and no environment variable to add patterns.

## Impact

A repo that keeps a large directory under `source_path` which isn't in the bundled template gets it silently zipped and uploaded to S3. In our case a 1.6 GB directory (git worktrees under `.claude/`) would have been packaged; the effective source is ~9 MB. The only workaround today is editing the installed `dockerignore.template` inside `site-packages`, which is lost on every `pip install` / fresh venv.

## Repro

1. `agentcore configure` a Python agent with `deployment_type: direct_code_deploy`.
2. Add a large directory not in the bundled template (e.g. `.claude/`, `data/`, `notebooks/`) under `source_path`.
3. Create a project-level `.dockerignore` containing that directory.
4. `agentcore deploy` → the directory is still included in `code.zip` (the project `.dockerignore` is ignored).

## Proposed fix

Have `_get_ignore_patterns()` (and `CodeBuildService._parse_dockerignore()`) **merge** the project's `.dockerignore` (resolved from `source_path` / build context) on top of the bundled template defaults. This matches Docker's own behavior and the least-surprise expectation that a `.dockerignore` in the project root is honored.

Alternatively (or additionally): support an explicit ignore list in `.bedrock_agentcore.yaml` and/or an `agentcore deploy --ignore ` flag.

## Environment

- `bedrock-agentcore-starter-toolkit` 0.3.3 (behavior confirmed identical on the current `main`, 0.3.10 — `_get_ignore_patterns` is unchanged and still reads only the bundled template)
- Deployment type: `direct_code_deploy`
- Python 3.13, macOS

Contributor guide

Open the contributing guide

Research direction

Start with utils/runtime/package.py at CodeZipPackager._get_ignore_patterns() and services/codebuild.py at CodeBuildService._parse_dockerignore(), then reproduce the direct_code_deploy packaging flow with a project-level .dockerignore. Done means project patterns are honored in both code.zip paths while the bundled dockerignore.template defaults remain effective.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.