Skip to content

feat(PROTOTYPE): git build-root for monorepos - #2761

Draft
lengau wants to merge 4 commits into
mainfrom
work/CHARMCRAFT-710-prototype
Draft

feat(PROTOTYPE): git build-root for monorepos#2761
lengau wants to merge 4 commits into
mainfrom
work/CHARMCRAFT-710-prototype

Conversation

@lengau

@lengau lengau commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

CHARMCRAFT-710


  • I've followed the contribution guidelines.
  • I've signed the CLA.
  • I've successfully run make lint && make test.
  • I've added or updated any relevant documentation.
  • In documents I changed, I added a meta description if one was missing.
  • I've updated the relevant release notes.

Workshop and others added 4 commits July 8, 2026 13:27
…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>
Copilot AI review requested due to automatic review settings July 8, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_MONOREPO and pass a use_git_build_root toggle into craft_application.AppMetadata.
  • Update Python/Poetry/uv plugins to copy src/ and lib/ from part_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.

Comment on lines +19 to +28
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
Comment on lines 33 to +40
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
@sinclert-canonical

Copy link
Copy Markdown

👋🏻 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_EXPERIMENTAL_MONOREPO env. var. I am asking because there are a couple of Data Platform teams already playing with this feature:

  • Kafka 4 (see build-charm.yaml workflow).
  • MySQL 8.4 (see build-charm.yaml workflow).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants