debian-forge-cli/cmd/image-builder/build.go
Simon de Vlieger 34de7d7ce5 build: directory creation
This now precreates the directory as it's possible that the directory
doesn't exist yet at this point; see #94.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-01-29 11:56:14 +00:00

43 lines
1 KiB
Go

package main
import (
"fmt"
"os"
"path/filepath"
"github.com/osbuild/images/pkg/imagefilter"
"github.com/osbuild/images/pkg/osbuild"
)
type buildOptions struct {
OutputDir string
StoreDir string
WriteManifest bool
}
func buildImage(res *imagefilter.Result, osbuildManifest []byte, opts *buildOptions) error {
if opts == nil {
opts = &buildOptions{}
}
// XXX: support output filename via commandline (c.f.
// https://github.com/osbuild/images/pull/1039)
if opts.OutputDir == "" {
opts.OutputDir = outputNameFor(res)
}
if opts.WriteManifest {
p := filepath.Join(opts.OutputDir, fmt.Sprintf("%s.osbuild-manifest.json", outputNameFor(res)))
if err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {
return err
}
if err := os.WriteFile(p, osbuildManifest, 0644); err != nil {
return err
}
}
// XXX: support stremaing via images/pkg/osbuild/monitor.go
_, err := osbuild.RunOSBuild(osbuildManifest, opts.StoreDir, opts.OutputDir, res.ImgType.Exports(), nil, nil, false, osStderr)
return err
}