Skip to content

Commit 631b0da

Browse files
committed
build: mount build cache directories
so `$ bob build` (when ran on host) can be faster on subsequent invocations
1 parent 7342985 commit 631b0da

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

cmd/bob/build.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ func runBuilder(builder bobfile.BuilderSpec, buildCtx *BuildContext, opDesc stri
7272
"--volume", "/tmp/build:/tmp/build", // cannot map to /tmp because at least apt won't work (permission issues?)
7373
}
7474

75+
baseImageConf, err := loadNonOptionalBaseImageConf(builder)
76+
if err == nil { // it's optional here. used to mount the cache directories
77+
for _, pathContainer := range baseImageConf.PathsToCache {
78+
pathHostSide := makeCachePathHostSide(pathContainer)
79+
buildArgs = append(buildArgs, fmt.Sprintf("--mount=type=bind,source=%s,destination=%s", pathHostSide, pathContainer))
80+
}
81+
}
82+
7583
if builder.Workdir != "" {
7684
buildArgs = append(buildArgs, "--workdir", builder.Workdir)
7785
}

cmd/bob/devshim.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ func makeCacheDir(dir string) error {
221221
return err
222222
}
223223

224-
// "/go/pkg" => "/tmp/build/go/pkg"
225-
cacheCounterpart := filepath.Join("/tmp/build/", dir)
224+
cacheCounterpart := makeCachePathHostSide(dir)
226225

227226
if err := os.MkdirAll(cacheCounterpart, 0755); err != nil {
228227
return err
@@ -231,6 +230,11 @@ func makeCacheDir(dir string) error {
231230
return os.Symlink(cacheCounterpart, dir)
232231
}
233232

233+
// "/go/pkg" => "/tmp/build/go/pkg" (at host-side)
234+
func makeCachePathHostSide(pathInContainer string) string {
235+
return filepath.Join("/tmp/build/", pathInContainer)
236+
}
237+
234238
func readShimConfig() (*shimConfig, error) {
235239
shimConf := &shimConfig{}
236240
return shimConf, jsonfile.ReadDisallowUnknownFields(filepath.Join(shimDataDirContainer, shimConfigFile), shimConf)

0 commit comments

Comments
 (0)