Skip to content
Merged
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
5 changes: 5 additions & 0 deletions cmd/lifecycle/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ func (e *exportCmd) initDaemonAppImage(analyzedMD files.Analyzed, logger log.Log
return nil, "", cmd.FailErr(err, " image")
}

// Identifier() returns an empty ID without an error when the run image is missing from the daemon
if !appImage.Found() {
return nil, "", cmd.FailErr(fmt.Errorf("run image %q not found in daemon", e.RunImageRef), "access run image")
}

runImageID, err := appImage.Identifier()
if err != nil {
return nil, "", cmd.FailErr(err, "get run image ID")
Expand Down
56 changes: 56 additions & 0 deletions cmd/lifecycle/exporter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"context"
"testing"

"github.com/moby/moby/client"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpacks/lifecycle/platform"
"github.com/buildpacks/lifecycle/platform/files"
h "github.com/buildpacks/lifecycle/testhelpers"
)

func TestExporter(t *testing.T) {
spec.Run(t, "exporter", testExporter, spec.Report(report.Terminal{}))
}

// notFoundError is recognized as "not found" by the daemon image lookup.
type notFoundError struct{}

func (notFoundError) Error() string { return "no such image" }
func (notFoundError) NotFound() {}

// emptyDaemon is a docker client whose daemon has no images.
type emptyDaemon struct {
client.APIClient
}

func (emptyDaemon) ServerVersion(context.Context, client.ServerVersionOptions) (client.ServerVersionResult, error) {
return client.ServerVersionResult{APIVersion: "1.48", Os: "linux", Arch: "amd64"}, nil
}

func (emptyDaemon) ImageInspect(context.Context, string, ...client.ImageInspectOption) (client.ImageInspectResult, error) {
return client.ImageInspectResult{}, notFoundError{}
}

func testExporter(t *testing.T, when spec.G, it spec.S) {
when("#initDaemonAppImage", func() {
when("the run image is not in the daemon", func() {
it("fails with an error naming the run image", func() {
e := &exportCmd{
Platform: platform.NewPlatformFor("0.11"),
docker: emptyDaemon{},
}
e.RunImageRef = "some-run-image"
e.OutputImageRef = "some-app-image"

_, _, err := e.initDaemonAppImage(files.Analyzed{}, nil)

h.AssertError(t, err, `run image "some-run-image" not found in daemon`)
})
})
})
}
Loading