Skip to content

Commit bdc79f1

Browse files
nicogbgNicolas Guibourge
andcommitted
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 <[email protected]>
1 parent a62b073 commit bdc79f1

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

toolkit/tools/internal/buildpipeline/buildpipeline.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,30 +179,38 @@ func GetRpmsDir(chrootDir string, proposedDir string) string {
179179
return filepath.Join(chrootDir, "localrpms")
180180
}
181181

182-
// CleanupDockerChroot: Docker based only, clean chroot => delete everything but the folders listed
182+
// CleanupDockerChroot: Docker based only, clean chroot =>
183+
// 1) delete everything but the folders listed
184+
// these folders are the ones mounted in docker run command (-v option)
185+
// 2) create empty folders
186+
// these folders are required by chroot (e.g.: /run) and needs to be created empty
187+
// to not inherit anything from previous build
183188
func CleanupDockerChroot(chroot string) (err error) {
184189
var folderToKeep = []string{
185190
"dev",
186191
"proc",
187-
"run",
188192
"localrpms",
189193
"upstream-cached-rpms",
190194
"sys",
191195
chrootUse,
192196
}
193197

198+
var folderToCreate = []string{
199+
"run",
200+
}
201+
194202
logger.Log.Debugf("cleanup Chroot -> %s", chroot)
195203

196204
rootFolder, err := os.Open(chroot)
197205
if err != nil {
198-
logger.Log.Warnf("Open chroot %s failed - %v", chroot, err)
206+
logger.Log.Warnf("Open chroot %s failed - %s", chroot, err)
199207
return err
200208
}
201209

202210
defer rootFolder.Close()
203211
names, err := rootFolder.Readdirnames(-1)
204212
if err != nil {
205-
logger.Log.Warnf("Reading files and folders under chroot %s failed - %v", chroot, err)
213+
logger.Log.Warnf("Reading files and folders under chroot %s failed - %s", chroot, err)
206214
return err
207215
}
208216

@@ -217,10 +225,18 @@ func CleanupDockerChroot(chroot string) (err error) {
217225
if toDelete {
218226
err = os.RemoveAll(filepath.Join(chroot, name))
219227
if err != nil {
220-
logger.Log.Warnf("Removing files in chroot %s failed: %v", chroot, err)
228+
logger.Log.Warnf("Removing files in chroot %s failed: %s", chroot, err)
221229
}
222230
}
223231
}
224232

233+
// create some folder(s) once chroot has been cleaned up
234+
for _, folder := range folderToCreate {
235+
err = os.Mkdir(filepath.Join(chroot, folder), os.ModePerm)
236+
if err != nil {
237+
logger.Log.Warnf("Creation of %s folder in chroot %s failed: %s", folder, chroot, err)
238+
}
239+
}
240+
225241
return
226242
}

0 commit comments

Comments
 (0)