mirror of https://github.com/docker/docs.git
Merge branch 'graph' of github.com:dotcloud/docker into graph
This commit is contained in:
commit
04ba4348de
|
@ -623,7 +623,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Display images which aren't part of a
|
// Display images which aren't part of a
|
||||||
if nameFilter != "" {
|
if nameFilter == "" {
|
||||||
for id, image := range allImages {
|
for id, image := range allImages {
|
||||||
if !*quiet {
|
if !*quiet {
|
||||||
for idx, field := range []string{
|
for idx, field := range []string{
|
||||||
|
@ -639,6 +639,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
w.Write([]byte("\t" + field))
|
w.Write([]byte("\t" + field))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
w.Write([]byte{'\n'})
|
||||||
} else {
|
} else {
|
||||||
stdout.Write([]byte(image.Id + "\n"))
|
stdout.Write([]byte(image.Id + "\n"))
|
||||||
}
|
}
|
||||||
|
|
1
graph.go
1
graph.go
|
@ -35,6 +35,7 @@ func (graph *Graph) Exists(id string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (graph *Graph) Get(id string) (*Image, error) {
|
func (graph *Graph) Get(id string) (*Image, error) {
|
||||||
|
// FIXME: return nil when the image doesn't exist, instead of an error
|
||||||
img, err := LoadImage(graph.imageRoot(id))
|
img, err := LoadImage(graph.imageRoot(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
39
runtime.go
39
runtime.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -62,15 +63,41 @@ func (runtime *Runtime) containerRoot(id string) string {
|
||||||
return path.Join(runtime.repository, id)
|
return path.Join(runtime.repository, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (runtime *Runtime) LookupImage(name string) (*Image, error) {
|
||||||
|
img, err := runtime.graph.Get(name)
|
||||||
|
if err != nil {
|
||||||
|
// FIXME: standardize on returning nil when the image doesn't exist, and err for everything else
|
||||||
|
// (so we can pass all errors here)
|
||||||
|
repoAndTag := strings.SplitN(name, ":", 2)
|
||||||
|
if len(repoAndTag) == 1 {
|
||||||
|
repoAndTag = append(repoAndTag, "")
|
||||||
|
}
|
||||||
|
if i, err := runtime.repositories.GetImage(repoAndTag[0], repoAndTag[1]); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if i == nil {
|
||||||
|
return nil, fmt.Errorf("No such image: %s", name)
|
||||||
|
} else {
|
||||||
|
img = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return img, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (runtime *Runtime) Create(command string, args []string, image string, config *Config) (*Container, error) {
|
func (runtime *Runtime) Create(command string, args []string, image string, config *Config) (*Container, error) {
|
||||||
|
// Lookup image
|
||||||
|
img, err := runtime.LookupImage(image)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
container := &Container{
|
container := &Container{
|
||||||
// FIXME: we should generate the ID here instead of receiving it as an argument
|
// FIXME: we should generate the ID here instead of receiving it as an argument
|
||||||
Id: GenerateId(),
|
Id: GenerateId(),
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
Path: command,
|
Path: command,
|
||||||
Args: args,
|
Args: args,
|
||||||
Config: config,
|
Config: config,
|
||||||
Image: image,
|
Image: img.Id, // Always use the resolved image id
|
||||||
|
//FIXME: store the name under which the image was given, for reference
|
||||||
NetworkSettings: &NetworkSettings{},
|
NetworkSettings: &NetworkSettings{},
|
||||||
// FIXME: do we need to store this in the container?
|
// FIXME: do we need to store this in the container?
|
||||||
SysInitPath: sysInitPath,
|
SysInitPath: sysInitPath,
|
||||||
|
|
8
tags.go
8
tags.go
|
@ -3,6 +3,7 @@ package docker
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +25,12 @@ func NewTagStore(path string, graph *Graph) (*TagStore, error) {
|
||||||
graph: graph,
|
graph: graph,
|
||||||
Repositories: make(map[string]Repository),
|
Repositories: make(map[string]Repository),
|
||||||
}
|
}
|
||||||
if err := store.Save(); err != nil {
|
// Load the json file if it exists, otherwise create it.
|
||||||
|
if err := store.Reload(); os.IsNotExist(err) {
|
||||||
|
if err := store.Save(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return store, nil
|
return store, nil
|
||||||
|
|
Loading…
Reference in New Issue