toolkit only - use local /run folder in chroot instead of mounted tmpfs (#2435)

* toolkit - use local /run folder in chroot instead of mounted tmpfs

* address PR comments

* address PR comments

* address PR comments

Co-authored-by: Nicolas Guibourge <nicolasg@microsoft.com>
This commit is contained in:
nicolas guibourge 2022-03-09 11:15:49 -08:00 коммит произвёл GitHub
Родитель e5f3e83bdf
Коммит 484170b5be
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 21 добавлений и 5 удалений

Просмотреть файл

@ -179,30 +179,38 @@ func GetRpmsDir(chrootDir string, proposedDir string) string {
return filepath.Join(chrootDir, "localrpms")
}
// CleanupDockerChroot: Docker based only, clean chroot => delete everything but the folders listed
// CleanupDockerChroot: Docker based only, clean chroot =>
// 1) delete everything but the folders listed
// these folders are the ones mounted in docker run command (-v option)
// 2) create empty folders
// these folders are required by chroot (e.g.: /run) and needs to be created empty
// to not inherit anything from previous build
func CleanupDockerChroot(chroot string) (err error) {
var folderToKeep = []string{
"dev",
"proc",
"run",
"localrpms",
"upstream-cached-rpms",
"sys",
chrootUse,
}
var folderToCreate = []string{
"run",
}
logger.Log.Debugf("cleanup Chroot -> %s", chroot)
rootFolder, err := os.Open(chroot)
if err != nil {
logger.Log.Warnf("Open chroot %s failed - %v", chroot, err)
logger.Log.Warnf("Open chroot %s failed - %s", chroot, err)
return err
}
defer rootFolder.Close()
names, err := rootFolder.Readdirnames(-1)
if err != nil {
logger.Log.Warnf("Reading files and folders under chroot %s failed - %v", chroot, err)
logger.Log.Warnf("Reading files and folders under chroot %s failed - %s", chroot, err)
return err
}
@ -217,10 +225,18 @@ func CleanupDockerChroot(chroot string) (err error) {
if toDelete {
err = os.RemoveAll(filepath.Join(chroot, name))
if err != nil {
logger.Log.Warnf("Removing files in chroot %s failed: %v", chroot, err)
logger.Log.Warnf("Removing files in chroot %s failed: %s", chroot, err)
}
}
}
// create some folder(s) once chroot has been cleaned up
for _, folder := range folderToCreate {
err = os.Mkdir(filepath.Join(chroot, folder), os.ModePerm)
if err != nil {
logger.Log.Warnf("Creation of %s folder in chroot %s failed: %s", folder, chroot, err)
}
}
return
}