Skip to content

Commit

Permalink
Merge pull request #406 from ktpv/i386_fix
Browse files Browse the repository at this point in the history
inspect-builder throws error with missing remote and local builder
  • Loading branch information
jromero authored Dec 9, 2019
2 parents 2dd526c + 01e2bf9 commit 3b65cd7
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 241 deletions.
31 changes: 18 additions & 13 deletions internal/commands/inspect_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,33 @@ func InspectBuilder(logger logging.Logger, cfg config.Config, client PackClient)
imageName = args[0]
}

presentRemote, remoteOutput, remoteWarnings, remoteErr := inspectBuilderOutput(client, cfg, imageName, false)
presentLocal, localOutput, localWarnings, localErr := inspectBuilderOutput(client, cfg, imageName, true)

if !presentRemote && !presentLocal {
return errors.New(fmt.Sprintf("Unable to find builder '%s' locally or remotely.\n", imageName))
}

if imageName == cfg.DefaultBuilder {
logger.Infof("Inspecting default builder: %s\n", style.Symbol(imageName))
} else {
logger.Infof("Inspecting builder: %s\n", style.Symbol(imageName))
}

remoteOutput, warnings, err := inspectBuilderOutput(client, cfg, imageName, false)
if err != nil {
logger.Error(err.Error())
if remoteErr != nil {
logger.Error(remoteErr.Error())
} else {
logger.Infof("\nREMOTE:\n%s\n", remoteOutput)
for _, w := range warnings {
for _, w := range remoteWarnings {
logger.Warn(w)
}
}

localOutput, warnings, err := inspectBuilderOutput(client, cfg, imageName, true)
if err != nil {
logger.Error(err.Error())
if localErr != nil {
logger.Error(localErr.Error())
} else {
logger.Infof("\nLOCAL:\n%s\n", localOutput)
for _, w := range warnings {
for _, w := range localWarnings {
logger.Warn(w)
}
}
Expand All @@ -69,28 +74,28 @@ func InspectBuilder(logger logging.Logger, cfg config.Config, client PackClient)
return cmd
}

func inspectBuilderOutput(client PackClient, cfg config.Config, imageName string, local bool) (output string, warning []string, err error) {
func inspectBuilderOutput(client PackClient, cfg config.Config, imageName string, local bool) (present bool, output string, warning []string, err error) {
source := "remote"
if local {
source = "local"
}

info, err := client.InspectBuilder(imageName, local)
if err != nil {
return "", nil, errors.Wrapf(err, "inspecting %s image '%s'", source, imageName)
return true, "", nil, errors.Wrapf(err, "inspecting %s image '%s'", source, imageName)
}

if info == nil {
return "(not present)", nil, nil
return false, "(not present)", nil, nil
}

var buf bytes.Buffer
warnings, err := generateBuilderOutput(&buf, imageName, cfg, *info)
if err != nil {
return "", nil, errors.Wrapf(err, "writing output for %s image '%s'", source, imageName)
return true, "", nil, errors.Wrapf(err, "writing output for %s image '%s'", source, imageName)
}

return buf.String(), warnings, nil
return true, buf.String(), warnings, nil
}

func generateBuilderOutput(writer io.Writer, imageName string, cfg config.Config, info pack.BuilderInfo) (warnings []string, err error) {
Expand Down
Loading

0 comments on commit 3b65cd7

Please sign in to comment.