Skip to content

Commit

Permalink
Don't print warnings about run image for older platform apis (#757)
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano authored Nov 10, 2021
1 parent f02ec0f commit 075a63e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
23 changes: 23 additions & 0 deletions acceptance/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,29 @@ func testAnalyzerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
})
})
})

when("older platform", func() {
it("does not print log warnings", func() {
h.SkipIf(t, api.MustParse(platformAPI).AtLeast("0.7"), "Platform API >= 0.7 accepts run image")

output := h.DockerRunAndCopy(t,
containerName,
copyDir,
ctrPath("/layers/analyzed.toml"),
analyzeImage,
h.WithFlags(
"--env", "CNB_PLATFORM_API="+platformAPI,
"--env", "CNB_REGISTRY_AUTH="+analyzeRegAuthConfig,
"--env", "CNB_RUN_IMAGE="+analyzeRegFixtures.ReadOnlyRunImage,
"--network", analyzeRegNetwork,
),
h.WithArgs(ctrPath(analyzerPath), analyzeRegFixtures.SomeAppImage),
)

h.AssertStringDoesNotContain(t, output, `no stack metadata found at path ''`)
h.AssertStringDoesNotContain(t, output, `Previous image with name "" not found`)
})
})
})
})

Expand Down
24 changes: 15 additions & 9 deletions cmd/lifecycle/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,19 @@ func (a *analyzeCmd) Args(nargs int, args []string) error {
a.platform06.groupPath = cmd.DefaultGroupPath(a.platform.API(), a.layersDir)
}

stackMD, err := readStack(a.stackPath)
if err != nil {
return cmd.FailErrCode(err, cmd.CodeInvalidArgs, "parse stack metadata")
}
if a.supportsRunImage() {
stackMD, err := readStack(a.stackPath)
if err != nil {
return cmd.FailErrCode(err, cmd.CodeInvalidArgs, "parse stack metadata")
}

if err := a.validateRunImageInput(); err != nil {
return cmd.FailErrCode(err, cmd.CodeInvalidArgs, "validate run image input")
}
if err := a.validateRunImageInput(); err != nil {
return cmd.FailErrCode(err, cmd.CodeInvalidArgs, "validate run image input")
}

if err := a.populateRunImage(stackMD, targetRegistry); err != nil {
return cmd.FailErrCode(err, cmd.CodeInvalidArgs, "populate run image")
if err := a.populateRunImage(stackMD, targetRegistry); err != nil {
return cmd.FailErrCode(err, cmd.CodeInvalidArgs, "populate run image")
}
}

return nil
Expand Down Expand Up @@ -240,6 +242,10 @@ func (aa analyzeArgs) analyze() (platform.AnalyzedMetadata, error) {
}

func (aa analyzeArgs) localOrRemote(fromImage string) (imgutil.Image, error) {
if fromImage == "" {
return nil, nil
}

if aa.useDaemon {
return local.NewImage(
fromImage,
Expand Down

0 comments on commit 075a63e

Please sign in to comment.