Merge pull request #142 from runcom/vendor-contimage

Vendor containers/image
This commit is contained in:
Antonio Murdaca 2016-07-04 12:46:10 +02:00 committed by GitHub
commit 29d76eb5ca
10 changed files with 36 additions and 36 deletions

View File

@ -37,7 +37,7 @@ var layersCmd = cli.Command{
if err != nil { if err != nil {
return err return err
} }
dest := directory.NewDirImageDestination(tmpDir) dest := directory.NewImageDestination(tmpDir)
manifest, _, err := src.Manifest() manifest, _, err := src.Manifest()
if err != nil { if err != nil {
return err return err

View File

@ -34,11 +34,11 @@ func parseImage(c *cli.Context) (types.Image, error) {
) )
switch { switch {
case strings.HasPrefix(imgName, dockerPrefix): case strings.HasPrefix(imgName, dockerPrefix):
return docker.NewDockerImage(strings.TrimPrefix(imgName, dockerPrefix), certPath, tlsVerify) return docker.NewImage(strings.TrimPrefix(imgName, dockerPrefix), certPath, tlsVerify)
//case strings.HasPrefix(img, appcPrefix): //case strings.HasPrefix(img, appcPrefix):
// //
case strings.HasPrefix(imgName, directoryPrefix): case strings.HasPrefix(imgName, directoryPrefix):
src := directory.NewDirImageSource(strings.TrimPrefix(imgName, directoryPrefix)) src := directory.NewImageSource(strings.TrimPrefix(imgName, directoryPrefix))
return image.FromSource(src, nil), nil return image.FromSource(src, nil), nil
} }
return nil, errors.New("no valid prefix provided") return nil, errors.New("no valid prefix provided")
@ -52,11 +52,11 @@ func parseImageSource(c *cli.Context, name string) (types.ImageSource, error) {
) )
switch { switch {
case strings.HasPrefix(name, dockerPrefix): case strings.HasPrefix(name, dockerPrefix):
return docker.NewDockerImageSource(strings.TrimPrefix(name, dockerPrefix), certPath, tlsVerify) return docker.NewImageSource(strings.TrimPrefix(name, dockerPrefix), certPath, tlsVerify)
case strings.HasPrefix(name, atomicPrefix): case strings.HasPrefix(name, atomicPrefix):
return openshift.NewOpenshiftImageSource(strings.TrimPrefix(name, atomicPrefix), certPath, tlsVerify) return openshift.NewImageSource(strings.TrimPrefix(name, atomicPrefix), certPath, tlsVerify)
case strings.HasPrefix(name, directoryPrefix): case strings.HasPrefix(name, directoryPrefix):
return directory.NewDirImageSource(strings.TrimPrefix(name, directoryPrefix)), nil return directory.NewImageSource(strings.TrimPrefix(name, directoryPrefix)), nil
} }
return nil, fmt.Errorf("Unrecognized image reference %s", name) return nil, fmt.Errorf("Unrecognized image reference %s", name)
} }
@ -69,13 +69,13 @@ func parseImageDestination(c *cli.Context, name string) (types.ImageDestination,
) )
switch { switch {
case strings.HasPrefix(name, dockerPrefix): case strings.HasPrefix(name, dockerPrefix):
return docker.NewDockerImageDestination(strings.TrimPrefix(name, dockerPrefix), certPath, tlsVerify) return docker.NewImageDestination(strings.TrimPrefix(name, dockerPrefix), certPath, tlsVerify)
case strings.HasPrefix(name, atomicPrefix): case strings.HasPrefix(name, atomicPrefix):
return openshift.NewOpenshiftImageDestination(strings.TrimPrefix(name, atomicPrefix), certPath, tlsVerify) return openshift.NewImageDestination(strings.TrimPrefix(name, atomicPrefix), certPath, tlsVerify)
case strings.HasPrefix(name, directoryPrefix): case strings.HasPrefix(name, directoryPrefix):
return directory.NewDirImageDestination(strings.TrimPrefix(name, directoryPrefix)), nil return directory.NewImageDestination(strings.TrimPrefix(name, directoryPrefix)), nil
case strings.HasPrefix(name, ociPrefix): case strings.HasPrefix(name, ociPrefix):
return oci.NewOCIImageDestination(strings.TrimPrefix(name, ociPrefix)) return oci.NewImageDestination(strings.TrimPrefix(name, ociPrefix))
} }
return nil, fmt.Errorf("Unrecognized image reference %s", name) return nil, fmt.Errorf("Unrecognized image reference %s", name)
} }

View File

@ -13,8 +13,8 @@ type dirImageDestination struct {
dir string dir string
} }
// NewDirImageDestination returns an ImageDestination for writing to an existing directory. // NewImageDestination returns an ImageDestination for writing to an existing directory.
func NewDirImageDestination(dir string) types.ImageDestination { func NewImageDestination(dir string) types.ImageDestination {
return &dirImageDestination{dir} return &dirImageDestination{dir}
} }

View File

@ -13,8 +13,8 @@ type dirImageSource struct {
dir string dir string
} }
// NewDirImageSource returns an ImageSource reading from an existing directory. // NewImageSource returns an ImageSource reading from an existing directory.
func NewDirImageSource(dir string) types.ImageSource { func NewImageSource(dir string) types.ImageSource {
return &dirImageSource{dir} return &dirImageSource{dir}
} }

View File

@ -16,9 +16,9 @@ type Image struct {
src *dockerImageSource src *dockerImageSource
} }
// NewDockerImage returns a new Image interface type after setting up // NewImage returns a new Image interface type after setting up
// a client to the registry hosting the given image. // a client to the registry hosting the given image.
func NewDockerImage(img, certPath string, tlsVerify bool) (types.Image, error) { func NewImage(img, certPath string, tlsVerify bool) (types.Image, error) {
s, err := newDockerImageSource(img, certPath, tlsVerify) s, err := newDockerImageSource(img, certPath, tlsVerify)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -8,9 +8,9 @@ import (
"net/http" "net/http"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/reference"
"github.com/containers/image/manifest" "github.com/containers/image/manifest"
"github.com/containers/image/types" "github.com/containers/image/types"
"github.com/docker/docker/reference"
) )
type dockerImageDestination struct { type dockerImageDestination struct {
@ -19,9 +19,9 @@ type dockerImageDestination struct {
c *dockerClient c *dockerClient
} }
// NewDockerImageDestination creates a new ImageDestination for the specified image and connection specification. // NewImageDestination creates a new ImageDestination for the specified image and connection specification.
func NewDockerImageDestination(img, certPath string, tlsVerify bool) (types.ImageDestination, error) { func NewImageDestination(img, certPath string, tlsVerify bool) (types.ImageDestination, error) {
ref, tag, err := parseDockerImageName(img) ref, tag, err := parseImageName(img)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -51,7 +51,7 @@ func (d *dockerImageDestination) CanonicalDockerReference() (string, error) {
func (d *dockerImageDestination) PutManifest(m []byte) error { func (d *dockerImageDestination) PutManifest(m []byte) error {
// FIXME: This only allows upload by digest, not creating a tag. See the // FIXME: This only allows upload by digest, not creating a tag. See the
// corresponding comment in NewOpenshiftImageDestination. // corresponding comment in openshift.NewImageDestination.
digest, err := manifest.Digest(m) digest, err := manifest.Digest(m)
if err != nil { if err != nil {
return err return err

View File

@ -9,9 +9,9 @@ import (
"strconv" "strconv"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/reference"
"github.com/containers/image/manifest" "github.com/containers/image/manifest"
"github.com/containers/image/types" "github.com/containers/image/types"
"github.com/docker/docker/reference"
) )
type errFetchManifest struct { type errFetchManifest struct {
@ -29,9 +29,9 @@ type dockerImageSource struct {
c *dockerClient c *dockerClient
} }
// newDockerImageSource is the same as NewDockerImageSource, only it returns the more specific *dockerImageSource type. // newDockerImageSource is the same as NewImageSource, only it returns the more specific *dockerImageSource type.
func newDockerImageSource(img, certPath string, tlsVerify bool) (*dockerImageSource, error) { func newDockerImageSource(img, certPath string, tlsVerify bool) (*dockerImageSource, error) {
ref, tag, err := parseDockerImageName(img) ref, tag, err := parseImageName(img)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -46,8 +46,8 @@ func newDockerImageSource(img, certPath string, tlsVerify bool) (*dockerImageSou
}, nil }, nil
} }
// NewDockerImageSource creates a new ImageSource for the specified image and connection specification. // NewImageSource creates a new ImageSource for the specified image and connection specification.
func NewDockerImageSource(img, certPath string, tlsVerify bool) (types.ImageSource, error) { func NewImageSource(img, certPath string, tlsVerify bool) (types.ImageSource, error) {
return newDockerImageSource(img, certPath, tlsVerify) return newDockerImageSource(img, certPath, tlsVerify)
} }

View File

@ -2,8 +2,8 @@ package docker
import "github.com/docker/docker/reference" import "github.com/docker/docker/reference"
// parseDockerImageName converts a string into a reference and tag value. // parseImageName converts a string into a reference and tag value.
func parseDockerImageName(img string) (reference.Named, string, error) { func parseImageName(img string) (reference.Named, string, error) {
ref, err := reference.ParseNamed(img) ref, err := reference.ParseNamed(img)
if err != nil { if err != nil {
return nil, "", err return nil, "", err

View File

@ -35,8 +35,8 @@ type ociImageDestination struct {
var refRegexp = regexp.MustCompile(`^([A-Za-z0-9._-]+)+$`) var refRegexp = regexp.MustCompile(`^([A-Za-z0-9._-]+)+$`)
// NewOCIImageDestination returns an ImageDestination for writing to an existing directory. // NewImageDestination returns an ImageDestination for writing to an existing directory.
func NewOCIImageDestination(dest string) (types.ImageDestination, error) { func NewImageDestination(dest string) (types.ImageDestination, error) {
dir := dest dir := dest
sep := strings.LastIndex(dest, ":") sep := strings.LastIndex(dest, ":")
tag := "latest" tag := "latest"

View File

@ -172,8 +172,8 @@ type openshiftImageSource struct {
imageStreamImageName string // Resolved image identifier, or "" if not known yet imageStreamImageName string // Resolved image identifier, or "" if not known yet
} }
// NewOpenshiftImageSource creates a new ImageSource for the specified image and connection specification. // NewImageSource creates a new ImageSource for the specified image and connection specification.
func NewOpenshiftImageSource(imageName, certPath string, tlsVerify bool) (types.ImageSource, error) { func NewImageSource(imageName, certPath string, tlsVerify bool) (types.ImageSource, error) {
client, err := newOpenshiftClient(imageName) client, err := newOpenshiftClient(imageName)
if err != nil { if err != nil {
return nil, err return nil, err
@ -247,7 +247,7 @@ func (s *openshiftImageSource) ensureImageIsResolved() error {
return err return err
} }
logrus.Debugf("Resolved reference %#v", dockerRef) logrus.Debugf("Resolved reference %#v", dockerRef)
d, err := docker.NewDockerImageSource(dockerRef, s.certPath, s.tlsVerify) d, err := docker.NewImageSource(dockerRef, s.certPath, s.tlsVerify)
if err != nil { if err != nil {
return err return err
} }
@ -261,8 +261,8 @@ type openshiftImageDestination struct {
docker types.ImageDestination // The Docker Registry endpoint docker types.ImageDestination // The Docker Registry endpoint
} }
// NewOpenshiftImageDestination creates a new ImageDestination for the specified image and connection specification. // NewImageDestination creates a new ImageDestination for the specified image and connection specification.
func NewOpenshiftImageDestination(imageName, certPath string, tlsVerify bool) (types.ImageDestination, error) { func NewImageDestination(imageName, certPath string, tlsVerify bool) (types.ImageDestination, error) {
client, err := newOpenshiftClient(imageName) client, err := newOpenshiftClient(imageName)
if err != nil { if err != nil {
return nil, err return nil, err
@ -272,7 +272,7 @@ func NewOpenshiftImageDestination(imageName, certPath string, tlsVerify bool) (t
// i.e. a single signed image cannot be available under multiple tags. But with types.ImageDestination, we don't know // i.e. a single signed image cannot be available under multiple tags. But with types.ImageDestination, we don't know
// the manifest digest at this point. // the manifest digest at this point.
dockerRef := fmt.Sprintf("%s/%s/%s:%s", client.dockerRegistryHostPart(), client.namespace, client.stream, client.tag) dockerRef := fmt.Sprintf("%s/%s/%s:%s", client.dockerRegistryHostPart(), client.namespace, client.stream, client.tag)
docker, err := docker.NewDockerImageDestination(dockerRef, certPath, tlsVerify) docker, err := docker.NewImageDestination(dockerRef, certPath, tlsVerify)
if err != nil { if err != nil {
return nil, err return nil, err
} }