feat(PROTOTYPE): git build-root for monorepos - #2761
Conversation
…REPO When CHARMCRAFT_EXPERIMENTAL_MONOREPO is set to a truthy value, charmcraft passes use_git_build_root=True to craft-application, which mounts the git repository root as the build root. This enables charms in a monorepo to access shared local dependencies (e.g. ../common) during pack. CHARMCRAFT-710 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When a charm uses a source-subdir (as happens with root_dir/monorepo builds), the charm files live at part_build_subdir not part_build_dir. Fix get_charm_copy_commands in all three charm plugins (poetry, python, uv) to use part_build_subdir so that src/, lib/ etc. are found correctly. CHARMCRAFT-710 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Move microk8s setup out of the charms/ suite-level prepare and into k8s-operator/task.yaml (the only test that uses a k8s Juju controller) so monorepo tests don't require microk8s. - Add tests/spread/charms/monorepo/ with four variants covering mysql-operators and mysql-router-operators × machines + kubernetes. - Add tests/spread/commands/git-build-root/ as a lightweight unit-level smoke test for the feature flag. CHARMCRAFT-710 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ype branches Temporarily pin both dependencies to the work/CHARMCRAFT-710-prototype branches while the upstream PRs are in review. CHARMCRAFT-710 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR prototypes “git build-root” support for monorepos by wiring a new experimental flag through Charmcraft into the underlying craft tooling, and adjusting packaging behavior/tests to validate building from a charm subdirectory within a larger git repo.
Changes:
- Add
CHARMCRAFT_EXPERIMENTAL_MONOREPOand pass ause_git_build_roottoggle intocraft_application.AppMetadata. - Update Python/Poetry/uv plugins to copy
src/andlib/frompart_build_subdir(to work correctly when the build root differs from the part source subdir). - Add spread coverage for monorepo packing and a synthetic git-root build scenario; adjust MicroK8s setup to be task-local for the k8s-operator spread task; switch uv resolution to git sources for craft-* dependencies.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
uv.lock |
Locks craft-* dependencies from git sources/branches for the prototype. |
pyproject.toml |
Adds [tool.uv.sources] entries to pull craft-* libs from git during development/locking. |
charmcraft/const.py |
Introduces EXPERIMENTAL_MONOREPO_ENV_VAR constant. |
charmcraft/application/main.py |
Reads CHARMCRAFT_EXPERIMENTAL_MONOREPO and passes use_git_build_root into app metadata. |
charmcraft/parts/plugins/_python.py |
Copies src/ and lib/ from part_build_subdir instead of part_build_dir. |
charmcraft/parts/plugins/_poetry.py |
Copies src/ and lib/ from part_build_subdir instead of part_build_dir. |
charmcraft/parts/plugins/_uv.py |
Copies src/ and lib/ from part_build_subdir instead of part_build_dir. |
tests/spread/commands/git-build-root/task.yaml |
Adds a synthetic monorepo test that depends on git-root build behavior to include sibling sources. |
tests/spread/charms/monorepo/task.yaml |
Adds an external-monorepo spread test validating packing from a subdir with monorepo mode enabled. |
tests/spread/charms/k8s-operator/task.yaml |
Moves MicroK8s bootstrap/setup into the task prepare. |
spread.yaml |
Removes MicroK8s setup from the tests/spread/charms/ suite-level prepare. |
| prepare: | | ||
| git clone --depth=1 https://github.com/canonical/"${REPO}".git /tmp/"${REPO}" | ||
| python3 - << 'EOF' | ||
| import os, yaml, pathlib | ||
| p = pathlib.Path(f'/tmp/{os.environ["REPO"]}/{os.environ["CHARM_SUBDIR"]}/charmcraft.yaml') | ||
| d = yaml.safe_load(p.read_text()) | ||
| d["parts"].pop("files", None) | ||
| d["parts"].get("charm-poetry", {}).pop("override-build", None) | ||
| p.write_text(yaml.dump(d)) | ||
| EOF |
| prepare: | | ||
| snap install microk8s --channel=1.28-strict/stable | ||
| microk8s enable hostpath-storage | ||
| microk8s enable dns | ||
| snap alias microk8s.kubectl kubectl | ||
| if ! juju controllers | grep -q k8s; then | ||
| juju bootstrap microk8s k8s | ||
| fi |
|
👋🏻 Hey @lengau, is there any timeline for this to get merged? According to the ST178 spec, it will require a full major version to have this natively supported into charmcraft, but my question is more about a snap store revision that already supports the |
CHARMCRAFT-710
make lint && make test.