mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Adding function to resolve tag to digest in daemon
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
parent
16ea0806f8
commit
87075353dc
2 changed files with 40 additions and 0 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
clustertypes "github.com/docker/docker/daemon/cluster/provider"
|
||||
"github.com/docker/docker/reference"
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/docker/libnetwork/cluster"
|
||||
networktypes "github.com/docker/libnetwork/types"
|
||||
|
@ -44,4 +45,5 @@ type Backend interface {
|
|||
UnsubscribeFromEvents(listener chan interface{})
|
||||
UpdateAttachment(string, string, string, *network.NetworkingConfig) error
|
||||
WaitForDetachment(context.Context, string, string, string, string) error
|
||||
ResolveTagToDigest(context.Context, reference.NamedTagged, *types.AuthConfig) (string, error)
|
||||
}
|
||||
|
|
|
@ -104,3 +104,41 @@ func (daemon *Daemon) pullImageWithReference(ctx context.Context, ref reference.
|
|||
<-writesDone
|
||||
return err
|
||||
}
|
||||
|
||||
func (daemon *Daemon) ResolveTagToDigest(ctx context.Context, ref reference.NamedTagged, authConfig *types.AuthConfig) (string, error) {
|
||||
// get repository info
|
||||
repoInfo, err := daemon.RegistryService.ResolveRepository(ref)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// makes sure name is not empty or `scratch`
|
||||
if err := distribution.ValidateRepoName(repoInfo.Name()); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// get endpoints
|
||||
endpoints, err := daemon.RegistryService.LookupPullEndpoints(repoInfo.Hostname())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// retrieve repository
|
||||
// TODO(nishanttotla): More sophisticated selection of endpoint
|
||||
repo, confirmedV2, err := distribution.NewV2Repository(ctx, repoInfo, endpoints[0], nil, authConfig, "pull")
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
digest := ""
|
||||
|
||||
// only retrieve digest if the repo is v2
|
||||
if confirmedV2 {
|
||||
dscrptr, err := repo.Tags(ctx).Get(ctx, ref.Tag())
|
||||
if err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
digest = dscrptr.Digest.String()
|
||||
}
|
||||
}
|
||||
return digest, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue