Skip to content

Commit

Permalink
progress: set --cache-max-size in osbuild
Browse files Browse the repository at this point in the history
This commit allows controlling the `osbuild --cache-max-size`
option. By default it will set the cache to 20GiB but allows
this to be controlled by the user.

Thanks to Simon for raising this.
  • Loading branch information
mvo5 committed Jan 27, 2025
1 parent f4ee689 commit 6bda3d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bib/pkg/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/mattn/go-isatty"
"github.com/sirupsen/logrus"

"github.com/osbuild/images/pkg/datasizes"
"github.com/osbuild/images/pkg/osbuild"
)

Expand Down Expand Up @@ -319,6 +320,8 @@ type OSBuildOptions struct {

// BuildLog writes the osbuild output to the given writer
BuildLog io.Writer

CacheMaxSize int64
}

func writersForOSBuild(pb ProgressBar, opts *OSBuildOptions, internalBuildLog io.Writer) (osbuildStdout io.Writer, osbuildStderr io.Writer) {
Expand Down Expand Up @@ -377,12 +380,17 @@ func RunOSBuild(pb ProgressBar, manifest []byte, exports []string, opts *OSBuild
defer rp.Close()
defer wp.Close()

cacheMaxSize := int64(20 * datasizes.GiB)
if opts.CacheMaxSize != 0 {
cacheMaxSize = opts.CacheMaxSize
}
cmd := exec.Command(
osbuildCmd,
"--store", opts.StoreDir,
"--output-directory", opts.OutputDir,
"--monitor=JSONSeqMonitor",
"--monitor-fd=3",
fmt.Sprintf("--cache-max-size=%v", cacheMaxSize),
"-",
)
for _, export := range exports {
Expand Down
18 changes: 18 additions & 0 deletions bib/pkg/progress/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,21 @@ func TestRunOSBuildWithProgressIncorrectJSON(t *testing.T) {
assert.EqualError(t, err, `errors parsing osbuild status:
cannot scan line "invalid-json": invalid character 'i' looking for beginning of value`)
}

func TestRunOSBuildCacheMaxSize(t *testing.T) {
fakeOsbuildBinary := makeFakeOsbuild(t, `echo "$@" > "$0".cmdline`)
restore := progress.MockOsbuildCmd(fakeOsbuildBinary)
defer restore()

pbar, err := progress.New("debug")
assert.NoError(t, err)

osbuildOpts := &progress.OSBuildOptions{
CacheMaxSize: 77,
}
err = progress.RunOSBuild(pbar, []byte(`{"fake":"manifest"}`), nil, osbuildOpts)
assert.NoError(t, err)
cmdline, err := os.ReadFile(fakeOsbuildBinary + ".cmdline")
assert.NoError(t, err)
assert.Contains(t, string(cmdline), "--cache-max-size=77")
}

0 comments on commit 6bda3d8

Please sign in to comment.