|
@@ -52,9 +52,9 @@ func (v *simpleVersionInfo) Version() string {
|
|
|
// docker, go, git-commit (of the docker) and the host's kernel.
|
|
|
//
|
|
|
// Such information will be used on call to NewRegistry().
|
|
|
-func (srv *Server) versionInfos() []registry.VersionInfo {
|
|
|
+func (srv *Server) versionInfos() []utils.VersionInfo {
|
|
|
v := srv.DockerVersion()
|
|
|
- ret := make([]registry.VersionInfo, 0, 4)
|
|
|
+ ret := make([]utils.VersionInfo, 0, 4)
|
|
|
ret = append(ret, &simpleVersionInfo{"docker", v.Version})
|
|
|
|
|
|
if len(v.GoVersion) > 0 {
|
|
@@ -102,7 +102,7 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error {
|
|
|
}
|
|
|
|
|
|
func (srv *Server) ImagesSearch(term string) ([]APISearch, error) {
|
|
|
- r, err := registry.NewRegistry(srv.runtime.root, nil, srv.versionInfos()...)
|
|
|
+ r, err := registry.NewRegistry(srv.runtime.root, nil, srv.HTTPRequestFactory())
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -145,7 +145,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.
|
|
|
return "", err
|
|
|
}
|
|
|
|
|
|
- if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, sf.FormatProgress("Downloading", "%8v/%v (%v)"), sf), path); err != nil {
|
|
|
+ if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, sf.FormatProgress("", "Downloading", "%8v/%v (%v)"), sf, true), path); err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
// FIXME: Handle custom repo, tag comment, author
|
|
@@ -153,7 +153,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
- out.Write(sf.FormatStatus(img.ID))
|
|
|
+ out.Write(sf.FormatStatus("", img.ID))
|
|
|
return img.ShortID(), nil
|
|
|
}
|
|
|
|
|
@@ -252,15 +252,31 @@ func (srv *Server) DockerInfo() *APIInfo {
|
|
|
} else {
|
|
|
imgcount = len(images)
|
|
|
}
|
|
|
+ lxcVersion := ""
|
|
|
+ if output, err := exec.Command("lxc-version").CombinedOutput(); err == nil {
|
|
|
+ outputStr := string(output)
|
|
|
+ if len(strings.SplitN(outputStr, ":", 2)) == 2 {
|
|
|
+ lxcVersion = strings.TrimSpace(strings.SplitN(string(output), ":", 2)[1])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ kernelVersion := "<unknown>"
|
|
|
+ if kv, err := utils.GetKernelVersion(); err == nil {
|
|
|
+ kernelVersion = kv.String()
|
|
|
+ }
|
|
|
+
|
|
|
return &APIInfo{
|
|
|
- Containers: len(srv.runtime.List()),
|
|
|
- Images: imgcount,
|
|
|
- MemoryLimit: srv.runtime.capabilities.MemoryLimit,
|
|
|
- SwapLimit: srv.runtime.capabilities.SwapLimit,
|
|
|
- Debug: os.Getenv("DEBUG") != "",
|
|
|
- NFd: utils.GetTotalUsedFds(),
|
|
|
- NGoroutines: runtime.NumGoroutine(),
|
|
|
- NEventsListener: len(srv.events),
|
|
|
+ Containers: len(srv.runtime.List()),
|
|
|
+ Images: imgcount,
|
|
|
+ MemoryLimit: srv.runtime.capabilities.MemoryLimit,
|
|
|
+ SwapLimit: srv.runtime.capabilities.SwapLimit,
|
|
|
+ IPv4Forwarding: srv.runtime.capabilities.IPv4Forwarding,
|
|
|
+ Debug: os.Getenv("DEBUG") != "",
|
|
|
+ NFd: utils.GetTotalUsedFds(),
|
|
|
+ NGoroutines: runtime.NumGoroutine(),
|
|
|
+ LXCVersion: lxcVersion,
|
|
|
+ NEventsListener: len(srv.events),
|
|
|
+ KernelVersion: kernelVersion,
|
|
|
+ IndexServerAddress: auth.IndexServerAddress(),
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -295,35 +311,34 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-func (srv *Server) ContainerTop(name string) ([]APITop, error) {
|
|
|
+func (srv *Server) ContainerTop(name, ps_args string) (*APITop, error) {
|
|
|
if container := srv.runtime.Get(name); container != nil {
|
|
|
- output, err := exec.Command("lxc-ps", "--name", container.ID).CombinedOutput()
|
|
|
+ output, err := exec.Command("lxc-ps", "--name", container.ID, "--", ps_args).CombinedOutput()
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("Error trying to use lxc-ps: %s (%s)", err, output)
|
|
|
}
|
|
|
- var procs []APITop
|
|
|
+ procs := APITop{}
|
|
|
for i, line := range strings.Split(string(output), "\n") {
|
|
|
- if i == 0 || len(line) == 0 {
|
|
|
+ if len(line) == 0 {
|
|
|
continue
|
|
|
}
|
|
|
- proc := APITop{}
|
|
|
+ words := []string{}
|
|
|
scanner := bufio.NewScanner(strings.NewReader(line))
|
|
|
scanner.Split(bufio.ScanWords)
|
|
|
if !scanner.Scan() {
|
|
|
return nil, fmt.Errorf("Error trying to use lxc-ps")
|
|
|
}
|
|
|
// no scanner.Text because we skip container id
|
|
|
- scanner.Scan()
|
|
|
- proc.PID = scanner.Text()
|
|
|
- scanner.Scan()
|
|
|
- proc.Tty = scanner.Text()
|
|
|
- scanner.Scan()
|
|
|
- proc.Time = scanner.Text()
|
|
|
- scanner.Scan()
|
|
|
- proc.Cmd = scanner.Text()
|
|
|
- procs = append(procs, proc)
|
|
|
+ for scanner.Scan() {
|
|
|
+ words = append(words, scanner.Text())
|
|
|
+ }
|
|
|
+ if i == 0 {
|
|
|
+ procs.Titles = words
|
|
|
+ } else {
|
|
|
+ procs.Processes = append(procs.Processes, words)
|
|
|
+ }
|
|
|
}
|
|
|
- return procs, nil
|
|
|
+ return &procs, nil
|
|
|
|
|
|
}
|
|
|
return nil, fmt.Errorf("No such container: %s", name)
|
|
@@ -407,7 +422,7 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoin
|
|
|
// FIXME: Launch the getRemoteImage() in goroutines
|
|
|
for _, id := range history {
|
|
|
if !srv.runtime.graph.Exists(id) {
|
|
|
- out.Write(sf.FormatStatus("Pulling %s metadata", id))
|
|
|
+ out.Write(sf.FormatStatus(utils.TruncateID(id), "Pulling metadata"))
|
|
|
imgJSON, imgSize, err := r.GetRemoteImageJSON(id, endpoint, token)
|
|
|
if err != nil {
|
|
|
// FIXME: Keep goging in case of error?
|
|
@@ -419,13 +434,13 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoin
|
|
|
}
|
|
|
|
|
|
// Get the layer
|
|
|
- out.Write(sf.FormatStatus("Pulling %s fs layer", id))
|
|
|
+ out.Write(sf.FormatStatus(utils.TruncateID(id), "Pulling fs layer"))
|
|
|
layer, err := r.GetRemoteImageLayer(img.ID, endpoint, token)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer layer.Close()
|
|
|
- if err := srv.runtime.graph.Register(utils.ProgressReader(layer, imgSize, out, sf.FormatProgress("Downloading", "%8v/%v (%v)"), sf), false, img); err != nil {
|
|
|
+ if err := srv.runtime.graph.Register(imgJSON, utils.ProgressReader(layer, imgSize, out, sf.FormatProgress(utils.TruncateID(id), "Downloading", "%8v/%v (%v)"), sf, false), img); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
@@ -433,20 +448,14 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoin
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName, remoteName, askedTag, indexEp string, sf *utils.StreamFormatter) error {
|
|
|
- out.Write(sf.FormatStatus("Pulling repository %s", localName))
|
|
|
+func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName, remoteName, askedTag, indexEp string, sf *utils.StreamFormatter, parallel bool) error {
|
|
|
+ out.Write(sf.FormatStatus("", "Pulling repository %s", localName))
|
|
|
|
|
|
repoData, err := r.GetRepositoryData(indexEp, remoteName)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- utils.Debugf("Updating checksums")
|
|
|
- // Reload the json file to make sure not to overwrite faster sums
|
|
|
- if err := srv.runtime.graph.UpdateChecksums(repoData.ImgList); err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
utils.Debugf("Retrieving the tag list")
|
|
|
tagsList, err := r.GetRemoteTags(repoData.Endpoints, remoteName, repoData.Tokens)
|
|
|
if err != nil {
|
|
@@ -477,30 +486,51 @@ func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName
|
|
|
repoData.ImgList[id].Tag = askedTag
|
|
|
}
|
|
|
|
|
|
- for _, img := range repoData.ImgList {
|
|
|
- if askedTag != "" && img.Tag != askedTag {
|
|
|
- utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.ID)
|
|
|
- continue
|
|
|
+ errors := make(chan error)
|
|
|
+ for _, image := range repoData.ImgList {
|
|
|
+ downloadImage := func(img *registry.ImgData) {
|
|
|
+ if askedTag != "" && img.Tag != askedTag {
|
|
|
+ utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.ID)
|
|
|
+ errors <- nil
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if img.Tag == "" {
|
|
|
+ utils.Debugf("Image (id: %s) present in this repository but untagged, skipping", img.ID)
|
|
|
+ errors <- nil
|
|
|
+ return
|
|
|
+ }
|
|
|
+ out.Write(sf.FormatStatus(utils.TruncateID(img.ID), "Pulling image (%s) from %s", img.Tag, localName))
|
|
|
+ success := false
|
|
|
+ for _, ep := range repoData.Endpoints {
|
|
|
+ if err := srv.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
|
|
|
+ out.Write(sf.FormatStatus(utils.TruncateID(img.ID), "Error while retrieving image for tag: %s (%s); checking next endpoint", askedTag, err))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ success = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ if !success {
|
|
|
+ errors <- fmt.Errorf("Could not find repository on any of the indexed registries.")
|
|
|
+ }
|
|
|
+ errors <- nil
|
|
|
}
|
|
|
|
|
|
- if img.Tag == "" {
|
|
|
- utils.Debugf("Image (id: %s) present in this repository but untagged, skipping", img.ID)
|
|
|
- continue
|
|
|
+ if parallel {
|
|
|
+ go downloadImage(image)
|
|
|
+ } else {
|
|
|
+ downloadImage(image)
|
|
|
}
|
|
|
- out.Write(sf.FormatStatus("Pulling image %s (%s) from %s", img.ID, img.Tag, localName))
|
|
|
- success := false
|
|
|
- for _, ep := range repoData.Endpoints {
|
|
|
- if err := srv.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
|
|
|
- out.Write(sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint", askedTag, err))
|
|
|
- continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if parallel {
|
|
|
+ for i := 0; i < len(repoData.ImgList); i++ {
|
|
|
+ if err := <-errors; err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
- success = true
|
|
|
- break
|
|
|
- }
|
|
|
- if !success {
|
|
|
- return fmt.Errorf("Could not find repository on any of the indexed registries.")
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
for tag, id := range tagsList {
|
|
|
if askedTag != "" && tag != askedTag {
|
|
|
continue
|
|
@@ -554,8 +584,8 @@ func (srv *Server) poolRemove(kind, key string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig) error {
|
|
|
- r, err := registry.NewRegistry(srv.runtime.root, authConfig, srv.versionInfos()...)
|
|
|
+func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *utils.StreamFormatter, authConfig *auth.AuthConfig, parallel bool) error {
|
|
|
+ r, err := registry.NewRegistry(srv.runtime.root, authConfig, srv.HTTPRequestFactory())
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -576,7 +606,7 @@ func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *ut
|
|
|
}
|
|
|
|
|
|
out = utils.NewWriteFlusher(out)
|
|
|
- err = srv.pullRepository(r, out, localName, remoteName, tag, endpoint, sf)
|
|
|
+ err = srv.pullRepository(r, out, localName, remoteName, tag, endpoint, sf, parallel)
|
|
|
if err != nil {
|
|
|
if err := srv.pullImage(r, out, remoteName, endpoint, nil, sf); err != nil {
|
|
|
return err
|
|
@@ -587,41 +617,6 @@ func (srv *Server) ImagePull(localName string, tag string, out io.Writer, sf *ut
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// Retrieve the checksum of an image
|
|
|
-// Priority:
|
|
|
-// - Check on the stored checksums
|
|
|
-// - Check if the archive exists, if it does not, ask the registry
|
|
|
-// - If the archive does exists, process the checksum from it
|
|
|
-// - If the archive does not exists and not found on registry, process checksum from layer
|
|
|
-func (srv *Server) getChecksum(imageID string) (string, error) {
|
|
|
- // FIXME: Use in-memory map instead of reading the file each time
|
|
|
- if sums, err := srv.runtime.graph.getStoredChecksums(); err != nil {
|
|
|
- return "", err
|
|
|
- } else if checksum, exists := sums[imageID]; exists {
|
|
|
- return checksum, nil
|
|
|
- }
|
|
|
-
|
|
|
- img, err := srv.runtime.graph.Get(imageID)
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
-
|
|
|
- if _, err := os.Stat(layerArchivePath(srv.runtime.graph.imageRoot(imageID))); err != nil {
|
|
|
- if os.IsNotExist(err) {
|
|
|
- // TODO: Ask the registry for the checksum
|
|
|
- // As the archive is not there, it is supposed to come from a pull.
|
|
|
- } else {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- checksum, err := img.Checksum()
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- return checksum, nil
|
|
|
-}
|
|
|
-
|
|
|
// Retrieve the all the images to be uploaded in the correct order
|
|
|
// Note: we can't use a map as it is not ordered
|
|
|
func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgData, error) {
|
|
@@ -638,14 +633,10 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat
|
|
|
return nil
|
|
|
}
|
|
|
imageSet[img.ID] = struct{}{}
|
|
|
- checksum, err := srv.getChecksum(img.ID)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
+
|
|
|
imgList = append([]*registry.ImgData{{
|
|
|
- ID: img.ID,
|
|
|
- Checksum: checksum,
|
|
|
- Tag: tag,
|
|
|
+ ID: img.ID,
|
|
|
+ Tag: tag,
|
|
|
}}, imgList...)
|
|
|
return nil
|
|
|
})
|
|
@@ -655,12 +646,11 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat
|
|
|
|
|
|
func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, localName, remoteName string, localRepo map[string]string, indexEp string, sf *utils.StreamFormatter) error {
|
|
|
out = utils.NewWriteFlusher(out)
|
|
|
- out.Write(sf.FormatStatus("Processing checksums"))
|
|
|
imgList, err := srv.getImageList(localRepo)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- out.Write(sf.FormatStatus("Sending image list"))
|
|
|
+ out.Write(sf.FormatStatus("", "Sending image list"))
|
|
|
|
|
|
var repoData *registry.RepositoryData
|
|
|
repoData, err = r.PushImageJSONIndex(indexEp, remoteName, imgList, false, nil)
|
|
@@ -669,21 +659,23 @@ func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, localName
|
|
|
}
|
|
|
|
|
|
for _, ep := range repoData.Endpoints {
|
|
|
- out.Write(sf.FormatStatus("Pushing repository %s (%d tags)", localName, len(localRepo)))
|
|
|
+ out.Write(sf.FormatStatus("", "Pushing repository %s (%d tags)", localName, len(localRepo)))
|
|
|
// For each image within the repo, push them
|
|
|
for _, elem := range imgList {
|
|
|
if _, exists := repoData.ImgList[elem.ID]; exists {
|
|
|
- out.Write(sf.FormatStatus("Image %s already pushed, skipping", elem.ID))
|
|
|
+ out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", elem.ID))
|
|
|
continue
|
|
|
} else if r.LookupRemoteImage(elem.ID, ep, repoData.Tokens) {
|
|
|
- out.Write(sf.FormatStatus("Image %s already pushed, skipping", elem.ID))
|
|
|
+ out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", elem.ID))
|
|
|
continue
|
|
|
}
|
|
|
- if err := srv.pushImage(r, out, remoteName, elem.ID, ep, repoData.Tokens, sf); err != nil {
|
|
|
+ if checksum, err := srv.pushImage(r, out, remoteName, elem.ID, ep, repoData.Tokens, sf); err != nil {
|
|
|
// FIXME: Continue on error?
|
|
|
return err
|
|
|
+ } else {
|
|
|
+ elem.Checksum = checksum
|
|
|
}
|
|
|
- out.Write(sf.FormatStatus("Pushing tags for rev [%s] on {%s}", elem.ID, ep+"repositories/"+remoteName+"/tags/"+elem.Tag))
|
|
|
+ out.Write(sf.FormatStatus("", "Pushing tags for rev [%s] on {%s}", elem.ID, ep+"repositories/"+remoteName+"/tags/"+elem.Tag))
|
|
|
if err := r.PushRegistryTag(remoteName, elem.ID, elem.Tag, ep, repoData.Tokens); err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -697,64 +689,45 @@ func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, localName
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgID, ep string, token []string, sf *utils.StreamFormatter) error {
|
|
|
+func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgID, ep string, token []string, sf *utils.StreamFormatter) (checksum string, err error) {
|
|
|
out = utils.NewWriteFlusher(out)
|
|
|
jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgID, "json"))
|
|
|
if err != nil {
|
|
|
- return fmt.Errorf("Error while retreiving the path for {%s}: %s", imgID, err)
|
|
|
+ return "", fmt.Errorf("Error while retreiving the path for {%s}: %s", imgID, err)
|
|
|
}
|
|
|
- out.Write(sf.FormatStatus("Pushing %s", imgID))
|
|
|
+ out.Write(sf.FormatStatus("", "Pushing %s", imgID))
|
|
|
|
|
|
- // Make sure we have the image's checksum
|
|
|
- checksum, err := srv.getChecksum(imgID)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
imgData := ®istry.ImgData{
|
|
|
- ID: imgID,
|
|
|
- Checksum: checksum,
|
|
|
+ ID: imgID,
|
|
|
}
|
|
|
|
|
|
// Send the json
|
|
|
if err := r.PushImageJSONRegistry(imgData, jsonRaw, ep, token); err != nil {
|
|
|
if err == registry.ErrAlreadyExists {
|
|
|
- out.Write(sf.FormatStatus("Image %s already pushed, skipping", imgData.ID))
|
|
|
- return nil
|
|
|
+ out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", imgData.ID))
|
|
|
+ return "", nil
|
|
|
}
|
|
|
- return err
|
|
|
+ return "", err
|
|
|
}
|
|
|
|
|
|
- // Retrieve the tarball to be sent
|
|
|
- var layerData *TempArchive
|
|
|
- // If the archive exists, use it
|
|
|
- file, err := os.Open(layerArchivePath(srv.runtime.graph.imageRoot(imgID)))
|
|
|
+ layerData, err := srv.runtime.graph.TempLayerArchive(imgID, Uncompressed, sf, out)
|
|
|
if err != nil {
|
|
|
- if os.IsNotExist(err) {
|
|
|
- // If the archive does not exist, create one from the layer
|
|
|
- layerData, err = srv.runtime.graph.TempLayerArchive(imgID, Xz, sf, out)
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("Failed to generate layer archive: %s", err)
|
|
|
- }
|
|
|
- } else {
|
|
|
- return err
|
|
|
- }
|
|
|
- } else {
|
|
|
- defer file.Close()
|
|
|
- st, err := file.Stat()
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- layerData = &TempArchive{
|
|
|
- File: file,
|
|
|
- Size: st.Size(),
|
|
|
- }
|
|
|
+ return "", fmt.Errorf("Failed to generate layer archive: %s", err)
|
|
|
}
|
|
|
|
|
|
// Send the layer
|
|
|
- if err := r.PushImageLayerRegistry(imgData.ID, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("Pushing", "%8v/%v (%v)"), sf), ep, token); err != nil {
|
|
|
- return err
|
|
|
+ if checksum, err := r.PushImageLayerRegistry(imgData.ID, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("", "Pushing", "%8v/%v (%v)"), sf, true), ep, token, jsonRaw); err != nil {
|
|
|
+ return "", err
|
|
|
+ } else {
|
|
|
+ imgData.Checksum = checksum
|
|
|
}
|
|
|
- return nil
|
|
|
+
|
|
|
+ // Send the checksum
|
|
|
+ if err := r.PushImageChecksumRegistry(imgData, ep, token); err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+
|
|
|
+ return imgData.Checksum, nil
|
|
|
}
|
|
|
|
|
|
// FIXME: Allow to interupt current push when new push of same image is done.
|
|
@@ -772,14 +745,14 @@ func (srv *Server) ImagePush(localName string, out io.Writer, sf *utils.StreamFo
|
|
|
|
|
|
out = utils.NewWriteFlusher(out)
|
|
|
img, err := srv.runtime.graph.Get(localName)
|
|
|
- r, err2 := registry.NewRegistry(srv.runtime.root, authConfig, srv.versionInfos()...)
|
|
|
+ r, err2 := registry.NewRegistry(srv.runtime.root, authConfig, srv.HTTPRequestFactory())
|
|
|
if err2 != nil {
|
|
|
return err2
|
|
|
}
|
|
|
|
|
|
if err != nil {
|
|
|
reposLen := len(srv.runtime.repositories.Repositories[localName])
|
|
|
- out.Write(sf.FormatStatus("The push refers to a repository [%s] (len: %d)", localName, reposLen))
|
|
|
+ out.Write(sf.FormatStatus("", "The push refers to a repository [%s] (len: %d)", localName, reposLen))
|
|
|
// If it fails, try to get the repository
|
|
|
if localRepo, exists := srv.runtime.repositories.Repositories[localName]; exists {
|
|
|
if err := srv.pushRepository(r, out, localName, remoteName, localRepo, endpoint, sf); err != nil {
|
|
@@ -791,8 +764,8 @@ func (srv *Server) ImagePush(localName string, out io.Writer, sf *utils.StreamFo
|
|
|
}
|
|
|
|
|
|
var token []string
|
|
|
- out.Write(sf.FormatStatus("The push refers to an image: [%s]", localName))
|
|
|
- if err := srv.pushImage(r, out, remoteName, img.ID, endpoint, token, sf); err != nil {
|
|
|
+ out.Write(sf.FormatStatus("", "The push refers to an image: [%s]", localName))
|
|
|
+ if _, err := srv.pushImage(r, out, remoteName, img.ID, endpoint, token, sf); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
@@ -814,14 +787,14 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write
|
|
|
u.Host = src
|
|
|
u.Path = ""
|
|
|
}
|
|
|
- out.Write(sf.FormatStatus("Downloading from %s", u))
|
|
|
+ out.Write(sf.FormatStatus("", "Downloading from %s", u))
|
|
|
// Download with curl (pretty progress bar)
|
|
|
// If curl is not available, fallback to http.Get()
|
|
|
resp, err = utils.Download(u.String(), out)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- archive = utils.ProgressReader(resp.Body, int(resp.ContentLength), out, sf.FormatProgress("Importing", "%8v/%v (%v)"), sf)
|
|
|
+ archive = utils.ProgressReader(resp.Body, int(resp.ContentLength), out, sf.FormatProgress("", "Importing", "%8v/%v (%v)"), sf, true)
|
|
|
}
|
|
|
img, err := srv.runtime.graph.Create(archive, nil, "Imported from "+src, "", nil)
|
|
|
if err != nil {
|
|
@@ -833,7 +806,7 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
- out.Write(sf.FormatStatus(img.ShortID()))
|
|
|
+ out.Write(sf.FormatStatus("", img.ShortID()))
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -984,6 +957,9 @@ func (srv *Server) deleteImage(img *Image, repoName, tag string) ([]APIRmi, erro
|
|
|
parsedRepo := strings.Split(repoAndTag, ":")[0]
|
|
|
if strings.Contains(img.ID, repoName) {
|
|
|
repoName = parsedRepo
|
|
|
+ if len(srv.runtime.repositories.ByID()[img.ID]) == 1 && len(strings.Split(repoAndTag, ":")) > 1 {
|
|
|
+ tag = strings.Split(repoAndTag, ":")[1]
|
|
|
+ }
|
|
|
} else if repoName != parsedRepo {
|
|
|
// the id belongs to multiple repos, like base:latest and user:test,
|
|
|
// in that case return conflict
|
|
@@ -1026,13 +1002,7 @@ func (srv *Server) ImageDelete(name string, autoPrune bool) ([]APIRmi, error) {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
- var tag string
|
|
|
- if strings.Contains(name, ":") {
|
|
|
- nameParts := strings.Split(name, ":")
|
|
|
- name = nameParts[0]
|
|
|
- tag = nameParts[1]
|
|
|
- }
|
|
|
-
|
|
|
+ name, tag := utils.ParseRepositoryTag(name)
|
|
|
return srv.deleteImage(img, name, tag)
|
|
|
}
|
|
|
|
|
@@ -1204,6 +1174,23 @@ func (srv *Server) ImageInspect(name string) (*Image, error) {
|
|
|
return nil, fmt.Errorf("No such image: %s", name)
|
|
|
}
|
|
|
|
|
|
+func (srv *Server) ContainerCopy(name string, resource string, out io.Writer) error {
|
|
|
+ if container := srv.runtime.Get(name); container != nil {
|
|
|
+
|
|
|
+ data, err := container.Copy(resource)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ if _, err := io.Copy(out, data); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return fmt.Errorf("No such container: %s", name)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
func NewServer(flGraphPath string, autoRestart, enableCors bool, dns ListOpts) (*Server, error) {
|
|
|
if runtime.GOARCH != "amd64" {
|
|
|
log.Fatalf("The docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH)
|
|
@@ -1219,11 +1206,21 @@ func NewServer(flGraphPath string, autoRestart, enableCors bool, dns ListOpts) (
|
|
|
pushingPool: make(map[string]struct{}),
|
|
|
events: make([]utils.JSONMessage, 0, 64), //only keeps the 64 last events
|
|
|
listeners: make(map[string]chan utils.JSONMessage),
|
|
|
+ reqFactory: nil,
|
|
|
}
|
|
|
runtime.srv = srv
|
|
|
return srv, nil
|
|
|
}
|
|
|
|
|
|
+func (srv *Server) HTTPRequestFactory() *utils.HTTPRequestFactory {
|
|
|
+ if srv.reqFactory == nil {
|
|
|
+ ud := utils.NewHTTPUserAgentDecorator(srv.versionInfos()...)
|
|
|
+ factory := utils.NewHTTPRequestFactory(ud)
|
|
|
+ srv.reqFactory = factory
|
|
|
+ }
|
|
|
+ return srv.reqFactory
|
|
|
+}
|
|
|
+
|
|
|
func (srv *Server) LogEvent(action, id string) {
|
|
|
now := time.Now().Unix()
|
|
|
jm := utils.JSONMessage{Status: action, ID: id, Time: now}
|
|
@@ -1244,4 +1241,5 @@ type Server struct {
|
|
|
pushingPool map[string]struct{}
|
|
|
events []utils.JSONMessage
|
|
|
listeners map[string]chan utils.JSONMessage
|
|
|
+ reqFactory *utils.HTTPRequestFactory
|
|
|
}
|