Skip to content

MIC: Factor out grub logic for ISO creation. #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions toolkit/tools/pkg/imagecustomizerlib/imagecustomizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,21 +304,22 @@ func CustomizeImage(buildDir string, baseConfigPath string, config *imagecustomi
return nil
}

func convertInputImageToWriteableFormat(ic *ImageCustomizerParameters) (*LiveOSIsoBuilder, error) {
func convertInputImageToWriteableFormat(ic *ImageCustomizerParameters) (*IsoArtifactsStore, error) {
logger.Log.Infof("Converting input image to a writeable format")

if ic.inputIsIso {
inputIsoArtifacts, err := createIsoBuilderFromIsoImage(ic.buildDirAbs, ic.inputImageFile)

inputIsoArtifacts, err := createIsoArtifactStoreFromIsoImage(ic.inputImageFile, filepath.Join(ic.buildDirAbs, "from-iso"))
if err != nil {
return nil, fmt.Errorf("failed to load input iso artifacts:\n%w", err)
return inputIsoArtifacts, fmt.Errorf("failed to create artifacts store from (%s):\n%w", ic.inputImageFile, err)
}

// If the input is a LiveOS iso and there are OS customizations
// defined, we create a writeable disk image so that mic can modify
// it. If no OS customizations are defined, we can skip this step and
// just re-use the existing squashfs.
if ic.customizeOSPartitions {
err = createWriteableImageFromArtifacts(ic.buildDirAbs, inputIsoArtifacts.artifacts.files, ic.rawImageFile)
err = createWriteableImageFromArtifacts(ic.buildDirAbs, inputIsoArtifacts.files, ic.rawImageFile)
if err != nil {
return nil, fmt.Errorf("failed to create writeable image:\n%w", err)
}
Expand Down Expand Up @@ -496,7 +497,7 @@ func customizeOSContents(ic *ImageCustomizerParameters) error {
return nil
}

func convertWriteableFormatToOutputImage(ic *ImageCustomizerParameters, inputIsoArtifacts *LiveOSIsoBuilder) error {
func convertWriteableFormatToOutputImage(ic *ImageCustomizerParameters, inputIsoArtifacts *IsoArtifactsStore) error {
logger.Log.Infof("Converting customized OS partitions into the final image")

// Create final output image file if requested.
Expand Down Expand Up @@ -529,8 +530,8 @@ func convertWriteableFormatToOutputImage(ic *ImageCustomizerParameters, inputIso
return fmt.Errorf("failed to create LiveOS iso image:\n%w", err)
}
} else {
err := inputIsoArtifacts.createImageFromUnchangedOS(ic.configPath, ic.config.Iso, ic.config.Pxe,
ic.outputImageFile, ic.outputPXEArtifactsDir)
err := createImageFromUnchangedOS(ic.buildDirAbs, ic.configPath, ic.config.Iso, ic.config.Pxe,
inputIsoArtifacts, ic.outputImageFile, ic.outputPXEArtifactsDir)
if err != nil {
return fmt.Errorf("failed to create LiveOS iso image:\n%w", err)
}
Expand Down
16 changes: 16 additions & 0 deletions toolkit/tools/pkg/imagecustomizerlib/liveosisoartifactstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ type IsoArtifactsStore struct {
files *IsoFilesStore
}

func (b *IsoArtifactsStore) cleanUp() error {
var err error
if b.files != nil {
cleanupErr := os.RemoveAll(b.files.artifactsDir)
if cleanupErr != nil {
if err != nil {
err = fmt.Errorf("%w:\nfailed to remove (%s): %w", err, b.files.artifactsDir, cleanupErr)
} else {
err = fmt.Errorf("failed to clean-up (%s): %w", b.files.artifactsDir, cleanupErr)
}
}
}

return err
}

func containsGrubNoPrefix(filePaths []string) (bool, error) {
_, bootFilesConfig, err := getBootArchConfig()
if err != nil {
Expand Down
Loading
Loading