From 6c091462edad59ee8ddd108eec45d6dbee62326a Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 3 Oct 2013 11:35:14 -0700 Subject: [PATCH] Update based on initial feedback Hard code root entity name Remove test from Dockerfile Name sure container names work across commands --- Dockerfile | 2 +- api.go | 2 ++ commands.go | 18 +++++++++++------- gograph/gograph.go | 11 +++++------ gograph/gograph_test.go | 2 +- links.go | 2 +- runtime.go | 3 ++- runtime_test.go | 2 +- 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 55fdc17ec..1c1f6e36d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,7 +40,7 @@ run curl -s https://go.googlecode.com/files/go1.2rc1.src.tar.gz | tar -v -C /usr env PATH /usr/local/go/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin env GOPATH /go:/go/src/github.com/dotcloud/docker/vendor run cd /usr/local/go/src && ./make.bash && go install -ldflags '-w -linkmode external -extldflags "-static -Wl,--unresolved-symbols=ignore-in-shared-libs"' -tags netgo -a std -run cd /tmp && echo 'package main' > t.go && go test -a -i -v + # Ubuntu stuff run apt-get install -y -q ruby1.9.3 rubygems libffi-dev run gem install --no-rdoc --no-ri fpm diff --git a/api.go b/api.go index 4ee1ddc81..e69e3c75a 100644 --- a/api.go +++ b/api.go @@ -806,6 +806,7 @@ func wsContainersAttach(srv *Server, version float64, w http.ResponseWriter, r * return fmt.Errorf("Missing parameter") } name := vars["name"] + name = decodeName(name) if _, err := srv.ContainerInspect(name); err != nil { return err @@ -828,6 +829,7 @@ func getContainersByName(srv *Server, version float64, w http.ResponseWriter, r return fmt.Errorf("Missing parameter") } name := vars["name"] + name = decodeName(name) container, err := srv.ContainerInspect(name) if err != nil { diff --git a/commands.go b/commands.go index 28985b107..e7563000e 100644 --- a/commands.go +++ b/commands.go @@ -537,8 +537,8 @@ func (cli *DockerCli) CmdRestart(args ...string) error { v.Set("t", strconv.Itoa(*nSeconds)) for _, name := range cmd.Args() { - name = cleanName(name) - _, _, err := cli.call("POST", "/containers/"+name+"/restart?"+v.Encode(), nil) + encName := cleanName(name) + _, _, err := cli.call("POST", "/containers/"+encName+"/restart?"+v.Encode(), nil) if err != nil { fmt.Fprintf(cli.err, "%s\n", err) } else { @@ -583,11 +583,11 @@ func (cli *DockerCli) CmdInspect(args ...string) error { } fmt.Fprintf(cli.out, "[") for i, name := range args { - name = cleanName(name) + encName := cleanName(name) if i > 0 { fmt.Fprintf(cli.out, ",") } - obj, _, err := cli.call("GET", "/containers/"+name+"/json", nil) + obj, _, err := cli.call("GET", "/containers/"+encName+"/json", nil) if err != nil { obj, _, err = cli.call("GET", "/images/"+name+"/json", nil) if err != nil { @@ -785,8 +785,8 @@ func (cli *DockerCli) CmdKill(args ...string) error { } for _, name := range args { - name = cleanName(name) - _, _, err := cli.call("POST", "/containers/"+name+"/kill", nil) + encName := cleanName(name) + _, _, err := cli.call("POST", "/containers/"+encName+"/kill", nil) if err != nil { fmt.Fprintf(cli.err, "%s\n", err) } else { @@ -1094,6 +1094,10 @@ func (cli *DockerCli) CmdPs(args ...string) error { } for _, out := range outs { + for i := 0; i < len(out.Names); i++ { + out.Names[i] = utils.Trunc(out.Names[i], 10) + } + names := strings.Join(out.Names, ",") if !*quiet { if *noTrunc { @@ -1148,7 +1152,7 @@ func (cli *DockerCli) CmdLs(args ...string) error { return len(i.Path) < len(j.Path) }) for _, link := range links { - fmt.Fprintf(w, "%s\t%s\t%s", link.Path, link.ContainerID, link.Image) + fmt.Fprintf(w, "%s\t%s\t%s", link.Path, utils.TruncateID(link.ContainerID), link.Image) fmt.Fprintf(w, "\n") } w.Flush() diff --git a/gograph/gograph.go b/gograph/gograph.go index 8dacb961f..876bd6b58 100644 --- a/gograph/gograph.go +++ b/gograph/gograph.go @@ -47,12 +47,11 @@ type WalkFunc func(fullPath string, entity *Entity) error // Graph database for storing entities and their relationships type Database struct { dbPath string - rootID string } // Create a new graph database initialized with a root entity -func NewDatabase(dbPath, rootId string) (*Database, error) { - db := &Database{dbPath, rootId} +func NewDatabase(dbPath string) (*Database, error) { + db := &Database{dbPath} if _, err := os.Stat(dbPath); err == nil { return db, nil } @@ -77,12 +76,12 @@ func NewDatabase(dbPath, rootId string) (*Database, error) { if _, err := conn.Exec("BEGIN"); err != nil { return nil, err } - if _, err := conn.Exec("INSERT INTO entity (id) VALUES (?);", rootId); err != nil { + if _, err := conn.Exec("INSERT INTO entity (id) VALUES (?);", "0"); err != nil { rollback() return nil, err } - if _, err := conn.Exec("INSERT INTO edge (entity_id, name) VALUES(?,?);", rootId, "/"); err != nil { + if _, err := conn.Exec("INSERT INTO edge (entity_id, name) VALUES(?,?);", "0", "/"); err != nil { rollback() return nil, err } @@ -150,7 +149,7 @@ func (db *Database) setEdge(conn *sql.DB, parentPath, name string, e *Entity) er // Return the root "/" entity for the database func (db *Database) RootEntity() *Entity { return &Entity{ - id: db.rootID, + id: "0", } } diff --git a/gograph/gograph_test.go b/gograph/gograph_test.go index 3b7515897..519b19969 100644 --- a/gograph/gograph_test.go +++ b/gograph/gograph_test.go @@ -8,7 +8,7 @@ import ( ) func newTestDb(t *testing.T) *Database { - db, err := NewDatabase(path.Join(os.TempDir(), "sqlite.db"), "0") + db, err := NewDatabase(path.Join(os.TempDir(), "sqlite.db")) if err != nil { t.Fatal(err) } diff --git a/links.go b/links.go index bcd6fe6a1..f1087ec34 100644 --- a/links.go +++ b/links.go @@ -108,7 +108,7 @@ func (l *Link) Enable() error { } func (l *Link) Disable() { - // We do not care about erros here because the link may not + // We do not care about errors here because the link may not // exist in iptables l.toggle("-D", true) diff --git a/runtime.go b/runtime.go index 11ce1f382..fbc0a8f72 100644 --- a/runtime.go +++ b/runtime.go @@ -577,7 +577,8 @@ func NewRuntimeFromDirectory(config *DaemonConfig) (*Runtime, error) { if err != nil { return nil, err } - graph, err := gograph.NewDatabase(path.Join(config.GraphPath, "linkgraph.db"), "engine") + + graph, err := gograph.NewDatabase(path.Join(config.GraphPath, "linkgraph.db")) if err != nil { return nil, err } diff --git a/runtime_test.go b/runtime_test.go index 87fd4a9fe..43694a5f4 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -597,7 +597,7 @@ func TestDefaultContainerName(t *testing.T) { t.Fatalf("Could not find edges for %s", containerID) } edge := paths[0] - if edge.ParentID != "engine" { + if edge.ParentID != "0" { t.Fatalf("Expected engine got %s", edge.ParentID) } if edge.EntityID != containerID {