Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Try docker daemon before reading remote image #18

Merged
merged 1 commit into from
Aug 12, 2019
Merged

Try docker daemon before reading remote image #18

merged 1 commit into from
Aug 12, 2019

Conversation

glyn
Copy link
Contributor

@glyn glyn commented Aug 7, 2019

It's better to use an image in the daemon than to fail. See cnabio/duffle#828 (comment).

Bump the go-containerregistry dependency and use a corresponding version of docker.

@@ -58,7 +68,7 @@ func writeRemoteImage(i v1.Image, n image.Name) error {
return err
}

return remote.Write(ref, i, auth, http.DefaultTransport)
return remote.Write(ref, i, remote.WithAuth(auth), remote.WithTransport(http.DefaultTransport))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was necessitated because of bumping go-containerregistry.

var derr error
img, derr = daemon.Image(ref)
if derr != nil {
return nil, fmt.Errorf("reading remote image %s failed: %v; attempting to read from daemon also failed: %v", n.String(), err, derr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to think carefully about the error message in this case. Initially, I ignored the daemon error and reported back just the repository error - the rationale being that since there is no hard dependency on the daemon, we should report errors from the daemon. However, this could mask a genuine problem with the daemon, so I decided to combine the two errors together, for example:

$ ./irel layout add layout glyn/helloworld-cnab:a028fb535114b81ae38a6711b5de896642a07dfd
2019/08/07 13:34:50 add failed: reading remote image docker.io/glyn/helloworld-cnab:a028fb535114b81ae38a6711b5de896642a07dfd failed: MANIFEST_UNKNOWN: manifest unknown; map[Tag:a028fb535114b81ae38a6711b5de896642a07dfd]; attempting to read from daemon also failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

@glyn glyn self-assigned this Aug 12, 2019
@glyn glyn changed the title Try docker daemon after failing to read remote image Try docker daemon before reading remote image Aug 12, 2019
@fbiville fbiville self-requested a review August 12, 2019 09:47
Copy link
Contributor

@fbiville fbiville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to add tests for these changes?

pkg/registry/remote.go Outdated Show resolved Hide resolved
@glyn
Copy link
Contributor Author

glyn commented Aug 12, 2019

Is there a way to add tests for these changes?

I considered that previously, but on second thoughts, you're right and I'll add some tests.

See cnabio/duffle#828 (comment).

Bump the go-containerregistry dependency and use a corresponding version of
docker.

Handle an empty image name more gracefully (than panicking).
@vmware-archive vmware-archive deleted a comment from codecov bot Aug 12, 2019
@glyn glyn requested a review from fbiville August 12, 2019 12:10
@glyn
Copy link
Contributor Author

glyn commented Aug 12, 2019

Is there a way to add tests for these changes?

I considered that previously, but on second thoughts, you're right and I'll add some tests.

There are some paths that can't be exercised because it's impossible to construct image names which are invalid in certain ways. However, the coverage is much improved and the main logic is now tested. Thanks for suggesting this.

@codecov
Copy link

codecov bot commented Aug 12, 2019

Codecov Report

Merging #18 into master will increase coverage by 7.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #18      +/-   ##
==========================================
+ Coverage   61.01%   68.07%   +7.05%     
==========================================
  Files           7        7              
  Lines         277      285       +8     
==========================================
+ Hits          169      194      +25     
+ Misses         96       75      -21     
- Partials       12       16       +4
Impacted Files Coverage Δ
pkg/registry/remote.go 75.75% <100%> (+75.75%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1445a3d...76b3864. Read the comment docs.

Expect(err).NotTo(HaveOccurred())
mockImage.DigestReturns(h1, nil)

testError = errors.New("hard cheese")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧀

@glyn glyn merged commit ea07ec0 into vmware-archive:master Aug 12, 2019
@glyn glyn deleted the use-daemon branch August 12, 2019 13:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants