This repository has been archived by the owner on Jun 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 177
Store repo digest as app image is pushed #770
Open
ndeloof
wants to merge
2
commits into
docker:master
Choose a base branch
from
ndeloof:digests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import ( | |
"os" | ||
"strings" | ||
|
||
"github.com/opencontainers/go-digest" | ||
|
||
"github.com/docker/app/internal/relocated" | ||
"github.com/docker/app/internal/store" | ||
|
||
|
@@ -69,10 +71,20 @@ func runPush(dockerCli command.Cli, name string) error { | |
return err | ||
} | ||
|
||
cnabRef := reference.TagNameOnly(ref) | ||
|
||
// Push the bundle | ||
return pushBundle(dockerCli, bndl, cnabRef) | ||
dg, err := pushBundle(dockerCli, bndl, ref) | ||
if err != nil { | ||
return errors.Wrapf(err, "could not push %q", ref) | ||
} | ||
|
||
// we can't just re-use bndl var here, as fixup did rewrite the bundle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As stated in the specs, https://github.com/cnabio/cnab-spec/blob/master/101-bundle-json.md#invocation-images
the contentDigest can be omitted, but needs to be filled before pushing. I think that's exactly what we do here, that's why the bundle is mutated by the |
||
bndl, err = resolveReferenceAndBundle(bundleStore, ref) | ||
if err != nil { | ||
return err | ||
} | ||
bndl.RepoDigest = dg | ||
_, err = bundleStore.Store(bndl, ref) | ||
return err | ||
} | ||
|
||
func resolveReferenceAndBundle(bundleStore store.BundleStore, ref reference.Reference) (*relocated.Bundle, error) { | ||
|
@@ -88,10 +100,10 @@ func resolveReferenceAndBundle(bundleStore store.BundleStore, ref reference.Refe | |
return bndl, err | ||
} | ||
|
||
func pushBundle(dockerCli command.Cli, bndl *relocated.Bundle, cnabRef reference.Named) error { | ||
func pushBundle(dockerCli command.Cli, bndl *relocated.Bundle, cnabRef reference.Named) (digest.Digest, error) { | ||
insecureRegistries, err := internal.InsecureRegistriesFromEngine(dockerCli) | ||
if err != nil { | ||
return errors.Wrap(err, "could not retrieve insecure registries") | ||
return "", errors.Wrap(err, "could not retrieve insecure registries") | ||
} | ||
resolver := remotes.CreateResolver(dockerCli.ConfigFile(), insecureRegistries...) | ||
var display fixupDisplay = &plainDisplay{out: os.Stdout} | ||
|
@@ -107,17 +119,17 @@ func pushBundle(dockerCli command.Cli, bndl *relocated.Bundle, cnabRef reference | |
// bundle fixup | ||
relocationMap, err := remotes.FixupBundle(context.Background(), bndl.Bundle, cnabRef, resolver, fixupOptions...) | ||
if err != nil { | ||
return errors.Wrapf(err, "fixing up %q for push", cnabRef) | ||
return "", errors.Wrapf(err, "fixing up %q for push", cnabRef) | ||
} | ||
bndl.RelocationMap = relocationMap | ||
// push bundle manifest | ||
logrus.Debugf("Pushing the bundle %q", cnabRef) | ||
descriptor, err := remotes.Push(log.WithLogContext(context.Background()), bndl.Bundle, bndl.RelocationMap, cnabRef, resolver, true, withAppAnnotations) | ||
if err != nil { | ||
return errors.Wrapf(err, "pushing to %q", cnabRef) | ||
return "", errors.Wrapf(err, "pushing to %q", cnabRef) | ||
} | ||
fmt.Fprintf(os.Stdout, "Successfully pushed bundle to %s. Digest is %s.\n", cnabRef, descriptor.Digest) | ||
return nil | ||
return descriptor.Digest, nil | ||
} | ||
|
||
func withAppAnnotations(index *ocischemav1.Index) error { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand that correctly, tagging a pulled app image means we drop its repo digest? So it won't be displayed in the
docker app image ls --digest
column?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be wrong, but IIUC repo digest won't be the same if you push under a distinct tag. So keeing this "pulled digest" for a tagged image would be wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be the same repo digest, as tagging is just pushing a new descriptor, pointing to the same manifest/manifest list, but the repo digest should be the digest of the pointed object, not the pointer. cc @eunomie / @thaJeztah any idea?