-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toolkit: Use systemd-detect-virt instead of /.dockerenv to detect container builds. #11039
base: 3.0-dev
Are you sure you want to change the base?
Toolkit: Use systemd-detect-virt instead of /.dockerenv to detect container builds. #11039
Conversation
c42b604
to
c61f7b6
Compare
Pipe line to validate this keeps working: https://dev.azure.com/mariner-org/mariner/_git/CBL-Mariner-Pipelines/pullrequest/21071 |
logger.Log.Warnf("Failed to check if /.dockerenv exists: %s", err) | ||
} | ||
isRegularBuild = !isContainerBuild | ||
message := []string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note sure what "PrintMessageBox" is doing, but it seems to me the code would be a little simpler here if we just emitted the "Failed to detect" message before we call "checkIfContainerDockerEnvFile" first, then composed the result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PrintMessageBox is a really obvious warning to the user with big borders. I try to add these when I think there is a non-obvious thing that the user should fix that might cause confusing errors later. I think I see what you mean with the ordering though, I'll give it a go.
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
pipeline PR soon): https://dev.azure.com/mariner-org/mariner/_build/results?buildId=675755&view=results