44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package plan
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"metis/pkg/image"
|
|
"metis/pkg/inventory"
|
|
"metis/pkg/writer"
|
|
)
|
|
|
|
// BuildImageFile materializes a fully injected raw image for a node.
|
|
func BuildImageFile(ctx context.Context, inv *inventory.Inventory, nodeName, cacheDir, output string) error {
|
|
p, err := Build(inv, nodeName, output, cacheDir)
|
|
if err != nil {
|
|
return fmt.Errorf("build plan: %w", err)
|
|
}
|
|
_, class, err := inv.FindNode(nodeName)
|
|
if err != nil {
|
|
return fmt.Errorf("load node class: %w", err)
|
|
}
|
|
|
|
cacheImage := filepath.Join(cacheDir, filepath.Base(p.Image))
|
|
if err := image.Download(p.Image, cacheImage); err != nil {
|
|
return fmt.Errorf("download image: %w", err)
|
|
}
|
|
if err := image.VerifyChecksum(cacheImage, class.Checksum); err != nil {
|
|
return fmt.Errorf("verify checksum: %w", err)
|
|
}
|
|
if err := writer.WriteImage(ctx, cacheImage, output); err != nil {
|
|
return fmt.Errorf("copy base image: %w", err)
|
|
}
|
|
|
|
files, err := Files(inv, nodeName)
|
|
if err != nil {
|
|
return fmt.Errorf("resolve files: %w", err)
|
|
}
|
|
if err := image.InjectRootFS(output, files); err != nil {
|
|
return fmt.Errorf("inject rootfs: %w", err)
|
|
}
|
|
return nil
|
|
}
|