Skip to content

Commit

Permalink
refactor: refine the code structure and remove useless directories
Browse files Browse the repository at this point in the history
  • Loading branch information
nqerz committed Aug 8, 2024
1 parent f92e7f2 commit 1e3ec0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
15 changes: 12 additions & 3 deletions pkg/build/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@ package build

import (
"fmt"
"os"
"path/filepath"

"github.com/suse-edge/edge-image-builder/pkg/log"
)


func (b *Builder) Extract() error {
log.Audit("Generating image customization components...")

if err := b.configureCombustion(b.context); err != nil {
log.Audit("Error configuring customization components, check the logs under the build directory for more information.")
log.Audit("Error configuring customization components, check the logs under the extract directory for more information.")
return fmt.Errorf("configuring combustion: %w", err)
}


log.Audit("Extract complete!")
return nil
}

func SetupExtractArtifactsDirectory(buildDir string) (artefactsDir string, err error) {
artefactsDir = filepath.Join(buildDir, "artefacts")
if err = os.MkdirAll(artefactsDir, os.ModePerm); err != nil {
return "", fmt.Errorf("creating an artefacts directory: %w", err)

Check failure on line 26 in pkg/build/extract.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` `-r 'interface{} -> any'` (gofmt)
}

return artefactsDir, nil

Check failure on line 29 in pkg/build/extract.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
}
11 changes: 4 additions & 7 deletions pkg/cli/build/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ func Extract(_ *cli.Context) error {
os.Exit(1)
}

combustionDir, artefactsDir, err := build.SetupCombustionDirectory(buildDir)
artefactsDir, err := build.SetupExtractArtifactsDirectory(buildDir)
if err != nil {
log.Auditf("Setting up the combustion directory failed. %s", checkExtractLogMessage)
zap.S().Fatalf("Failed to create combustion directories: %s", err)
log.Auditf("Setting up the extract artifacts directory failed. %s", checkExtractLogMessage)
zap.S().Fatalf("Failed to create extract artifacts directories: %s", err)
}

ctx := buildContext(buildDir, combustionDir, artefactsDir, args.ConfigDir, imageDefinition)

ctx.ImageDefinition.OperatingSystem.Packages = image.Packages{}
ctx := buildContext(buildDir, "", artefactsDir, args.ConfigDir, imageDefinition)
if cmdErr = validateImageDefinition(ctx); cmdErr != nil {
cmd.LogError(cmdErr, checkExtractLogMessage)
os.Exit(1)
Expand Down Expand Up @@ -92,7 +90,6 @@ func Extract(_ *cli.Context) error {
return nil
}


// If the image definition requires it, starts the necessary services, returning an error in the event of failure.
func bootstrapExtractDependencyServices(ctx *image.Context, rootDir string) *cmd.Error {
if combustion.IsEmbeddedArtifactRegistryConfigured(ctx) {
Expand Down

0 comments on commit 1e3ec0c

Please sign in to comment.