|
@@ -16,8 +16,12 @@ import (
|
|
"strings"
|
|
"strings"
|
|
)
|
|
)
|
|
|
|
|
|
-func (srv *Server) DockerVersion() ApiVersion {
|
|
|
|
- return ApiVersion{VERSION, GIT_COMMIT, srv.runtime.capabilities.MemoryLimit, srv.runtime.capabilities.SwapLimit}
|
|
|
|
|
|
+func (srv *Server) DockerVersion() APIVersion {
|
|
|
|
+ return APIVersion{
|
|
|
|
+ Version: VERSION,
|
|
|
|
+ GitCommit: GITCOMMIT,
|
|
|
|
+ GoVersion: runtime.Version(),
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func (srv *Server) ContainerKill(name string) error {
|
|
func (srv *Server) ContainerKill(name string) error {
|
|
@@ -48,16 +52,16 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error {
|
|
return fmt.Errorf("No such container: %s", name)
|
|
return fmt.Errorf("No such container: %s", name)
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) {
|
|
|
|
|
|
+func (srv *Server) ImagesSearch(term string) ([]APISearch, error) {
|
|
|
|
|
|
results, err := registry.NewRegistry(srv.runtime.root).SearchRepositories(term)
|
|
results, err := registry.NewRegistry(srv.runtime.root).SearchRepositories(term)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- var outs []ApiSearch
|
|
|
|
|
|
+ var outs []APISearch
|
|
for _, repo := range results.Results {
|
|
for _, repo := range results.Results {
|
|
- var out ApiSearch
|
|
|
|
|
|
+ var out APISearch
|
|
out.Description = repo["description"]
|
|
out.Description = repo["description"]
|
|
if len(out.Description) > 45 {
|
|
if len(out.Description) > 45 {
|
|
out.Description = utils.Trunc(out.Description, 42) + "..."
|
|
out.Description = utils.Trunc(out.Description, 42) + "..."
|
|
@@ -68,7 +72,7 @@ func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) {
|
|
return outs, nil
|
|
return outs, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) ImageInsert(name, url, path string, out io.Writer) (string, error) {
|
|
|
|
|
|
+func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.StreamFormatter) (string, error) {
|
|
out = utils.NewWriteFlusher(out)
|
|
out = utils.NewWriteFlusher(out)
|
|
img, err := srv.runtime.repositories.LookupImage(name)
|
|
img, err := srv.runtime.repositories.LookupImage(name)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -81,7 +85,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer) (string, e
|
|
}
|
|
}
|
|
defer file.Body.Close()
|
|
defer file.Body.Close()
|
|
|
|
|
|
- config, _, err := ParseRun([]string{img.Id, "echo", "insert", url, path}, srv.runtime.capabilities)
|
|
|
|
|
|
+ config, _, err := ParseRun([]string{img.ID, "echo", "insert", url, path}, srv.runtime.capabilities)
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
@@ -92,7 +96,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer) (string, e
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
|
|
|
|
- if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, "Downloading %v/%v (%v)\r", false), path); err != nil {
|
|
|
|
|
|
+ if err := c.Inject(utils.ProgressReader(file.Body, int(file.ContentLength), out, sf.FormatProgress("Downloading", "%v/%v (%v)"), sf), path); err != nil {
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
// FIXME: Handle custom repo, tag comment, author
|
|
// FIXME: Handle custom repo, tag comment, author
|
|
@@ -100,8 +104,8 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer) (string, e
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
- fmt.Fprintf(out, "%s\n", img.Id)
|
|
|
|
- return img.ShortId(), nil
|
|
|
|
|
|
+ out.Write(sf.FormatStatus(img.ID))
|
|
|
|
+ return img.ShortID(), nil
|
|
}
|
|
}
|
|
|
|
|
|
func (srv *Server) ImagesViz(out io.Writer) error {
|
|
func (srv *Server) ImagesViz(out io.Writer) error {
|
|
@@ -121,9 +125,9 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
|
return fmt.Errorf("Error while getting parent image: %v", err)
|
|
return fmt.Errorf("Error while getting parent image: %v", err)
|
|
}
|
|
}
|
|
if parentImage != nil {
|
|
if parentImage != nil {
|
|
- out.Write([]byte(" \"" + parentImage.ShortId() + "\" -> \"" + image.ShortId() + "\"\n"))
|
|
|
|
|
|
+ out.Write([]byte(" \"" + parentImage.ShortID() + "\" -> \"" + image.ShortID() + "\"\n"))
|
|
} else {
|
|
} else {
|
|
- out.Write([]byte(" base -> \"" + image.ShortId() + "\" [style=invis]\n"))
|
|
|
|
|
|
+ out.Write([]byte(" base -> \"" + image.ShortID() + "\" [style=invis]\n"))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -131,7 +135,7 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
|
|
|
|
|
for name, repository := range srv.runtime.repositories.Repositories {
|
|
for name, repository := range srv.runtime.repositories.Repositories {
|
|
for tag, id := range repository {
|
|
for tag, id := range repository {
|
|
- reporefs[utils.TruncateId(id)] = append(reporefs[utils.TruncateId(id)], fmt.Sprintf("%s:%s", name, tag))
|
|
|
|
|
|
+ reporefs[utils.TruncateID(id)] = append(reporefs[utils.TruncateID(id)], fmt.Sprintf("%s:%s", name, tag))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -142,7 +146,7 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
|
|
|
|
|
+func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
|
|
var (
|
|
var (
|
|
allImages map[string]*Image
|
|
allImages map[string]*Image
|
|
err error
|
|
err error
|
|
@@ -155,13 +159,13 @@ func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
- outs := []ApiImages{} //produce [] when empty instead of 'null'
|
|
|
|
|
|
+ outs := []APIImages{} //produce [] when empty instead of 'null'
|
|
for name, repository := range srv.runtime.repositories.Repositories {
|
|
for name, repository := range srv.runtime.repositories.Repositories {
|
|
if filter != "" && name != filter {
|
|
if filter != "" && name != filter {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
for tag, id := range repository {
|
|
for tag, id := range repository {
|
|
- var out ApiImages
|
|
|
|
|
|
+ var out APIImages
|
|
image, err := srv.runtime.graph.Get(id)
|
|
image, err := srv.runtime.graph.Get(id)
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Printf("Warning: couldn't load %s from %s/%s: %s", id, name, tag, err)
|
|
log.Printf("Warning: couldn't load %s from %s/%s: %s", id, name, tag, err)
|
|
@@ -170,7 +174,7 @@ func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
|
delete(allImages, id)
|
|
delete(allImages, id)
|
|
out.Repository = name
|
|
out.Repository = name
|
|
out.Tag = tag
|
|
out.Tag = tag
|
|
- out.Id = image.Id
|
|
|
|
|
|
+ out.ID = image.ID
|
|
out.Created = image.Created.Unix()
|
|
out.Created = image.Created.Unix()
|
|
out.Size = image.Size
|
|
out.Size = image.Size
|
|
out.ParentSize = image.getVirtualSize(0)
|
|
out.ParentSize = image.getVirtualSize(0)
|
|
@@ -180,8 +184,8 @@ func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
|
// Display images which aren't part of a
|
|
// Display images which aren't part of a
|
|
if filter == "" {
|
|
if filter == "" {
|
|
for _, image := range allImages {
|
|
for _, image := range allImages {
|
|
- var out ApiImages
|
|
|
|
- out.Id = image.Id
|
|
|
|
|
|
+ var out APIImages
|
|
|
|
+ out.ID = image.ID
|
|
out.Created = image.Created.Unix()
|
|
out.Created = image.Created.Unix()
|
|
out.Size = image.Size
|
|
out.Size = image.Size
|
|
out.ParentSize = image.getVirtualSize(0)
|
|
out.ParentSize = image.getVirtualSize(0)
|
|
@@ -191,7 +195,7 @@ func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
|
return outs, nil
|
|
return outs, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) DockerInfo() ApiInfo {
|
|
|
|
|
|
+func (srv *Server) DockerInfo() *APIInfo {
|
|
images, _ := srv.runtime.graph.All()
|
|
images, _ := srv.runtime.graph.All()
|
|
var imgcount int
|
|
var imgcount int
|
|
if images == nil {
|
|
if images == nil {
|
|
@@ -199,29 +203,27 @@ func (srv *Server) DockerInfo() ApiInfo {
|
|
} else {
|
|
} else {
|
|
imgcount = len(images)
|
|
imgcount = len(images)
|
|
}
|
|
}
|
|
- var out ApiInfo
|
|
|
|
- out.Containers = len(srv.runtime.List())
|
|
|
|
- out.Version = VERSION
|
|
|
|
- out.Images = imgcount
|
|
|
|
- out.GoVersion = runtime.Version()
|
|
|
|
- if os.Getenv("DEBUG") != "" {
|
|
|
|
- out.Debug = true
|
|
|
|
- out.NFd = utils.GetTotalUsedFds()
|
|
|
|
- out.NGoroutines = runtime.NumGoroutine()
|
|
|
|
|
|
+ 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(),
|
|
}
|
|
}
|
|
- return out
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) ImageHistory(name string) ([]ApiHistory, error) {
|
|
|
|
|
|
+func (srv *Server) ImageHistory(name string) ([]APIHistory, error) {
|
|
image, err := srv.runtime.repositories.LookupImage(name)
|
|
image, err := srv.runtime.repositories.LookupImage(name)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- var outs []ApiHistory = []ApiHistory{} //produce [] when empty instead of 'null'
|
|
|
|
|
|
+ outs := []APIHistory{} //produce [] when empty instead of 'null'
|
|
err = image.WalkHistory(func(img *Image) error {
|
|
err = image.WalkHistory(func(img *Image) error {
|
|
- var out ApiHistory
|
|
|
|
- out.Id = srv.runtime.repositories.ImageName(img.ShortId())
|
|
|
|
|
|
+ var out APIHistory
|
|
|
|
+ out.ID = srv.runtime.repositories.ImageName(img.ShortID())
|
|
out.Created = img.Created.Unix()
|
|
out.Created = img.Created.Unix()
|
|
out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ")
|
|
out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ")
|
|
outs = append(outs, out)
|
|
outs = append(outs, out)
|
|
@@ -238,17 +240,17 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) {
|
|
return nil, fmt.Errorf("No such container: %s", name)
|
|
return nil, fmt.Errorf("No such container: %s", name)
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) Containers(all bool, n int, since, before string) []ApiContainers {
|
|
|
|
|
|
+func (srv *Server) Containers(all bool, n int, since, before string) []APIContainers {
|
|
var foundBefore bool
|
|
var foundBefore bool
|
|
var displayed int
|
|
var displayed int
|
|
- retContainers := []ApiContainers{}
|
|
|
|
|
|
+ retContainers := []APIContainers{}
|
|
|
|
|
|
for _, container := range srv.runtime.List() {
|
|
for _, container := range srv.runtime.List() {
|
|
if !container.State.Running && !all && n == -1 && since == "" && before == "" {
|
|
if !container.State.Running && !all && n == -1 && since == "" && before == "" {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
if before != "" {
|
|
if before != "" {
|
|
- if container.ShortId() == before {
|
|
|
|
|
|
+ if container.ShortID() == before {
|
|
foundBefore = true
|
|
foundBefore = true
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
@@ -259,13 +261,13 @@ func (srv *Server) Containers(all bool, n int, since, before string) []ApiContai
|
|
if displayed == n {
|
|
if displayed == n {
|
|
break
|
|
break
|
|
}
|
|
}
|
|
- if container.ShortId() == since {
|
|
|
|
|
|
+ if container.ShortID() == since {
|
|
break
|
|
break
|
|
}
|
|
}
|
|
displayed++
|
|
displayed++
|
|
|
|
|
|
- c := ApiContainers{
|
|
|
|
- Id: container.Id,
|
|
|
|
|
|
+ c := APIContainers{
|
|
|
|
+ ID: container.ID,
|
|
}
|
|
}
|
|
c.Image = srv.runtime.repositories.ImageName(container.Image)
|
|
c.Image = srv.runtime.repositories.ImageName(container.Image)
|
|
c.Command = fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
|
c.Command = fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
|
@@ -288,7 +290,7 @@ func (srv *Server) ContainerCommit(name, repo, tag, author, comment string, conf
|
|
if err != nil {
|
|
if err != nil {
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
- return img.ShortId(), err
|
|
|
|
|
|
+ return img.ShortID(), err
|
|
}
|
|
}
|
|
|
|
|
|
func (srv *Server) ContainerTag(name, repo, tag string, force bool) error {
|
|
func (srv *Server) ContainerTag(name, repo, tag string, force bool) error {
|
|
@@ -298,7 +300,7 @@ func (srv *Server) ContainerTag(name, repo, tag string, force bool) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgId, endpoint string, token []string, json bool) error {
|
|
|
|
|
|
+func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgId, endpoint string, token []string, sf *utils.StreamFormatter) error {
|
|
history, err := r.GetRemoteHistory(imgId, endpoint, token)
|
|
history, err := r.GetRemoteHistory(imgId, endpoint, token)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -308,24 +310,25 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgId, endpoin
|
|
// FIXME: Launch the getRemoteImage() in goroutines
|
|
// FIXME: Launch the getRemoteImage() in goroutines
|
|
for _, id := range history {
|
|
for _, id := range history {
|
|
if !srv.runtime.graph.Exists(id) {
|
|
if !srv.runtime.graph.Exists(id) {
|
|
- fmt.Fprintf(out, utils.FormatStatus("Pulling %s metadata", json), id)
|
|
|
|
- imgJson, err := r.GetRemoteImageJson(id, endpoint, token)
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("Pulling %s metadata", id))
|
|
|
|
+ imgJSON, err := r.GetRemoteImageJSON(id, endpoint, token)
|
|
if err != nil {
|
|
if err != nil {
|
|
// FIXME: Keep goging in case of error?
|
|
// FIXME: Keep goging in case of error?
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- img, err := NewImgJson(imgJson)
|
|
|
|
|
|
+ img, err := NewImgJSON(imgJSON)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("Failed to parse json: %s", err)
|
|
return fmt.Errorf("Failed to parse json: %s", err)
|
|
}
|
|
}
|
|
|
|
|
|
// Get the layer
|
|
// Get the layer
|
|
- fmt.Fprintf(out, utils.FormatStatus("Pulling %s fs layer", json), id)
|
|
|
|
- layer, contentLength, err := r.GetRemoteImageLayer(img.Id, endpoint, token)
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("Pulling %s fs layer", id))
|
|
|
|
+ layer, contentLength, err := r.GetRemoteImageLayer(img.ID, endpoint, token)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- if err := srv.runtime.graph.Register(utils.ProgressReader(layer, contentLength, out, utils.FormatProgress("%v/%v (%v)", json), json), false, img); err != nil {
|
|
|
|
|
|
+ defer layer.Close()
|
|
|
|
+ if err := srv.runtime.graph.Register(utils.ProgressReader(layer, contentLength, out, sf.FormatProgress("Downloading", "%v/%v (%v)"), sf), false, img); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -333,8 +336,8 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgId, endpoin
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, remote, askedTag string, json bool) error {
|
|
|
|
- fmt.Fprintf(out, utils.FormatStatus("Pulling repository %s from %s", json), remote, auth.IndexServerAddress())
|
|
|
|
|
|
+func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, remote, askedTag string, sf *utils.StreamFormatter) error {
|
|
|
|
+ out.Write(sf.FormatStatus("Pulling repository %s from %s", remote, auth.IndexServerAddress()))
|
|
repoData, err := r.GetRepositoryData(remote)
|
|
repoData, err := r.GetRepositoryData(remote)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -359,23 +362,23 @@ func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, remote, a
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// Otherwise, check that the tag exists and use only that one
|
|
// Otherwise, check that the tag exists and use only that one
|
|
- if id, exists := tagsList[askedTag]; !exists {
|
|
|
|
|
|
+ id, exists := tagsList[askedTag]
|
|
|
|
+ if !exists {
|
|
return fmt.Errorf("Tag %s not found in repositoy %s", askedTag, remote)
|
|
return fmt.Errorf("Tag %s not found in repositoy %s", askedTag, remote)
|
|
- } else {
|
|
|
|
- repoData.ImgList[id].Tag = askedTag
|
|
|
|
}
|
|
}
|
|
|
|
+ repoData.ImgList[id].Tag = askedTag
|
|
}
|
|
}
|
|
|
|
|
|
for _, img := range repoData.ImgList {
|
|
for _, img := range repoData.ImgList {
|
|
if askedTag != "" && img.Tag != askedTag {
|
|
if askedTag != "" && img.Tag != askedTag {
|
|
- utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.Id)
|
|
|
|
|
|
+ utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.ID)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- fmt.Fprintf(out, utils.FormatStatus("Pulling image %s (%s) from %s", json), img.Id, img.Tag, remote)
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("Pulling image %s (%s) from %s", img.ID, img.Tag, remote))
|
|
success := false
|
|
success := false
|
|
for _, ep := range repoData.Endpoints {
|
|
for _, ep := range repoData.Endpoints {
|
|
- if err := srv.pullImage(r, out, img.Id, "https://"+ep+"/v1", repoData.Tokens, json); err != nil {
|
|
|
|
- fmt.Fprintf(out, utils.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint\n", json), askedTag, err)
|
|
|
|
|
|
+ if err := srv.pullImage(r, out, img.ID, "https://"+ep+"/v1", repoData.Tokens, sf); err != nil {
|
|
|
|
+ out.Write(sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint", askedTag, err))
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
success = true
|
|
success = true
|
|
@@ -400,17 +403,17 @@ func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, remote, a
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) ImagePull(name, tag, endpoint string, out io.Writer, json bool) error {
|
|
|
|
|
|
+func (srv *Server) ImagePull(name, tag, endpoint string, out io.Writer, sf *utils.StreamFormatter) error {
|
|
r := registry.NewRegistry(srv.runtime.root)
|
|
r := registry.NewRegistry(srv.runtime.root)
|
|
out = utils.NewWriteFlusher(out)
|
|
out = utils.NewWriteFlusher(out)
|
|
if endpoint != "" {
|
|
if endpoint != "" {
|
|
- if err := srv.pullImage(r, out, name, endpoint, nil, json); err != nil {
|
|
|
|
|
|
+ if err := srv.pullImage(r, out, name, endpoint, nil, sf); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
- if err := srv.pullRepository(r, out, name, tag, json); err != nil {
|
|
|
|
|
|
+ if err := srv.pullRepository(r, out, name, tag, sf); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -464,16 +467,16 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
img.WalkHistory(func(img *Image) error {
|
|
img.WalkHistory(func(img *Image) error {
|
|
- if _, exists := imageSet[img.Id]; exists {
|
|
|
|
|
|
+ if _, exists := imageSet[img.ID]; exists {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
- imageSet[img.Id] = struct{}{}
|
|
|
|
- checksum, err := srv.getChecksum(img.Id)
|
|
|
|
|
|
+ imageSet[img.ID] = struct{}{}
|
|
|
|
+ checksum, err := srv.getChecksum(img.ID)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
imgList = append([]*registry.ImgData{{
|
|
imgList = append([]*registry.ImgData{{
|
|
- Id: img.Id,
|
|
|
|
|
|
+ ID: img.ID,
|
|
Checksum: checksum,
|
|
Checksum: checksum,
|
|
Tag: tag,
|
|
Tag: tag,
|
|
}}, imgList...)
|
|
}}, imgList...)
|
|
@@ -483,52 +486,52 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat
|
|
return imgList, nil
|
|
return imgList, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, name string, localRepo map[string]string) error {
|
|
|
|
|
|
+func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, name string, localRepo map[string]string, sf *utils.StreamFormatter) error {
|
|
out = utils.NewWriteFlusher(out)
|
|
out = utils.NewWriteFlusher(out)
|
|
- fmt.Fprintf(out, "Processing checksums\n")
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("Processing checksums"))
|
|
imgList, err := srv.getImageList(localRepo)
|
|
imgList, err := srv.getImageList(localRepo)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- fmt.Fprintf(out, "Sending images list\n")
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("Sending image list"))
|
|
|
|
|
|
- repoData, err := r.PushImageJsonIndex(name, imgList, false)
|
|
|
|
|
|
+ repoData, err := r.PushImageJSONIndex(name, imgList, false)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
for _, ep := range repoData.Endpoints {
|
|
for _, ep := range repoData.Endpoints {
|
|
- fmt.Fprintf(out, "Pushing repository %s to %s (%d tags)\r\n", name, ep, len(localRepo))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("Pushing repository %s to %s (%d tags)", name, ep, len(localRepo)))
|
|
// For each image within the repo, push them
|
|
// For each image within the repo, push them
|
|
for _, elem := range imgList {
|
|
for _, elem := range imgList {
|
|
- if _, exists := repoData.ImgList[elem.Id]; exists {
|
|
|
|
- fmt.Fprintf(out, "Image %s already on registry, skipping\n", name)
|
|
|
|
|
|
+ if _, exists := repoData.ImgList[elem.ID]; exists {
|
|
|
|
+ out.Write(sf.FormatStatus("Image %s already on registry, skipping", name))
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- if err := srv.pushImage(r, out, name, elem.Id, ep, repoData.Tokens); err != nil {
|
|
|
|
|
|
+ if err := srv.pushImage(r, out, name, elem.ID, ep, repoData.Tokens, sf); err != nil {
|
|
// FIXME: Continue on error?
|
|
// FIXME: Continue on error?
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- fmt.Fprintf(out, "Pushing tags for rev [%s] on {%s}\n", elem.Id, ep+"/users/"+name+"/"+elem.Tag)
|
|
|
|
- if err := r.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil {
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("Pushing tags for rev [%s] on {%s}", elem.ID, ep+"/users/"+name+"/"+elem.Tag))
|
|
|
|
+ if err := r.PushRegistryTag(name, elem.ID, elem.Tag, ep, repoData.Tokens); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if _, err := r.PushImageJsonIndex(name, imgList, true); err != nil {
|
|
|
|
|
|
+ if _, err := r.PushImageJSONIndex(name, imgList, true); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgId, ep string, token []string) error {
|
|
|
|
|
|
+func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgId, ep string, token []string, sf *utils.StreamFormatter) error {
|
|
out = utils.NewWriteFlusher(out)
|
|
out = utils.NewWriteFlusher(out)
|
|
jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgId, "json"))
|
|
jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgId, "json"))
|
|
if err != nil {
|
|
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)
|
|
}
|
|
}
|
|
- fmt.Fprintf(out, "Pushing %s\r\n", imgId)
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("Pushing %s", imgId))
|
|
|
|
|
|
// Make sure we have the image's checksum
|
|
// Make sure we have the image's checksum
|
|
checksum, err := srv.getChecksum(imgId)
|
|
checksum, err := srv.getChecksum(imgId)
|
|
@@ -536,14 +539,14 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgId,
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
imgData := ®istry.ImgData{
|
|
imgData := ®istry.ImgData{
|
|
- Id: imgId,
|
|
|
|
|
|
+ ID: imgId,
|
|
Checksum: checksum,
|
|
Checksum: checksum,
|
|
}
|
|
}
|
|
|
|
|
|
// Send the json
|
|
// Send the json
|
|
- if err := r.PushImageJsonRegistry(imgData, jsonRaw, ep, token); err != nil {
|
|
|
|
|
|
+ if err := r.PushImageJSONRegistry(imgData, jsonRaw, ep, token); err != nil {
|
|
if err == registry.ErrAlreadyExists {
|
|
if err == registry.ErrAlreadyExists {
|
|
- fmt.Fprintf(out, "Image %s already uploaded ; skipping\n", imgData.Id)
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("Image %s already uploaded ; skipping", imgData.ID))
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
return err
|
|
return err
|
|
@@ -576,22 +579,22 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgId,
|
|
}
|
|
}
|
|
|
|
|
|
// Send the layer
|
|
// Send the layer
|
|
- if err := r.PushImageLayerRegistry(imgData.Id, utils.ProgressReader(layerData, int(layerData.Size), out, "", false), ep, token); err != nil {
|
|
|
|
|
|
+ if err := r.PushImageLayerRegistry(imgData.ID, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("Pushing", "%v/%v (%v)"), sf), ep, token); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) ImagePush(name, endpoint string, out io.Writer) error {
|
|
|
|
|
|
+func (srv *Server) ImagePush(name, endpoint string, out io.Writer, sf *utils.StreamFormatter) error {
|
|
out = utils.NewWriteFlusher(out)
|
|
out = utils.NewWriteFlusher(out)
|
|
img, err := srv.runtime.graph.Get(name)
|
|
img, err := srv.runtime.graph.Get(name)
|
|
r := registry.NewRegistry(srv.runtime.root)
|
|
r := registry.NewRegistry(srv.runtime.root)
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Fprintf(out, "The push refers to a repository [%s] (len: %d)\n", name, len(srv.runtime.repositories.Repositories[name]))
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("The push refers to a repository [%s] (len: %d)", name, len(srv.runtime.repositories.Repositories[name])))
|
|
// If it fails, try to get the repository
|
|
// If it fails, try to get the repository
|
|
if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists {
|
|
if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists {
|
|
- if err := srv.pushRepository(r, out, name, localRepo); err != nil {
|
|
|
|
|
|
+ if err := srv.pushRepository(r, out, name, localRepo, sf); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
@@ -599,14 +602,14 @@ func (srv *Server) ImagePush(name, endpoint string, out io.Writer) error {
|
|
|
|
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- fmt.Fprintf(out, "The push refers to an image: [%s]\n", name)
|
|
|
|
- if err := srv.pushImage(r, out, name, img.Id, endpoint, nil); err != nil {
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("The push refers to an image: [%s]", name))
|
|
|
|
+ if err := srv.pushImage(r, out, name, img.ID, endpoint, nil, sf); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Writer) error {
|
|
|
|
|
|
+func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Writer, sf *utils.StreamFormatter) error {
|
|
var archive io.Reader
|
|
var archive io.Reader
|
|
var resp *http.Response
|
|
var resp *http.Response
|
|
|
|
|
|
@@ -615,21 +618,21 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write
|
|
} else {
|
|
} else {
|
|
u, err := url.Parse(src)
|
|
u, err := url.Parse(src)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Fprintf(out, "Error: %s\n", err)
|
|
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
if u.Scheme == "" {
|
|
if u.Scheme == "" {
|
|
u.Scheme = "http"
|
|
u.Scheme = "http"
|
|
u.Host = src
|
|
u.Host = src
|
|
u.Path = ""
|
|
u.Path = ""
|
|
}
|
|
}
|
|
- fmt.Fprintf(out, "Downloading from %s\n", u)
|
|
|
|
|
|
+ out.Write(sf.FormatStatus("Downloading from %s", u))
|
|
// Download with curl (pretty progress bar)
|
|
// Download with curl (pretty progress bar)
|
|
// If curl is not available, fallback to http.Get()
|
|
// If curl is not available, fallback to http.Get()
|
|
resp, err = utils.Download(u.String(), out)
|
|
resp, err = utils.Download(u.String(), out)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- archive = utils.ProgressReader(resp.Body, int(resp.ContentLength), out, "Importing %v/%v (%v)\r", false)
|
|
|
|
|
|
+ archive = utils.ProgressReader(resp.Body, int(resp.ContentLength), out, sf.FormatProgress("Importing", "%v/%v (%v)"), sf)
|
|
}
|
|
}
|
|
img, err := srv.runtime.graph.Create(archive, nil, "Imported from "+src, "", nil)
|
|
img, err := srv.runtime.graph.Create(archive, nil, "Imported from "+src, "", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -637,11 +640,11 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write
|
|
}
|
|
}
|
|
// Optionally register the image at REPO/TAG
|
|
// Optionally register the image at REPO/TAG
|
|
if repo != "" {
|
|
if repo != "" {
|
|
- if err := srv.runtime.repositories.Set(repo, tag, img.Id, true); err != nil {
|
|
|
|
|
|
+ if err := srv.runtime.repositories.Set(repo, tag, img.ID, true); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- fmt.Fprintf(out, "%s\n", img.ShortId())
|
|
|
|
|
|
+ out.Write(sf.FormatStatus(img.ShortID()))
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -662,7 +665,7 @@ func (srv *Server) ContainerCreate(config *Config) (string, error) {
|
|
}
|
|
}
|
|
return "", err
|
|
return "", err
|
|
}
|
|
}
|
|
- return container.ShortId(), nil
|
|
|
|
|
|
+ return container.ShortID(), nil
|
|
}
|
|
}
|
|
|
|
|
|
func (srv *Server) ContainerRestart(name string, t int) error {
|
|
func (srv *Server) ContainerRestart(name string, t int) error {
|
|
@@ -699,7 +702,7 @@ func (srv *Server) ContainerDestroy(name string, removeVolume bool) error {
|
|
for volumeId := range volumes {
|
|
for volumeId := range volumes {
|
|
// If the requested volu
|
|
// If the requested volu
|
|
if c, exists := usedVolumes[volumeId]; exists {
|
|
if c, exists := usedVolumes[volumeId]; exists {
|
|
- log.Printf("The volume %s is used by the container %s. Impossible to remove it. Skipping.\n", volumeId, c.Id)
|
|
|
|
|
|
+ log.Printf("The volume %s is used by the container %s. Impossible to remove it. Skipping.\n", volumeId, c.ID)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
if err := srv.runtime.volumes.Delete(volumeId); err != nil {
|
|
if err := srv.runtime.volumes.Delete(volumeId); err != nil {
|
|
@@ -717,10 +720,9 @@ func (srv *Server) ImageDelete(name string) error {
|
|
img, err := srv.runtime.repositories.LookupImage(name)
|
|
img, err := srv.runtime.repositories.LookupImage(name)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("No such image: %s", name)
|
|
return fmt.Errorf("No such image: %s", name)
|
|
- } else {
|
|
|
|
- if err := srv.runtime.graph.Delete(img.Id); err != nil {
|
|
|
|
- return fmt.Errorf("Error deleting image %s: %s", name, err.Error())
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ if err := srv.runtime.graph.Delete(img.ID); err != nil {
|
|
|
|
+ return fmt.Errorf("Error deleting image %s: %s", name, err.Error())
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -739,7 +741,7 @@ func (srv *Server) ImageGetCached(imgId string, config *Config) (*Image, error)
|
|
if _, exists := imageMap[img.Parent]; !exists {
|
|
if _, exists := imageMap[img.Parent]; !exists {
|
|
imageMap[img.Parent] = make(map[string]struct{})
|
|
imageMap[img.Parent] = make(map[string]struct{})
|
|
}
|
|
}
|
|
- imageMap[img.Parent][img.Id] = struct{}{}
|
|
|
|
|
|
+ imageMap[img.Parent][img.ID] = struct{}{}
|
|
}
|
|
}
|
|
|
|
|
|
// Loop on the children of the given image and check the config
|
|
// Loop on the children of the given image and check the config
|
|
@@ -796,7 +798,6 @@ func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, std
|
|
if container == nil {
|
|
if container == nil {
|
|
return fmt.Errorf("No such container: %s", name)
|
|
return fmt.Errorf("No such container: %s", name)
|
|
}
|
|
}
|
|
-
|
|
|
|
//logs
|
|
//logs
|
|
if logs {
|
|
if logs {
|
|
if stdout {
|
|
if stdout {
|
|
@@ -822,6 +823,9 @@ func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, std
|
|
if container.State.Ghost {
|
|
if container.State.Ghost {
|
|
return fmt.Errorf("Impossible to attach to a ghost container")
|
|
return fmt.Errorf("Impossible to attach to a ghost container")
|
|
}
|
|
}
|
|
|
|
+ if !container.State.Running {
|
|
|
|
+ return fmt.Errorf("Impossible to attach to a stopped container, start it first")
|
|
|
|
+ }
|
|
|
|
|
|
var (
|
|
var (
|
|
cStdin io.ReadCloser
|
|
cStdin io.ReadCloser
|