Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions directory/directory_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (d *dirImageDestination) PutBlob(ctx context.Context, stream io.Reader, inp
digester := digest.Canonical.Digester()
tee := io.TeeReader(stream, digester.Hash())

// TODO: This can take quite some time, and should ideally be cancellable using ctx.Done().
size, err := io.Copy(blobFile, tee)
if err != nil {
return types.BlobInfo{}, err
Expand Down
44 changes: 23 additions & 21 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
// Package image provides libraries and commands to interact with containers images.
//
// package main
// package main
//
// import (
// "fmt"
// import (
// "context"
// "fmt"
//
// "github.com/containers/image/docker"
// )
// "github.com/containers/image/docker"
// )
//
// func main() {
// ref, err := docker.ParseReference("//fedora")
// if err != nil {
// panic(err)
// }
// ctx := context.Background()
// img, err := ref.NewImage(ctx)
// if err != nil {
// panic(err)
// }
// defer img.Close()
// b, _, err := img.Manifest(ctx)
// if err != nil {
// panic(err)
// }
// fmt.Printf("%s", string(b))
// func main() {
// ref, err := docker.ParseReference("//fedora")
// if err != nil {
// panic(err)
// }
// ctx := context.Background()
// img, err := ref.NewImage(ctx, nil)
// if err != nil {
// panic(err)
// }
// defer img.Close()
// b, _, err := img.Manifest(ctx)
// if err != nil {
// panic(err)
// }
// fmt.Printf("%s", string(b))
// }
//
//
// TODO(runcom)
package image
2 changes: 1 addition & 1 deletion docker/archive/dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type archiveImageDestination struct {
writer io.Closer
}

func newImageDestination(ctx context.Context, ref archiveReference) (types.ImageDestination, error) {
func newImageDestination(ref archiveReference) (types.ImageDestination, error) {
if ref.destinationRef == nil {
return nil, errors.Errorf("docker-archive: destination reference not supplied (must be of form <path>:<reference:tag>)")
}
Expand Down
2 changes: 1 addition & 1 deletion docker/archive/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (ref archiveReference) NewImageSource(ctx context.Context, sys *types.Syste
// NewImageDestination returns a types.ImageDestination for this reference.
// The caller must call .Close() on the returned ImageDestination.
func (ref archiveReference) NewImageDestination(ctx context.Context, sys *types.SystemContext) (types.ImageDestination, error) {
return newImageDestination(ctx, ref)
return newImageDestination(ref)
}

// DeleteImage deletes the named image from the registry, if supported.
Expand Down
2 changes: 1 addition & 1 deletion docker/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func dockerCertDir(sys *types.SystemContext, hostPort string) (string, error) {

// newDockerClientFromRef returns a new dockerClient instance for refHostname (a host a specified in the Docker image reference, not canonicalized to dockerRegistry)
// “write” specifies whether the client will be used for "write" access (in particular passed to lookaside.go:toplevelFromSection)
func newDockerClientFromRef(ctx context.Context, sys *types.SystemContext, ref dockerReference, write bool, actions string) (*dockerClient, error) {
func newDockerClientFromRef(sys *types.SystemContext, ref dockerReference, write bool, actions string) (*dockerClient, error) {
registry := reference.Domain(ref.ref)
username, password, err := config.GetAuthentication(sys, reference.Domain(ref.ref))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docker/docker_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Image struct {
// a client to the registry hosting the given image.
// The caller must call .Close() on the returned Image.
func newImage(ctx context.Context, sys *types.SystemContext, ref dockerReference) (types.ImageCloser, error) {
s, err := newImageSource(ctx, sys, ref)
s, err := newImageSource(sys, ref)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions docker/docker_image_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ type dockerImageDestination struct {
}

// newImageDestination creates a new ImageDestination for the specified image reference.
func newImageDestination(ctx context.Context, sys *types.SystemContext, ref dockerReference) (types.ImageDestination, error) {
c, err := newDockerClientFromRef(ctx, sys, ref, true, "pull,push")
func newImageDestination(sys *types.SystemContext, ref dockerReference) (types.ImageDestination, error) {
c, err := newDockerClientFromRef(sys, ref, true, "pull,push")
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions docker/docker_image_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type dockerImageSource struct {

// newImageSource creates a new ImageSource for the specified image reference.
// The caller must call .Close() on the returned ImageSource.
func newImageSource(ctx context.Context, sys *types.SystemContext, ref dockerReference) (*dockerImageSource, error) {
c, err := newDockerClientFromRef(ctx, sys, ref, false, "pull")
func newImageSource(sys *types.SystemContext, ref dockerReference) (*dockerImageSource, error) {
c, err := newDockerClientFromRef(sys, ref, false, "pull")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -310,7 +310,7 @@ func (s *dockerImageSource) getSignaturesFromAPIExtension(ctx context.Context, i

// deleteImage deletes the named image from the registry, if supported.
func deleteImage(ctx context.Context, sys *types.SystemContext, ref dockerReference) error {
c, err := newDockerClientFromRef(ctx, sys, ref, true, "push")
c, err := newDockerClientFromRef(sys, ref, true, "push")
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions docker/docker_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ func (ref dockerReference) NewImage(ctx context.Context, sys *types.SystemContex
// NewImageSource returns a types.ImageSource for this reference.
// The caller must call .Close() on the returned ImageSource.
func (ref dockerReference) NewImageSource(ctx context.Context, sys *types.SystemContext) (types.ImageSource, error) {
return newImageSource(ctx, sys, ref)
return newImageSource(sys, ref)
}

// NewImageDestination returns a types.ImageDestination for this reference.
// The caller must call .Close() on the returned ImageDestination.
func (ref dockerReference) NewImageDestination(ctx context.Context, sys *types.SystemContext) (types.ImageDestination, error) {
return newImageDestination(ctx, sys, ref)
return newImageDestination(sys, ref)
}

// DeleteImage deletes the named image from the registry, if supported.
Expand Down
2 changes: 2 additions & 0 deletions docker/tarfile/dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (d *Destination) PutBlob(ctx context.Context, stream io.Reader, inputInfo t

digester := digest.Canonical.Digester()
tee := io.TeeReader(stream, digester.Hash())
// TODO: This can take quite some time, and should ideally be cancellable using ctx.Done().
size, err := io.Copy(streamCopy, tee)
if err != nil {
return types.BlobInfo{}, err
Expand Down Expand Up @@ -352,6 +353,7 @@ func (d *Destination) sendFile(path string, expectedSize int64, stream io.Reader
if err := d.tar.WriteHeader(hdr); err != nil {
return err
}
// TODO: This can take quite some time, and should ideally be cancellable using a context.Context.
size, err := io.Copy(d.tar, stream)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions docker/tarfile/src.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func NewSourceFromStream(inputStream io.Reader) (*Source, error) {
}
}()

// TODO: This can take quite some time, and should ideally be cancellable using a context.Context.
if _, err := io.Copy(tarCopyFile, inputStream); err != nil {
return nil, errors.Wrapf(err, "error copying contents to temporary file %q", tarCopyFile.Name())
}
Expand Down
1 change: 1 addition & 0 deletions oci/archive/oci_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func tarDirectory(src, dst string) error {
defer outFile.Close()

// copies the contents of the directory to the tar file
// TODO: This can take quite some time, and should ideally be cancellable using a context.Context.
_, err = io.Copy(outFile, input)

return err
Expand Down
1 change: 1 addition & 0 deletions oci/archive/oci_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func createUntarTempDir(ref ociArchiveReference) (tempDirOCIRef, error) {
}
src := ref.resolvedFile
dst := tempDirRef.tempDirectory
// TODO: This can take quite some time, and should ideally be cancellable using a context.Context.
if err := archive.UntarPath(src, dst); err != nil {
if err := tempDirRef.deleteTempDir(); err != nil {
return tempDirOCIRef{}, errors.Wrapf(err, "error deleting temp directory %q", tempDirRef.tempDirectory)
Expand Down
3 changes: 2 additions & 1 deletion oci/layout/oci_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ociImageDestination struct {
}

// newImageDestination returns an ImageDestination for writing to an existing directory.
func newImageDestination(ctx context.Context, sys *types.SystemContext, ref ociReference) (types.ImageDestination, error) {
func newImageDestination(sys *types.SystemContext, ref ociReference) (types.ImageDestination, error) {
if ref.image == "" {
return nil, errors.Errorf("cannot save image with empty image.ref.name")
}
Expand Down Expand Up @@ -125,6 +125,7 @@ func (d *ociImageDestination) PutBlob(ctx context.Context, stream io.Reader, inp
digester := digest.Canonical.Digester()
tee := io.TeeReader(stream, digester.Hash())

// TODO: This can take quite some time, and should ideally be cancellable using ctx.Done().
size, err := io.Copy(blobFile, tee)
if err != nil {
return types.BlobInfo{}, err
Expand Down
2 changes: 1 addition & 1 deletion oci/layout/oci_dest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestPutManifestTwice(t *testing.T) {
}

func putTestManifest(t *testing.T, ociRef ociReference, tmpDir string) {
imageDest, err := newImageDestination(context.Background(), nil, ociRef)
imageDest, err := newImageDestination(nil, ociRef)
assert.NoError(t, err)

data := []byte("abc")
Expand Down
2 changes: 1 addition & 1 deletion oci/layout/oci_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ociImageSource struct {
}

// newImageSource returns an ImageSource for reading from an existing directory.
func newImageSource(ctx context.Context, sys *types.SystemContext, ref ociReference) (types.ImageSource, error) {
func newImageSource(sys *types.SystemContext, ref ociReference) (types.ImageSource, error) {
tr := tlsclientconfig.NewTransport()
tr.TLSClientConfig = tlsconfig.ServerDefault()

Expand Down
6 changes: 3 additions & 3 deletions oci/layout/oci_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (ref ociReference) PolicyConfigurationNamespaces() []string {
// verify that UnparsedImage, and convert it into a real Image via image.FromUnparsedImage.
// WARNING: This may not do the right thing for a manifest list, see image.FromSource for details.
func (ref ociReference) NewImage(ctx context.Context, sys *types.SystemContext) (types.ImageCloser, error) {
src, err := newImageSource(ctx, sys, ref)
src, err := newImageSource(sys, ref)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -219,13 +219,13 @@ func LoadManifestDescriptor(imgRef types.ImageReference) (imgspecv1.Descriptor,
// NewImageSource returns a types.ImageSource for this reference.
// The caller must call .Close() on the returned ImageSource.
func (ref ociReference) NewImageSource(ctx context.Context, sys *types.SystemContext) (types.ImageSource, error) {
return newImageSource(ctx, sys, ref)
return newImageSource(sys, ref)
}

// NewImageDestination returns a types.ImageDestination for this reference.
// The caller must call .Close() on the returned ImageDestination.
func (ref ociReference) NewImageDestination(ctx context.Context, sys *types.SystemContext) (types.ImageDestination, error) {
return newImageDestination(ctx, sys, ref)
return newImageDestination(sys, ref)
}

// DeleteImage deletes the named image from the registry, if supported.
Expand Down
2 changes: 1 addition & 1 deletion openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ type openshiftImageSource struct {

// newImageSource creates a new ImageSource for the specified reference.
// The caller must call .Close() on the returned ImageSource.
func newImageSource(ctx context.Context, sys *types.SystemContext, ref openshiftReference) (types.ImageSource, error) {
func newImageSource(sys *types.SystemContext, ref openshiftReference) (types.ImageSource, error) {
client, err := newOpenshiftClient(ref)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions openshift/openshift_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (ref openshiftReference) PolicyConfigurationNamespaces() []string {
// verify that UnparsedImage, and convert it into a real Image via image.FromUnparsedImage.
// WARNING: This may not do the right thing for a manifest list, see image.FromSource for details.
func (ref openshiftReference) NewImage(ctx context.Context, sys *types.SystemContext) (types.ImageCloser, error) {
src, err := newImageSource(ctx, sys, ref)
src, err := newImageSource(sys, ref)
if err != nil {
return nil, err
}
Expand All @@ -142,7 +142,7 @@ func (ref openshiftReference) NewImage(ctx context.Context, sys *types.SystemCon
// NewImageSource returns a types.ImageSource for this reference.
// The caller must call .Close() on the returned ImageSource.
func (ref openshiftReference) NewImageSource(ctx context.Context, sys *types.SystemContext) (types.ImageSource, error) {
return newImageSource(ctx, sys, ref)
return newImageSource(sys, ref)
}

// NewImageDestination returns a types.ImageDestination for this reference.
Expand Down
3 changes: 3 additions & 0 deletions ostree/ostree_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (d *ostreeImageDestination) PutBlob(ctx context.Context, stream io.Reader,
digester := digest.Canonical.Digester()
tee := io.TeeReader(stream, digester.Hash())

// TODO: This can take quite some time, and should ideally be cancellable using ctx.Done().
size, err := io.Copy(blobFile, tee)
if err != nil {
return types.BlobInfo{}, err
Expand Down Expand Up @@ -264,6 +265,8 @@ func generateTarSplitMetadata(output *bytes.Buffer, file string) (digest.Digest,
}

func (d *ostreeImageDestination) importBlob(selinuxHnd *C.struct_selabel_handle, repo *otbuiltin.Repo, blob *blobToImport) error {
// TODO: This can take quite some time, and should ideally be cancellable using a context.Context.

ostreeBranch := fmt.Sprintf("ociimage/%s", blob.Digest.Hex())
destinationPath := filepath.Join(d.tmpDirPath, blob.Digest.Hex(), "root")
if err := ensureDirectoryExists(destinationPath); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ostree/ostree_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ostreeImageSource struct {
}

// newImageSource returns an ImageSource for reading from an existing directory.
func newImageSource(ctx context.Context, tmpDir string, ref ostreeReference) (types.ImageSource, error) {
func newImageSource(tmpDir string, ref ostreeReference) (types.ImageSource, error) {
return &ostreeImageSource{ref: ref, tmpDir: tmpDir, compressed: nil}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions ostree/ostree_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (ref ostreeReference) NewImage(ctx context.Context, sys *types.SystemContex
} else {
tmpDir = sys.OSTreeTmpDirPath
}
src, err := newImageSource(ctx, tmpDir, ref)
src, err := newImageSource(tmpDir, ref)
if err != nil {
return nil, err
}
Expand All @@ -205,7 +205,7 @@ func (ref ostreeReference) NewImageSource(ctx context.Context, sys *types.System
} else {
tmpDir = sys.OSTreeTmpDirPath
}
return newImageSource(ctx, tmpDir, ref)
return newImageSource(tmpDir, ref)
}

// NewImageDestination returns a types.ImageDestination for this reference.
Expand Down
4 changes: 3 additions & 1 deletion storage/storage_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (s *storageImageSource) GetSignatures(ctx context.Context, instanceDigest *

// newImageDestination sets us up to write a new image, caching blobs in a temporary directory until
// it's time to Commit() the image
func newImageDestination(ctx context.Context, imageRef storageReference) (*storageImageDestination, error) {
func newImageDestination(imageRef storageReference) (*storageImageDestination, error) {
directory, err := ioutil.TempDir(temporaryDirectoryForBigFiles, "storage")
if err != nil {
return nil, errors.Wrapf(err, "error creating a temporary directory")
Expand Down Expand Up @@ -309,6 +309,7 @@ func (s *storageImageDestination) PutBlob(ctx context.Context, stream io.Reader,
return errorBlobInfo, errors.Wrap(err, "error setting up to decompress blob")
}
// Copy the data to the file.
// TODO: This can take quite some time, and should ideally be cancellable using ctx.Done().
_, err = io.Copy(diffID.Hash(), decompressed)
decompressed.Close()
if err != nil {
Expand Down Expand Up @@ -544,6 +545,7 @@ func (s *storageImageDestination) Commit(ctx context.Context) error {
return errors.Errorf("error applying blob %q: content not found", blob.Digest)
}
// Build the new layer using the diff, regardless of where it came from.
// TODO: This can take quite some time, and should ideally be cancellable using ctx.Done().
layer, _, err := s.imageRef.transport.store.PutLayer(id, lastLayer, nil, "", false, nil, diff)
if err != nil {
return errors.Wrapf(err, "error adding layer with blob %q", blob.Digest)
Expand Down
2 changes: 1 addition & 1 deletion storage/storage_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,5 @@ func (s storageReference) NewImageSource(ctx context.Context, sys *types.SystemC
}

func (s storageReference) NewImageDestination(ctx context.Context, sys *types.SystemContext) (types.ImageDestination, error) {
return newImageDestination(ctx, s)
return newImageDestination(s)
}
1 change: 1 addition & 0 deletions tarball/tarball_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (r *tarballReference) NewImageSource(ctx context.Context, sys *types.System
layerType = imgspecv1.MediaTypeImageLayer
uncompressed = nil
}
// TODO: This can take quite some time, and should ideally be cancellable using ctx.Done().
n, err := io.Copy(ioutil.Discard, reader)
if err != nil {
return nil, fmt.Errorf("error reading %q: %v", filename, err)
Expand Down