main: add new --store argument to image-builder build
This commit adds a new `--store` flag to the `image-builder build` command. This is used to specify a osbuild store directory to store the intermediate build tree for faster rebuilding. It is also useful for the container version of `image-builder-cli` to allow mapping the users store into the container.
This commit is contained in:
parent
e5b3ccd6ed
commit
b3f9fb88f1
3 changed files with 15 additions and 5 deletions
|
|
@ -8,8 +8,7 @@ import (
|
|||
"github.com/osbuild/images/pkg/osbuild"
|
||||
)
|
||||
|
||||
func buildImage(res *imagefilter.Result, osbuildManifest []byte) error {
|
||||
osbuildStoreDir := ".store"
|
||||
func buildImage(res *imagefilter.Result, osbuildManifest []byte, osbuildStoreDir string) error {
|
||||
// XXX: support output dir via commandline
|
||||
// XXX2: support output filename via commandline (c.f.
|
||||
// https://github.com/osbuild/images/pull/1039)
|
||||
|
|
|
|||
|
|
@ -88,8 +88,12 @@ func cmdManifest(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
func cmdBuild(cmd *cobra.Command, args []string) error {
|
||||
var mf bytes.Buffer
|
||||
storeDir, err := cmd.Flags().GetString("store")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var mf bytes.Buffer
|
||||
// XXX: check env here, i.e. if user is root and osbuild is installed
|
||||
res, err := cmdManifestWrapper(cmd, args, &mf, func(archStr string) error {
|
||||
if archStr != arch.Current().String() {
|
||||
|
|
@ -101,7 +105,7 @@ func cmdBuild(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return buildImage(res, mf.Bytes())
|
||||
return buildImage(res, mf.Bytes(), storeDir)
|
||||
}
|
||||
|
||||
func run() error {
|
||||
|
|
@ -154,6 +158,7 @@ operating sytsems like centos and RHEL with easy customizations support.`,
|
|||
Args: cobra.RangeArgs(1, 2),
|
||||
}
|
||||
buildCmd.Flags().AddFlagSet(manifestCmd.Flags())
|
||||
buildCmd.Flags().String("store", ".store", `osbuild store directory to cache intermediata build artifacts"`)
|
||||
rootCmd.AddCommand(buildCmd)
|
||||
|
||||
return rootCmd.Execute()
|
||||
|
|
|
|||
|
|
@ -239,11 +239,13 @@ func TestBuildIntegrationHappy(t *testing.T) {
|
|||
restore := main.MockNewRepoRegistry(testrepos.New)
|
||||
defer restore()
|
||||
|
||||
tmpdir := t.TempDir()
|
||||
restore = main.MockOsArgs([]string{
|
||||
"build",
|
||||
"qcow2",
|
||||
makeTestBlueprint(t, testBlueprint),
|
||||
"--distro", "centos-9",
|
||||
"--store", tmpdir,
|
||||
})
|
||||
defer restore()
|
||||
|
||||
|
|
@ -256,8 +258,12 @@ func TestBuildIntegrationHappy(t *testing.T) {
|
|||
|
||||
// ensure osbuild was run exactly one
|
||||
assert.Equal(t, 1, len(fakeOsbuildCmd.Calls()))
|
||||
// and we passed the output dir
|
||||
osbuildCall := fakeOsbuildCmd.Calls()[0]
|
||||
// --store is passed correctly to osbuild
|
||||
storePos := slices.Index(osbuildCall, "--store")
|
||||
assert.True(t, storePos > -1)
|
||||
assert.Equal(t, tmpdir, osbuildCall[storePos+1])
|
||||
// and we passed the output dir
|
||||
outputDirPos := slices.Index(osbuildCall, "--output-directory")
|
||||
assert.True(t, outputDirPos > -1)
|
||||
assert.Equal(t, "centos-9-qcow2-x86_64", osbuildCall[outputDirPos+1])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue