Toolkit: Use systemd-detect-virt instead of /.dockerenv to detect container builds. #11039
+171
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Merge Checklist
All boxes should be checked before merging the PR (just tick any boxes which don't apply to this PR)
*-static
subpackages, etc.) have had theirRelease
tag incremented../cgmanifest.json
,./toolkit/scripts/toolchain/cgmanifest.json
,.github/workflows/cgmanifest.json
)./LICENSES-AND-NOTICES/SPECS/data/licenses.json
,./LICENSES-AND-NOTICES/SPECS/LICENSES-MAP.md
,./LICENSES-AND-NOTICES/SPECS/LICENSE-EXCEPTIONS.PHOTON
)*.signatures.json
filessudo make go-tidy-all
andsudo make go-test-coverage
passSummary
There have been several issues with a mismatch between the build environment and the detected state by the toolkit. When running in docker, the chroots generally need to be configured externally with their mounts and re-used. This can be done via setting
CHROOT_DIR=/path/to/reusable/chroots
, and if the toolkit thinks it's in a container, it will switch modes.See https://github.com/microsoft/azurelinux-tutorials/tree/main/build-in-container for more details.
Some builds are currently failing because what is ostensibly a container environment does not have
/.dockerenv
present.In the opposite direction, there are also situations where WSL images (which should work fine as a normal build) are reporting as docker because they have a
/.dockerenv
file present.systemd
has a tool (systemd-detect-virt
) which is designed to detect what sort of virtualization is being used to run the current environment. Instead of designing a new system to re-implement this behavior, we can just use this tool. We already have an implicit build dependency onsystemd
(we run the docker service etc.) so adding it as an explicit requirement shouldn't change anything.Also, to help people self-diagnose, sanity check the configurations and warn the user:
systemd-detect-virt
tool is not present, print a warning but fallback to the old behavior.To validate this we will need to add a new testcase to the toolkit sanity test pipeline that ensures the chroots keep working.
We will need to back-port this to 2.0 as well.
Change Log
systemd-detect-virt
over/.dockerenv
for container detectionDoes this affect the toolchain?
NO
Associated issues
Test Methodology