mirror of https://github.com/docker/docs.git
Folded graph/ back into main package
This commit is contained in:
parent
44faa07b6c
commit
ef711962d5
|
@ -1,4 +1,4 @@
|
||||||
package graph
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -1,4 +1,4 @@
|
||||||
package graph
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
|
@ -1,4 +1,4 @@
|
||||||
package graph
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -803,7 +803,7 @@ func NewServer() (*Server, error) {
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
// }
|
// }
|
||||||
runtime, err := New()
|
runtime, err := NewRuntime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
22
container.go
22
container.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/graph"
|
|
||||||
"github.com/kr/pty"
|
"github.com/kr/pty"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -63,11 +62,6 @@ type NetworkSettings struct {
|
||||||
PortMapping map[string]string
|
PortMapping map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateId() string {
|
|
||||||
return graph.GenerateId() // Re-use the same code to generate container and image IDs
|
|
||||||
// (this might change when image Ids become content-based)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (container *Container) Cmd() *exec.Cmd {
|
func (container *Container) Cmd() *exec.Cmd {
|
||||||
return container.cmd
|
return container.cmd
|
||||||
}
|
}
|
||||||
|
@ -376,15 +370,15 @@ func (container *Container) Wait() int {
|
||||||
return container.State.ExitCode
|
return container.State.ExitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) ExportRw() (graph.Archive, error) {
|
func (container *Container) ExportRw() (Archive, error) {
|
||||||
return graph.Tar(container.rwPath(), graph.Uncompressed)
|
return Tar(container.rwPath(), Uncompressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) Export() (graph.Archive, error) {
|
func (container *Container) Export() (Archive, error) {
|
||||||
if err := container.EnsureMounted(); err != nil {
|
if err := container.EnsureMounted(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return graph.Tar(container.RootfsPath(), graph.Uncompressed)
|
return Tar(container.RootfsPath(), Uncompressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) WaitTimeout(timeout time.Duration) error {
|
func (container *Container) WaitTimeout(timeout time.Duration) error {
|
||||||
|
@ -420,7 +414,7 @@ func (container *Container) Mount() error {
|
||||||
return image.Mount(container.RootfsPath(), container.rwPath())
|
return image.Mount(container.RootfsPath(), container.rwPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) Changes() ([]graph.Change, error) {
|
func (container *Container) Changes() ([]Change, error) {
|
||||||
image, err := container.GetImage()
|
image, err := container.GetImage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -428,7 +422,7 @@ func (container *Container) Changes() ([]graph.Change, error) {
|
||||||
return image.Changes(container.rwPath())
|
return image.Changes(container.rwPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) GetImage() (*graph.Image, error) {
|
func (container *Container) GetImage() (*Image, error) {
|
||||||
if container.runtime == nil {
|
if container.runtime == nil {
|
||||||
return nil, fmt.Errorf("Can't get image of unregistered container")
|
return nil, fmt.Errorf("Can't get image of unregistered container")
|
||||||
}
|
}
|
||||||
|
@ -436,11 +430,11 @@ func (container *Container) GetImage() (*graph.Image, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) Mounted() (bool, error) {
|
func (container *Container) Mounted() (bool, error) {
|
||||||
return graph.Mounted(container.RootfsPath())
|
return Mounted(container.RootfsPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) Unmount() error {
|
func (container *Container) Unmount() error {
|
||||||
return graph.Unmount(container.RootfsPath())
|
return Unmount(container.RootfsPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) logPath(name string) string {
|
func (container *Container) logPath(name string) string {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package graph
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -13,7 +13,7 @@ type Graph struct {
|
||||||
Root string
|
Root string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(root string) (*Graph, error) {
|
func NewGraph(root string) (*Graph, error) {
|
||||||
abspath, err := filepath.Abs(root)
|
abspath, err := filepath.Abs(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -84,7 +84,7 @@ func (graph *Graph) Register(layerData Archive, img *Image) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (graph *Graph) Mktemp(id string) (string, error) {
|
func (graph *Graph) Mktemp(id string) (string, error) {
|
||||||
tmp, err := New(path.Join(graph.Root, ":tmp:"))
|
tmp, err := NewGraph(path.Join(graph.Root, ":tmp:"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Couldn't create temp: %s", err)
|
return "", fmt.Errorf("Couldn't create temp: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ func (graph *Graph) Mktemp(id string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (graph *Graph) Garbage() (*Graph, error) {
|
func (graph *Graph) Garbage() (*Graph, error) {
|
||||||
return New(path.Join(graph.Root, ":garbage:"))
|
return NewGraph(path.Join(graph.Root, ":garbage:"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (graph *Graph) Delete(id string) error {
|
func (graph *Graph) Delete(id string) error {
|
|
@ -1,4 +1,4 @@
|
||||||
package graph
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
|
@ -28,7 +28,7 @@ func TestInit(t *testing.T) {
|
||||||
|
|
||||||
// FIXME: Do more extensive tests (ex: create multiple, delete, recreate;
|
// FIXME: Do more extensive tests (ex: create multiple, delete, recreate;
|
||||||
// create multiple, check the amount of images and paths, etc..)
|
// create multiple, check the amount of images and paths, etc..)
|
||||||
func TestCreate(t *testing.T) {
|
func TestGraphCreate(t *testing.T) {
|
||||||
graph := tempGraph(t)
|
graph := tempGraph(t)
|
||||||
defer os.RemoveAll(graph.Root)
|
defer os.RemoveAll(graph.Root)
|
||||||
archive, err := fakeTar()
|
archive, err := fakeTar()
|
||||||
|
@ -177,7 +177,7 @@ func tempGraph(t *testing.T) *Graph {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
graph, err := New(tmp)
|
graph, err := NewGraph(tmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package graph
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package graph
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package graph
|
package docker
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package graph
|
package docker
|
||||||
|
|
||||||
import "syscall"
|
import "syscall"
|
||||||
|
|
15
runtime.go
15
runtime.go
|
@ -3,7 +3,6 @@ package docker
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/graph"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -19,8 +18,8 @@ type Runtime struct {
|
||||||
repository string
|
repository string
|
||||||
containers *list.List
|
containers *list.List
|
||||||
networkManager *NetworkManager
|
networkManager *NetworkManager
|
||||||
graph *graph.Graph
|
graph *Graph
|
||||||
repositories *graph.TagStore
|
repositories *TagStore
|
||||||
}
|
}
|
||||||
|
|
||||||
var sysInitPath string
|
var sysInitPath string
|
||||||
|
@ -191,22 +190,22 @@ func (runtime *Runtime) restore() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() (*Runtime, error) {
|
func NewRuntime() (*Runtime, error) {
|
||||||
return NewFromDirectory("/var/lib/docker")
|
return NewRuntimeFromDirectory("/var/lib/docker")
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFromDirectory(root string) (*Runtime, error) {
|
func NewRuntimeFromDirectory(root string) (*Runtime, error) {
|
||||||
runtime_repo := path.Join(root, "containers")
|
runtime_repo := path.Join(root, "containers")
|
||||||
|
|
||||||
if err := os.MkdirAll(runtime_repo, 0700); err != nil && !os.IsExist(err) {
|
if err := os.MkdirAll(runtime_repo, 0700); err != nil && !os.IsExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
g, err := graph.New(path.Join(root, "graph"))
|
g, err := NewGraph(path.Join(root, "graph"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
repositories, err := graph.NewTagStore(path.Join(root, "repositories"), g)
|
repositories, err := NewTagStore(path.Join(root, "repositories"), g)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Couldn't create Tag store: %s", err)
|
return nil, fmt.Errorf("Couldn't create Tag store: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker/graph"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -57,7 +56,7 @@ func init() {
|
||||||
unitTestStoreBase = root
|
unitTestStoreBase = root
|
||||||
|
|
||||||
// Make it our Store root
|
// Make it our Store root
|
||||||
runtime, err := NewFromDirectory(root)
|
runtime, err := NewRuntimeFromDirectory(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -84,7 +83,7 @@ func newTestRuntime() (*Runtime, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime, err := NewFromDirectory(root)
|
runtime, err := NewRuntimeFromDirectory(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -92,7 +91,7 @@ func newTestRuntime() (*Runtime, error) {
|
||||||
return runtime, nil
|
return runtime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTestImage(runtime *Runtime) *graph.Image {
|
func GetTestImage(runtime *Runtime) *Image {
|
||||||
imgs, err := runtime.graph.All()
|
imgs, err := runtime.graph.All()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -102,7 +101,7 @@ func GetTestImage(runtime *Runtime) *graph.Image {
|
||||||
return imgs[0]
|
return imgs[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestRuntimeCreate(t *testing.T) {
|
||||||
runtime, err := newTestRuntime()
|
runtime, err := newTestRuntime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -269,7 +268,7 @@ func TestRestore(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime1, err := NewFromDirectory(root)
|
runtime1, err := NewRuntimeFromDirectory(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -294,7 +293,7 @@ func TestRestore(t *testing.T) {
|
||||||
|
|
||||||
// Here are are simulating a docker restart - that is, reloading all containers
|
// Here are are simulating a docker restart - that is, reloading all containers
|
||||||
// from scratch
|
// from scratch
|
||||||
runtime2, err := NewFromDirectory(root)
|
runtime2, err := NewRuntimeFromDirectory(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package graph
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
Loading…
Reference in New Issue