mirror of https://github.com/docker/compose.git
use DistributionInspect to resolve image digest
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
9ac4f69918
commit
8f2b747104
17
go.mod
17
go.mod
|
@ -5,7 +5,6 @@ go 1.19
|
|||
require (
|
||||
github.com/AlecAivazis/survey/v2 v2.3.6
|
||||
github.com/buger/goterm v1.0.4
|
||||
github.com/cnabio/cnab-to-oci v0.3.1-beta1
|
||||
github.com/compose-spec/compose-go v1.7.0
|
||||
github.com/containerd/console v1.0.3
|
||||
github.com/containerd/containerd v1.6.10
|
||||
|
@ -41,16 +40,13 @@ require (
|
|||
|
||||
require (
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
||||
github.com/Masterminds/semver v1.5.0 // indirect
|
||||
github.com/Microsoft/go-winio v0.5.2 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/cnabio/cnab-go v0.23.0 // indirect
|
||||
github.com/containerd/continuity v0.3.0 // indirect
|
||||
github.com/containerd/ttrpc v1.1.0 // indirect
|
||||
github.com/containerd/typeurl v1.0.2 // indirect
|
||||
github.com/cyberphone/json-canonicalization v0.0.0-20210303052042-6bc126869bf4 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/docker/distribution v2.8.1+incompatible // indirect
|
||||
github.com/docker/docker-credential-helpers v0.7.0 // indirect
|
||||
|
@ -98,8 +94,6 @@ require (
|
|||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.32.1 // indirect
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
github.com/qri-io/jsonpointer v0.1.1 // indirect
|
||||
github.com/qri-io/jsonschema v0.2.2-0.20210831022256-780655b2ba0e // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/serialx/hashring v0.0.0-20190422032157-8b2912629002 // indirect
|
||||
github.com/tonistiigi/fsutil v0.0.0-20220930225714-4638ad635be5 // indirect
|
||||
|
@ -144,13 +138,10 @@ require (
|
|||
)
|
||||
|
||||
require (
|
||||
github.com/gobuffalo/logger v1.0.3 // indirect
|
||||
github.com/gobuffalo/packd v1.0.0 // indirect
|
||||
github.com/gobuffalo/packr/v2 v2.8.0 // indirect
|
||||
github.com/karrick/godirwalk v1.15.3 // indirect
|
||||
github.com/markbates/errx v1.1.0 // indirect
|
||||
github.com/markbates/oncer v1.0.0 // indirect
|
||||
github.com/markbates/safe v1.0.1 // indirect
|
||||
github.com/bugsnag/bugsnag-go v1.5.0 // indirect
|
||||
github.com/cloudflare/cfssl v1.4.1 // indirect
|
||||
github.com/jinzhu/gorm v1.9.11 // indirect
|
||||
github.com/spf13/viper v1.4.0 // indirect
|
||||
)
|
||||
|
||||
replace (
|
||||
|
|
|
@ -23,12 +23,10 @@ import (
|
|||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/cnabio/cnab-to-oci/remotes"
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/distribution/distribution/v3/reference"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/config/configfile"
|
||||
registry "github.com/docker/cli/cli/registry/client"
|
||||
"github.com/docker/cli/cli/streams"
|
||||
moby "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
|
@ -55,10 +53,6 @@ func (s *composeService) apiClient() client.APIClient {
|
|||
return s.dockerCli.Client()
|
||||
}
|
||||
|
||||
func (s *composeService) registryClient() registry.RegistryClient {
|
||||
return s.dockerCli.RegistryClient(false)
|
||||
}
|
||||
|
||||
func (s *composeService) configFile() *configfile.ConfigFile {
|
||||
return s.dockerCli.ConfigFile()
|
||||
}
|
||||
|
@ -101,11 +95,20 @@ func getContainerNameWithoutProject(c moby.Container) string {
|
|||
|
||||
func (s *composeService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) {
|
||||
if options.ResolveImageDigests {
|
||||
// TODO use dockercli.RegistryClient instead
|
||||
resolver := remotes.CreateResolver(s.configFile())
|
||||
err := project.ResolveImages(func(named reference.Named) (digest.Digest, error) {
|
||||
_, desc, err := resolver.Resolve(ctx, named.String())
|
||||
return desc.Digest, err
|
||||
info, err := s.apiClient().Info(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = project.ResolveImages(func(named reference.Named) (digest.Digest, error) {
|
||||
auth, err := encodedAuth(named, info, s.configFile())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
inspect, err := s.apiClient().DistributionInspect(ctx, named.String(), auth)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return inspect.Descriptor.Digest, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -118,7 +121,7 @@ func (s *composeService) Convert(ctx context.Context, project *types.Project, op
|
|||
case "yaml":
|
||||
return yaml.Marshal(project)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported format %q", options)
|
||||
return nil, fmt.Errorf("unsupported format %q", options.Format)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -158,32 +158,18 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
|
|||
return "", err
|
||||
}
|
||||
|
||||
repoInfo, err := registry.ParseRepositoryInfo(ref)
|
||||
encodedAuth, err := encodedAuth(ref, info, configFile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
key := repoInfo.Index.Name
|
||||
if repoInfo.Index.Official {
|
||||
key = info.IndexServerAddress
|
||||
}
|
||||
|
||||
authConfig, err := configFile.GetAuthConfig(key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
buf, err := json.Marshal(authConfig)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
platform := service.Platform
|
||||
if platform == "" {
|
||||
platform = defaultPlatform
|
||||
}
|
||||
|
||||
stream, err := s.apiClient().ImagePull(ctx, service.Image, moby.ImagePullOptions{
|
||||
RegistryAuth: base64.URLEncoding.EncodeToString(buf),
|
||||
RegistryAuth: encodedAuth,
|
||||
Platform: platform,
|
||||
})
|
||||
|
||||
|
@ -236,6 +222,29 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
|
|||
return inspected.ID, nil
|
||||
}
|
||||
|
||||
func encodedAuth(ref reference.Named, info moby.Info, configFile driver.Auth) (string, error) {
|
||||
repoInfo, err := registry.ParseRepositoryInfo(ref)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
key := repoInfo.Index.Name
|
||||
if repoInfo.Index.Official {
|
||||
key = info.IndexServerAddress
|
||||
}
|
||||
|
||||
authConfig, err := configFile.GetAuthConfig(key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
buf, err := json.Marshal(authConfig)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base64.URLEncoding.EncodeToString(buf), nil
|
||||
}
|
||||
|
||||
func (s *composeService) pullRequiredImages(ctx context.Context, project *types.Project, images map[string]string, quietPull bool) error {
|
||||
info, err := s.apiClient().Info(ctx)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue