mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #15735 from tonistiigi/graph-register-readcloser
Make graph.Register take in io.Reader
This commit is contained in:
commit
1544c5edb6
3 changed files with 14 additions and 13 deletions
|
@ -1,8 +1,9 @@
|
||||||
package graphdriver
|
package graphdriver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/pkg/archive"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NOTE: These interfaces are used for implementing specific features of the Windows
|
// NOTE: These interfaces are used for implementing specific features of the Windows
|
||||||
|
@ -26,5 +27,5 @@ type Tagger interface {
|
||||||
// functions without needing to import graph.
|
// functions without needing to import graph.
|
||||||
type Recorder interface {
|
type Recorder interface {
|
||||||
Exists(id string) bool
|
Exists(id string) bool
|
||||||
Register(img *image.Image, layerData archive.Reader) error
|
Register(img *image.Image, layerData io.Reader) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,7 @@ func (graph *Graph) Get(name string) (*image.Image, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a new image and registers it in the graph.
|
// Create creates a new image and registers it in the graph.
|
||||||
func (graph *Graph) Create(layerData archive.Reader, containerID, containerImage, comment, author string, containerConfig, config *runconfig.Config) (*image.Image, error) {
|
func (graph *Graph) Create(layerData io.Reader, containerID, containerImage, comment, author string, containerConfig, config *runconfig.Config) (*image.Image, error) {
|
||||||
img := &image.Image{
|
img := &image.Image{
|
||||||
ID: stringid.GenerateRandomID(),
|
ID: stringid.GenerateRandomID(),
|
||||||
Comment: comment,
|
Comment: comment,
|
||||||
|
@ -224,7 +224,7 @@ func (graph *Graph) Create(layerData archive.Reader, containerID, containerImage
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register imports a pre-existing image into the graph.
|
// Register imports a pre-existing image into the graph.
|
||||||
func (graph *Graph) Register(img *image.Image, layerData archive.Reader) (err error) {
|
func (graph *Graph) Register(img *image.Image, layerData io.Reader) (err error) {
|
||||||
|
|
||||||
if err := image.ValidateID(img.ID); err != nil {
|
if err := image.ValidateID(img.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -286,7 +286,7 @@ func (graph *Graph) Register(img *image.Image, layerData archive.Reader) (err er
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRootFilesystemInDriver(graph *Graph, img *image.Image, layerData archive.Reader) error {
|
func createRootFilesystemInDriver(graph *Graph, img *image.Image, layerData io.Reader) error {
|
||||||
if err := graph.driver.Create(img.ID, img.Parent); err != nil {
|
if err := graph.driver.Create(img.ID, img.Parent); err != nil {
|
||||||
return fmt.Errorf("Driver %s failed to create image rootfs %s: %s", graph.driver, img.ID, err)
|
return fmt.Errorf("Driver %s failed to create image rootfs %s: %s", graph.driver, img.ID, err)
|
||||||
}
|
}
|
||||||
|
@ -451,7 +451,7 @@ func (graph *Graph) Heads() map[string]*image.Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TarLayer returns a tar archive of the image's filesystem layer.
|
// TarLayer returns a tar archive of the image's filesystem layer.
|
||||||
func (graph *Graph) TarLayer(img *image.Image) (arch archive.Archive, err error) {
|
func (graph *Graph) TarLayer(img *image.Image) (arch io.ReadCloser, err error) {
|
||||||
rdr, err := graph.assembleTarLayer(img)
|
rdr, err := graph.assembleTarLayer(img)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("[graph] TarLayer with traditional differ: %s", img.ID)
|
logrus.Debugf("[graph] TarLayer with traditional differ: %s", img.ID)
|
||||||
|
@ -556,7 +556,7 @@ func jsonPath(root string) string {
|
||||||
// storeImage stores file system layer data for the given image to the
|
// storeImage stores file system layer data for the given image to the
|
||||||
// graph's storage driver. Image metadata is stored in a file
|
// graph's storage driver. Image metadata is stored in a file
|
||||||
// at the specified root directory.
|
// at the specified root directory.
|
||||||
func (graph *Graph) storeImage(img *image.Image, layerData archive.Reader, root string) (err error) {
|
func (graph *Graph) storeImage(img *image.Image, layerData io.Reader, root string) (err error) {
|
||||||
// Store the layer. If layerData is not nil, unpack it into the new layer
|
// Store the layer. If layerData is not nil, unpack it into the new layer
|
||||||
if layerData != nil {
|
if layerData != nil {
|
||||||
if err := graph.disassembleAndApplyTarLayer(img, layerData, root); err != nil {
|
if err := graph.disassembleAndApplyTarLayer(img, layerData, root); err != nil {
|
||||||
|
@ -578,8 +578,8 @@ func (graph *Graph) storeImage(img *image.Image, layerData archive.Reader, root
|
||||||
return json.NewEncoder(f).Encode(img)
|
return json.NewEncoder(f).Encode(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (graph *Graph) disassembleAndApplyTarLayer(img *image.Image, layerData archive.Reader, root string) (err error) {
|
func (graph *Graph) disassembleAndApplyTarLayer(img *image.Image, layerData io.Reader, root string) (err error) {
|
||||||
var ar archive.Reader
|
var ar io.Reader
|
||||||
|
|
||||||
if graph.tarSplitDisabled {
|
if graph.tarSplitDisabled {
|
||||||
ar = layerData
|
ar = layerData
|
||||||
|
@ -617,7 +617,7 @@ func (graph *Graph) disassembleAndApplyTarLayer(img *image.Image, layerData arch
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (graph *Graph) assembleTarLayer(img *image.Image) (archive.Archive, error) {
|
func (graph *Graph) assembleTarLayer(img *image.Image) (io.ReadCloser, error) {
|
||||||
root := graph.imageRoot(img.ID)
|
root := graph.imageRoot(img.ID)
|
||||||
mFileName := filepath.Join(root, tarDataFileName)
|
mFileName := filepath.Join(root, tarDataFileName)
|
||||||
mf, err := os.Open(mFileName)
|
mf, err := os.Open(mFileName)
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
|
||||||
"github.com/docker/docker/pkg/httputils"
|
"github.com/docker/docker/pkg/httputils"
|
||||||
"github.com/docker/docker/pkg/progressreader"
|
"github.com/docker/docker/pkg/progressreader"
|
||||||
"github.com/docker/docker/pkg/streamformatter"
|
"github.com/docker/docker/pkg/streamformatter"
|
||||||
|
@ -20,13 +19,14 @@ import (
|
||||||
func (s *TagStore) Import(src string, repo string, tag string, inConfig io.ReadCloser, outStream io.Writer, containerConfig *runconfig.Config) error {
|
func (s *TagStore) Import(src string, repo string, tag string, inConfig io.ReadCloser, outStream io.Writer, containerConfig *runconfig.Config) error {
|
||||||
var (
|
var (
|
||||||
sf = streamformatter.NewJSONStreamFormatter()
|
sf = streamformatter.NewJSONStreamFormatter()
|
||||||
archive archive.Reader
|
archive io.ReadCloser
|
||||||
resp *http.Response
|
resp *http.Response
|
||||||
)
|
)
|
||||||
|
|
||||||
if src == "-" {
|
if src == "-" {
|
||||||
archive = inConfig
|
archive = inConfig
|
||||||
} else {
|
} else {
|
||||||
|
inConfig.Close()
|
||||||
u, err := url.Parse(src)
|
u, err := url.Parse(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -50,10 +50,10 @@ func (s *TagStore) Import(src string, repo string, tag string, inConfig io.ReadC
|
||||||
ID: "",
|
ID: "",
|
||||||
Action: "Importing",
|
Action: "Importing",
|
||||||
})
|
})
|
||||||
defer progressReader.Close()
|
|
||||||
archive = progressReader
|
archive = progressReader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer archive.Close()
|
||||||
img, err := s.graph.Create(archive, "", "", "Imported from "+src, "", nil, containerConfig)
|
img, err := s.graph.Create(archive, "", "", "Imported from "+src, "", nil, containerConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue