Skip to content

Commit

Permalink
Add support for /run/.containerenv
Browse files Browse the repository at this point in the history
Container processes want to check for the existence of this file
to determine if they are running inside of a container.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Sep 6, 2019
1 parent 4da1d5d commit bc99264
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ func (b *Builder) Run(command []string, options RunOptions) error {
}
bindFiles["/etc/resolv.conf"] = resolvFile
}
// Empty file, so no need to recreate if it exists
if _, ok := bindFiles["/run/.containerenv"]; !ok {
// Empty string for now, but we may consider populating this later
containerenvPath := filepath.Join(path, "/run/.containerenv")
emptyFile, err := os.Create(containerenvPath)
if err != nil {
return err
}
emptyFile.Close()
bindFiles["/run/.containerenv"] = containerenvPath
}

err = b.setupMounts(mountPoint, spec, path, options.Mounts, bindFiles, volumes, b.CommonBuildOpts.Volumes, b.CommonBuildOpts.ShmSize, namespaceOptions)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,13 @@ function configure_and_check_user() {
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
run_buildah 42 run ${cid} sh -c 'exit 42'
}

@test "Verify /run/.containerenv exist" {
if ! which runc ; then
skip "no runc in PATH"
fi
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
# test a standard mount to /run/.containerenv
run_buildah --log-level=error run $cid ls -1 /run/.containerenv
expect_output --substring "/run/.containerenv"
}

0 comments on commit bc99264

Please sign in to comment.