|
@@ -5,11 +5,15 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/dotcloud/docker/archive"
|
|
|
"github.com/dotcloud/docker/auth"
|
|
|
+ "github.com/dotcloud/docker/daemonconfig"
|
|
|
"github.com/dotcloud/docker/dockerversion"
|
|
|
"github.com/dotcloud/docker/engine"
|
|
|
+ "github.com/dotcloud/docker/graph"
|
|
|
+ "github.com/dotcloud/docker/image"
|
|
|
"github.com/dotcloud/docker/pkg/graphdb"
|
|
|
"github.com/dotcloud/docker/registry"
|
|
|
"github.com/dotcloud/docker/runconfig"
|
|
|
+ "github.com/dotcloud/docker/runtime"
|
|
|
"github.com/dotcloud/docker/utils"
|
|
|
"io"
|
|
|
"io/ioutil"
|
|
@@ -21,7 +25,7 @@ import (
|
|
|
"os/signal"
|
|
|
"path"
|
|
|
"path/filepath"
|
|
|
- "runtime"
|
|
|
+ goruntime "runtime"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
@@ -34,13 +38,13 @@ import (
|
|
|
// The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup.
|
|
|
func InitServer(job *engine.Job) engine.Status {
|
|
|
job.Logf("Creating server")
|
|
|
- srv, err := NewServer(job.Eng, DaemonConfigFromJob(job))
|
|
|
+ srv, err := NewServer(job.Eng, daemonconfig.ConfigFromJob(job))
|
|
|
if err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
- if srv.runtime.config.Pidfile != "" {
|
|
|
+ if srv.runtime.Config().Pidfile != "" {
|
|
|
job.Logf("Creating pidfile")
|
|
|
- if err := utils.CreatePidFile(srv.runtime.config.Pidfile); err != nil {
|
|
|
+ if err := utils.CreatePidFile(srv.runtime.Config().Pidfile); err != nil {
|
|
|
// FIXME: do we need fatal here instead of returning a job error?
|
|
|
log.Fatal(err)
|
|
|
}
|
|
@@ -51,7 +55,7 @@ func InitServer(job *engine.Job) engine.Status {
|
|
|
go func() {
|
|
|
sig := <-c
|
|
|
log.Printf("Received signal '%v', exiting\n", sig)
|
|
|
- utils.RemovePidFile(srv.runtime.config.Pidfile)
|
|
|
+ utils.RemovePidFile(srv.runtime.Config().Pidfile)
|
|
|
srv.Close()
|
|
|
os.Exit(0)
|
|
|
}()
|
|
@@ -178,10 +182,10 @@ func (srv *Server) ContainerKill(job *engine.Job) engine.Status {
|
|
|
if err := container.Kill(); err != nil {
|
|
|
return job.Errorf("Cannot kill container %s: %s", name, err)
|
|
|
}
|
|
|
- srv.LogEvent("kill", container.ID, srv.runtime.repositories.ImageName(container.Image))
|
|
|
+ srv.LogEvent("kill", container.ID, srv.runtime.Repositories().ImageName(container.Image))
|
|
|
} else {
|
|
|
// Otherwise, just send the requested signal
|
|
|
- if err := container.kill(int(sig)); err != nil {
|
|
|
+ if err := container.KillSig(int(sig)); err != nil {
|
|
|
return job.Errorf("Cannot kill container %s: %s", name, err)
|
|
|
}
|
|
|
// FIXME: Add event for signals
|
|
@@ -290,7 +294,7 @@ func (srv *Server) ContainerExport(job *engine.Job) engine.Status {
|
|
|
return job.Errorf("%s: %s", name, err)
|
|
|
}
|
|
|
// FIXME: factor job-specific LogEvent to engine.Job.Run()
|
|
|
- srv.LogEvent("export", container.ID, srv.runtime.repositories.ImageName(container.Image))
|
|
|
+ srv.LogEvent("export", container.ID, srv.runtime.Repositories().ImageName(container.Image))
|
|
|
return engine.StatusOK
|
|
|
}
|
|
|
return job.Errorf("No such container: %s", name)
|
|
@@ -315,7 +319,7 @@ func (srv *Server) ImageExport(job *engine.Job) engine.Status {
|
|
|
|
|
|
utils.Debugf("Serializing %s", name)
|
|
|
|
|
|
- rootRepo, err := srv.runtime.repositories.Get(name)
|
|
|
+ rootRepo, err := srv.runtime.Repositories().Get(name)
|
|
|
if err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
@@ -332,7 +336,7 @@ func (srv *Server) ImageExport(job *engine.Job) engine.Status {
|
|
|
}
|
|
|
|
|
|
// write repositories
|
|
|
- rootRepoMap := map[string]Repository{}
|
|
|
+ rootRepoMap := map[string]graph.Repository{}
|
|
|
rootRepoMap[name] = rootRepo
|
|
|
rootRepoJson, _ := json.Marshal(rootRepoMap)
|
|
|
|
|
@@ -361,8 +365,8 @@ func (srv *Server) ImageExport(job *engine.Job) engine.Status {
|
|
|
return engine.StatusOK
|
|
|
}
|
|
|
|
|
|
-func (srv *Server) exportImage(image *Image, tempdir string) error {
|
|
|
- for i := image; i != nil; {
|
|
|
+func (srv *Server) exportImage(img *image.Image, tempdir string) error {
|
|
|
+ for i := img; i != nil; {
|
|
|
// temporary directory
|
|
|
tmpImageDir := path.Join(tempdir, i.ID)
|
|
|
if err := os.Mkdir(tmpImageDir, os.ModeDir); err != nil {
|
|
@@ -491,7 +495,7 @@ func (srv *Server) Build(job *engine.Job) engine.Status {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
if repoName != "" {
|
|
|
- srv.runtime.repositories.Set(repoName, tag, id, false)
|
|
|
+ srv.runtime.Repositories().Set(repoName, tag, id, false)
|
|
|
}
|
|
|
return engine.StatusOK
|
|
|
}
|
|
@@ -545,14 +549,14 @@ func (srv *Server) ImageLoad(job *engine.Job) engine.Status {
|
|
|
|
|
|
repositoriesJson, err := ioutil.ReadFile(path.Join(tmpImageDir, "repo", "repositories"))
|
|
|
if err == nil {
|
|
|
- repositories := map[string]Repository{}
|
|
|
+ repositories := map[string]graph.Repository{}
|
|
|
if err := json.Unmarshal(repositoriesJson, &repositories); err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
|
|
|
for imageName, tagMap := range repositories {
|
|
|
for tag, address := range tagMap {
|
|
|
- if err := srv.runtime.repositories.Set(imageName, tag, address, true); err != nil {
|
|
|
+ if err := srv.runtime.Repositories().Set(imageName, tag, address, true); err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
}
|
|
@@ -579,19 +583,19 @@ func (srv *Server) recursiveLoad(address, tmpImageDir string) error {
|
|
|
utils.Debugf("Error reading embedded tar", err)
|
|
|
return err
|
|
|
}
|
|
|
- img, err := NewImgJSON(imageJson)
|
|
|
+ img, err := image.NewImgJSON(imageJson)
|
|
|
if err != nil {
|
|
|
utils.Debugf("Error unmarshalling json", err)
|
|
|
return err
|
|
|
}
|
|
|
if img.Parent != "" {
|
|
|
- if !srv.runtime.graph.Exists(img.Parent) {
|
|
|
+ if !srv.runtime.Graph().Exists(img.Parent) {
|
|
|
if err := srv.recursiveLoad(img.Parent, tmpImageDir); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if err := srv.runtime.graph.Register(imageJson, layer, img); err != nil {
|
|
|
+ if err := srv.runtime.Graph().Register(imageJson, layer, img); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
@@ -647,7 +651,7 @@ func (srv *Server) ImageInsert(job *engine.Job) engine.Status {
|
|
|
sf := utils.NewStreamFormatter(job.GetenvBool("json"))
|
|
|
|
|
|
out := utils.NewWriteFlusher(job.Stdout)
|
|
|
- img, err := srv.runtime.repositories.LookupImage(name)
|
|
|
+ img, err := srv.runtime.Repositories().LookupImage(name)
|
|
|
if err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
@@ -658,7 +662,7 @@ func (srv *Server) ImageInsert(job *engine.Job) engine.Status {
|
|
|
}
|
|
|
defer file.Body.Close()
|
|
|
|
|
|
- config, _, _, err := runconfig.Parse([]string{img.ID, "echo", "insert", url, path}, srv.runtime.sysInfo)
|
|
|
+ config, _, _, err := runconfig.Parse([]string{img.ID, "echo", "insert", url, path}, srv.runtime.SystemConfig())
|
|
|
if err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
@@ -682,14 +686,14 @@ func (srv *Server) ImageInsert(job *engine.Job) engine.Status {
|
|
|
}
|
|
|
|
|
|
func (srv *Server) ImagesViz(job *engine.Job) engine.Status {
|
|
|
- images, _ := srv.runtime.graph.Map()
|
|
|
+ images, _ := srv.runtime.Graph().Map()
|
|
|
if images == nil {
|
|
|
return engine.StatusOK
|
|
|
}
|
|
|
job.Stdout.Write([]byte("digraph docker {\n"))
|
|
|
|
|
|
var (
|
|
|
- parentImage *Image
|
|
|
+ parentImage *image.Image
|
|
|
err error
|
|
|
)
|
|
|
for _, image := range images {
|
|
@@ -706,7 +710,7 @@ func (srv *Server) ImagesViz(job *engine.Job) engine.Status {
|
|
|
|
|
|
reporefs := make(map[string][]string)
|
|
|
|
|
|
- for name, repository := range srv.runtime.repositories.Repositories {
|
|
|
+ for name, repository := range srv.runtime.Repositories().Repositories {
|
|
|
for tag, id := range repository {
|
|
|
reporefs[utils.TruncateID(id)] = append(reporefs[utils.TruncateID(id)], fmt.Sprintf("%s:%s", name, tag))
|
|
|
}
|
|
@@ -721,26 +725,26 @@ func (srv *Server) ImagesViz(job *engine.Job) engine.Status {
|
|
|
|
|
|
func (srv *Server) Images(job *engine.Job) engine.Status {
|
|
|
var (
|
|
|
- allImages map[string]*Image
|
|
|
+ allImages map[string]*image.Image
|
|
|
err error
|
|
|
)
|
|
|
if job.GetenvBool("all") {
|
|
|
- allImages, err = srv.runtime.graph.Map()
|
|
|
+ allImages, err = srv.runtime.Graph().Map()
|
|
|
} else {
|
|
|
- allImages, err = srv.runtime.graph.Heads()
|
|
|
+ allImages, err = srv.runtime.Graph().Heads()
|
|
|
}
|
|
|
if err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
lookup := make(map[string]*engine.Env)
|
|
|
- for name, repository := range srv.runtime.repositories.Repositories {
|
|
|
+ for name, repository := range srv.runtime.Repositories().Repositories {
|
|
|
if job.Getenv("filter") != "" {
|
|
|
if match, _ := path.Match(job.Getenv("filter"), name); !match {
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
for tag, id := range repository {
|
|
|
- image, err := srv.runtime.graph.Get(id)
|
|
|
+ image, err := srv.runtime.Graph().Get(id)
|
|
|
if err != nil {
|
|
|
log.Printf("Warning: couldn't load %s from %s/%s: %s", id, name, tag, err)
|
|
|
continue
|
|
@@ -756,7 +760,7 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
|
|
|
out.Set("Id", image.ID)
|
|
|
out.SetInt64("Created", image.Created.Unix())
|
|
|
out.SetInt64("Size", image.Size)
|
|
|
- out.SetInt64("VirtualSize", image.getParentsSize(0)+image.Size)
|
|
|
+ out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size)
|
|
|
lookup[id] = out
|
|
|
}
|
|
|
|
|
@@ -777,7 +781,7 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
|
|
|
out.Set("Id", image.ID)
|
|
|
out.SetInt64("Created", image.Created.Unix())
|
|
|
out.SetInt64("Size", image.Size)
|
|
|
- out.SetInt64("VirtualSize", image.getParentsSize(0)+image.Size)
|
|
|
+ out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size)
|
|
|
outs.Add(out)
|
|
|
}
|
|
|
}
|
|
@@ -790,7 +794,7 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
|
|
|
}
|
|
|
|
|
|
func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
|
|
|
- images, _ := srv.runtime.graph.Map()
|
|
|
+ images, _ := srv.runtime.Graph().Map()
|
|
|
var imgcount int
|
|
|
if images == nil {
|
|
|
imgcount = 0
|
|
@@ -806,21 +810,21 @@ func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
|
|
|
initPath := utils.DockerInitPath("")
|
|
|
if initPath == "" {
|
|
|
// if that fails, we'll just return the path from the runtime
|
|
|
- initPath = srv.runtime.sysInitPath
|
|
|
+ initPath = srv.runtime.SystemInitPath()
|
|
|
}
|
|
|
|
|
|
v := &engine.Env{}
|
|
|
v.SetInt("Containers", len(srv.runtime.List()))
|
|
|
v.SetInt("Images", imgcount)
|
|
|
- v.Set("Driver", srv.runtime.driver.String())
|
|
|
- v.SetJson("DriverStatus", srv.runtime.driver.Status())
|
|
|
- v.SetBool("MemoryLimit", srv.runtime.sysInfo.MemoryLimit)
|
|
|
- v.SetBool("SwapLimit", srv.runtime.sysInfo.SwapLimit)
|
|
|
- v.SetBool("IPv4Forwarding", !srv.runtime.sysInfo.IPv4ForwardingDisabled)
|
|
|
+ v.Set("Driver", srv.runtime.GraphDriver().String())
|
|
|
+ v.SetJson("DriverStatus", srv.runtime.GraphDriver().Status())
|
|
|
+ v.SetBool("MemoryLimit", srv.runtime.SystemConfig().MemoryLimit)
|
|
|
+ v.SetBool("SwapLimit", srv.runtime.SystemConfig().SwapLimit)
|
|
|
+ v.SetBool("IPv4Forwarding", !srv.runtime.SystemConfig().IPv4ForwardingDisabled)
|
|
|
v.SetBool("Debug", os.Getenv("DEBUG") != "")
|
|
|
v.SetInt("NFd", utils.GetTotalUsedFds())
|
|
|
- v.SetInt("NGoroutines", runtime.NumGoroutine())
|
|
|
- v.Set("ExecutionDriver", srv.runtime.execDriver.Name())
|
|
|
+ v.SetInt("NGoroutines", goruntime.NumGoroutine())
|
|
|
+ v.Set("ExecutionDriver", srv.runtime.ExecutionDriver().Name())
|
|
|
v.SetInt("NEventsListener", len(srv.listeners))
|
|
|
v.Set("KernelVersion", kernelVersion)
|
|
|
v.Set("IndexServerAddress", auth.IndexServerAddress())
|
|
@@ -837,13 +841,13 @@ func (srv *Server) ImageHistory(job *engine.Job) engine.Status {
|
|
|
return job.Errorf("Usage: %s IMAGE", job.Name)
|
|
|
}
|
|
|
name := job.Args[0]
|
|
|
- image, err := srv.runtime.repositories.LookupImage(name)
|
|
|
+ foundImage, err := srv.runtime.Repositories().LookupImage(name)
|
|
|
if err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
|
|
|
lookupMap := make(map[string][]string)
|
|
|
- for name, repository := range srv.runtime.repositories.Repositories {
|
|
|
+ for name, repository := range srv.runtime.Repositories().Repositories {
|
|
|
for tag, id := range repository {
|
|
|
// If the ID already has a reverse lookup, do not update it unless for "latest"
|
|
|
if _, exists := lookupMap[id]; !exists {
|
|
@@ -854,7 +858,7 @@ func (srv *Server) ImageHistory(job *engine.Job) engine.Status {
|
|
|
}
|
|
|
|
|
|
outs := engine.NewTable("Created", 0)
|
|
|
- err = image.WalkHistory(func(img *Image) error {
|
|
|
+ err = foundImage.WalkHistory(func(img *image.Image) error {
|
|
|
out := &engine.Env{}
|
|
|
out.Set("Id", img.ID)
|
|
|
out.SetInt64("Created", img.Created.Unix())
|
|
@@ -888,7 +892,7 @@ func (srv *Server) ContainerTop(job *engine.Job) engine.Status {
|
|
|
if !container.State.IsRunning() {
|
|
|
return job.Errorf("Container %s is not running", name)
|
|
|
}
|
|
|
- pids, err := srv.runtime.execDriver.GetPidsForContainer(container.ID)
|
|
|
+ pids, err := srv.runtime.ExecutionDriver().GetPidsForContainer(container.ID)
|
|
|
if err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
@@ -981,7 +985,7 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
|
|
|
outs := engine.NewTable("Created", 0)
|
|
|
|
|
|
names := map[string][]string{}
|
|
|
- srv.runtime.containerGraph.Walk("/", func(p string, e *graphdb.Entity) error {
|
|
|
+ srv.runtime.ContainerGraph().Walk("/", func(p string, e *graphdb.Entity) error {
|
|
|
names[e.ID()] = append(names[e.ID()], p)
|
|
|
return nil
|
|
|
}, -1)
|
|
@@ -1006,7 +1010,7 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
|
|
|
out := &engine.Env{}
|
|
|
out.Set("Id", container.ID)
|
|
|
out.SetList("Names", names[container.ID])
|
|
|
- out.Set("Image", srv.runtime.repositories.ImageName(container.Image))
|
|
|
+ out.Set("Image", srv.runtime.Repositories().ImageName(container.Image))
|
|
|
if len(container.Args) > 0 {
|
|
|
out.Set("Command", fmt.Sprintf("\"%s %s\"", container.Path, strings.Join(container.Args, " ")))
|
|
|
} else {
|
|
@@ -1064,7 +1068,7 @@ func (srv *Server) ImageTag(job *engine.Job) engine.Status {
|
|
|
if len(job.Args) == 3 {
|
|
|
tag = job.Args[2]
|
|
|
}
|
|
|
- if err := srv.runtime.repositories.Set(job.Args[1], tag, job.Args[0], job.GetenvBool("force")); err != nil {
|
|
|
+ if err := srv.runtime.Repositories().Set(job.Args[1], tag, job.Args[0], job.GetenvBool("force")); err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
return engine.StatusOK
|
|
@@ -1089,7 +1093,7 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoin
|
|
|
}
|
|
|
defer srv.poolRemove("pull", "layer:"+id)
|
|
|
|
|
|
- if !srv.runtime.graph.Exists(id) {
|
|
|
+ if !srv.runtime.Graph().Exists(id) {
|
|
|
out.Write(sf.FormatProgress(utils.TruncateID(id), "Pulling metadata", nil))
|
|
|
imgJSON, imgSize, err := r.GetRemoteImageJSON(id, endpoint, token)
|
|
|
if err != nil {
|
|
@@ -1097,7 +1101,7 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoin
|
|
|
// FIXME: Keep going in case of error?
|
|
|
return err
|
|
|
}
|
|
|
- img, err := NewImgJSON(imgJSON)
|
|
|
+ img, err := image.NewImgJSON(imgJSON)
|
|
|
if err != nil {
|
|
|
out.Write(sf.FormatProgress(utils.TruncateID(id), "Error pulling dependent layers", nil))
|
|
|
return fmt.Errorf("Failed to parse json: %s", err)
|
|
@@ -1111,7 +1115,7 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgID, endpoin
|
|
|
return err
|
|
|
}
|
|
|
defer layer.Close()
|
|
|
- if err := srv.runtime.graph.Register(imgJSON, utils.ProgressReader(layer, imgSize, out, sf, false, utils.TruncateID(id), "Downloading"), img); err != nil {
|
|
|
+ if err := srv.runtime.Graph().Register(imgJSON, utils.ProgressReader(layer, imgSize, out, sf, false, utils.TruncateID(id), "Downloading"), img); err != nil {
|
|
|
out.Write(sf.FormatProgress(utils.TruncateID(id), "Error downloading dependent layers", nil))
|
|
|
return err
|
|
|
}
|
|
@@ -1246,11 +1250,11 @@ func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, localName
|
|
|
if askedTag != "" && tag != askedTag {
|
|
|
continue
|
|
|
}
|
|
|
- if err := srv.runtime.repositories.Set(localName, tag, id, true); err != nil {
|
|
|
+ if err := srv.runtime.Repositories().Set(localName, tag, id, true); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
- if err := srv.runtime.repositories.Save(); err != nil {
|
|
|
+ if err := srv.runtime.Repositories().Save(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
@@ -1371,7 +1375,7 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]string, map[stri
|
|
|
|
|
|
tagsByImage[id] = append(tagsByImage[id], tag)
|
|
|
|
|
|
- for img, err := srv.runtime.graph.Get(id); img != nil; img, err = img.GetParent() {
|
|
|
+ for img, err := srv.runtime.Graph().Get(id); img != nil; img, err = img.GetParent() {
|
|
|
if err != nil {
|
|
|
return nil, nil, err
|
|
|
}
|
|
@@ -1478,7 +1482,7 @@ func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, localName
|
|
|
|
|
|
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"))
|
|
|
+ jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.Graph().Root, imgID, "json"))
|
|
|
if err != nil {
|
|
|
return "", fmt.Errorf("Cannot retrieve the path for {%s}: %s", imgID, err)
|
|
|
}
|
|
@@ -1497,7 +1501,7 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgID,
|
|
|
return "", err
|
|
|
}
|
|
|
|
|
|
- layerData, err := srv.runtime.graph.TempLayerArchive(imgID, archive.Uncompressed, sf, out)
|
|
|
+ layerData, err := srv.runtime.Graph().TempLayerArchive(imgID, archive.Uncompressed, sf, out)
|
|
|
if err != nil {
|
|
|
return "", fmt.Errorf("Failed to generate layer archive: %s", err)
|
|
|
}
|
|
@@ -1549,17 +1553,17 @@ func (srv *Server) ImagePush(job *engine.Job) engine.Status {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
|
|
|
- img, err := srv.runtime.graph.Get(localName)
|
|
|
+ img, err := srv.runtime.Graph().Get(localName)
|
|
|
r, err2 := registry.NewRegistry(authConfig, srv.HTTPRequestFactory(metaHeaders), endpoint)
|
|
|
if err2 != nil {
|
|
|
return job.Error(err2)
|
|
|
}
|
|
|
|
|
|
if err != nil {
|
|
|
- reposLen := len(srv.runtime.repositories.Repositories[localName])
|
|
|
+ reposLen := len(srv.runtime.Repositories().Repositories[localName])
|
|
|
job.Stdout.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 localRepo, exists := srv.runtime.Repositories().Repositories[localName]; exists {
|
|
|
if err := srv.pushRepository(r, job.Stdout, localName, remoteName, localRepo, sf); err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
@@ -1615,13 +1619,13 @@ func (srv *Server) ImageImport(job *engine.Job) engine.Status {
|
|
|
defer progressReader.Close()
|
|
|
archive = progressReader
|
|
|
}
|
|
|
- img, err := srv.runtime.graph.Create(archive, nil, "Imported from "+src, "", nil)
|
|
|
+ img, err := srv.runtime.Graph().Create(archive, "", "", "Imported from "+src, "", nil, nil)
|
|
|
if err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
// Optionally register the image at REPO/TAG
|
|
|
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 job.Error(err)
|
|
|
}
|
|
|
}
|
|
@@ -1640,11 +1644,11 @@ func (srv *Server) ContainerCreate(job *engine.Job) engine.Status {
|
|
|
if config.Memory != 0 && config.Memory < 524288 {
|
|
|
return job.Errorf("Minimum memory limit allowed is 512k")
|
|
|
}
|
|
|
- if config.Memory > 0 && !srv.runtime.sysInfo.MemoryLimit {
|
|
|
+ if config.Memory > 0 && !srv.runtime.SystemConfig().MemoryLimit {
|
|
|
job.Errorf("Your kernel does not support memory limit capabilities. Limitation discarded.\n")
|
|
|
config.Memory = 0
|
|
|
}
|
|
|
- if config.Memory > 0 && !srv.runtime.sysInfo.SwapLimit {
|
|
|
+ if config.Memory > 0 && !srv.runtime.SystemConfig().SwapLimit {
|
|
|
job.Errorf("Your kernel does not support swap limit capabilities. Limitation discarded.\n")
|
|
|
config.MemorySwap = -1
|
|
|
}
|
|
@@ -1652,26 +1656,26 @@ func (srv *Server) ContainerCreate(job *engine.Job) engine.Status {
|
|
|
if err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
- if !config.NetworkDisabled && len(config.Dns) == 0 && len(srv.runtime.config.Dns) == 0 && utils.CheckLocalDns(resolvConf) {
|
|
|
- job.Errorf("Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : %v\n", defaultDns)
|
|
|
- config.Dns = defaultDns
|
|
|
+ if !config.NetworkDisabled && len(config.Dns) == 0 && len(srv.runtime.Config().Dns) == 0 && utils.CheckLocalDns(resolvConf) {
|
|
|
+ job.Errorf("Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : %v\n", runtime.DefaultDns)
|
|
|
+ config.Dns = runtime.DefaultDns
|
|
|
}
|
|
|
|
|
|
container, buildWarnings, err := srv.runtime.Create(config, name)
|
|
|
if err != nil {
|
|
|
- if srv.runtime.graph.IsNotExist(err) {
|
|
|
+ if srv.runtime.Graph().IsNotExist(err) {
|
|
|
_, tag := utils.ParseRepositoryTag(config.Image)
|
|
|
if tag == "" {
|
|
|
- tag = DEFAULTTAG
|
|
|
+ tag = graph.DEFAULTTAG
|
|
|
}
|
|
|
return job.Errorf("No such image: %s (tag: %s)", config.Image, tag)
|
|
|
}
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
- if !container.Config.NetworkDisabled && srv.runtime.sysInfo.IPv4ForwardingDisabled {
|
|
|
+ if !container.Config.NetworkDisabled && srv.runtime.SystemConfig().IPv4ForwardingDisabled {
|
|
|
job.Errorf("IPv4 forwarding is disabled.\n")
|
|
|
}
|
|
|
- srv.LogEvent("create", container.ID, srv.runtime.repositories.ImageName(container.Image))
|
|
|
+ srv.LogEvent("create", container.ID, srv.runtime.Repositories().ImageName(container.Image))
|
|
|
// FIXME: this is necessary because runtime.Create might return a nil container
|
|
|
// with a non-nil error. This should not happen! Once it's fixed we
|
|
|
// can remove this workaround.
|
|
@@ -1699,7 +1703,7 @@ func (srv *Server) ContainerRestart(job *engine.Job) engine.Status {
|
|
|
if err := container.Restart(int(t)); err != nil {
|
|
|
return job.Errorf("Cannot restart container %s: %s\n", name, err)
|
|
|
}
|
|
|
- srv.LogEvent("restart", container.ID, srv.runtime.repositories.ImageName(container.Image))
|
|
|
+ srv.LogEvent("restart", container.ID, srv.runtime.Repositories().ImageName(container.Image))
|
|
|
} else {
|
|
|
return job.Errorf("No such container: %s\n", name)
|
|
|
}
|
|
@@ -1721,7 +1725,7 @@ func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status {
|
|
|
if container == nil {
|
|
|
return job.Errorf("No such link: %s", name)
|
|
|
}
|
|
|
- name, err := getFullName(name)
|
|
|
+ name, err := runtime.GetFullContainerName(name)
|
|
|
if err != nil {
|
|
|
job.Error(err)
|
|
|
}
|
|
@@ -1729,21 +1733,17 @@ func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status {
|
|
|
if parent == "/" {
|
|
|
return job.Errorf("Conflict, cannot remove the default name of the container")
|
|
|
}
|
|
|
- pe := srv.runtime.containerGraph.Get(parent)
|
|
|
+ pe := srv.runtime.ContainerGraph().Get(parent)
|
|
|
if pe == nil {
|
|
|
return job.Errorf("Cannot get parent %s for name %s", parent, name)
|
|
|
}
|
|
|
parentContainer := srv.runtime.Get(pe.ID())
|
|
|
|
|
|
- if parentContainer != nil && parentContainer.activeLinks != nil {
|
|
|
- if link, exists := parentContainer.activeLinks[n]; exists {
|
|
|
- link.Disable()
|
|
|
- } else {
|
|
|
- utils.Debugf("Could not find active link for %s", name)
|
|
|
- }
|
|
|
+ if parentContainer != nil {
|
|
|
+ parentContainer.DisableLink(n)
|
|
|
}
|
|
|
|
|
|
- if err := srv.runtime.containerGraph.Delete(name); err != nil {
|
|
|
+ if err := srv.runtime.ContainerGraph().Delete(name); err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
return engine.StatusOK
|
|
@@ -1762,13 +1762,13 @@ func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status {
|
|
|
if err := srv.runtime.Destroy(container); err != nil {
|
|
|
return job.Errorf("Cannot destroy container %s: %s", name, err)
|
|
|
}
|
|
|
- srv.LogEvent("destroy", container.ID, srv.runtime.repositories.ImageName(container.Image))
|
|
|
+ srv.LogEvent("destroy", container.ID, srv.runtime.Repositories().ImageName(container.Image))
|
|
|
|
|
|
if removeVolume {
|
|
|
var (
|
|
|
volumes = make(map[string]struct{})
|
|
|
binds = make(map[string]struct{})
|
|
|
- usedVolumes = make(map[string]*Container)
|
|
|
+ usedVolumes = make(map[string]*runtime.Container)
|
|
|
)
|
|
|
|
|
|
// the volume id is always the base of the path
|
|
@@ -1777,7 +1777,7 @@ func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status {
|
|
|
}
|
|
|
|
|
|
// populate bind map so that they can be skipped and not removed
|
|
|
- for _, bind := range container.hostConfig.Binds {
|
|
|
+ for _, bind := range container.HostConfig().Binds {
|
|
|
source := strings.Split(bind, ":")[0]
|
|
|
// TODO: refactor all volume stuff, all of it
|
|
|
// this is very important that we eval the link
|
|
@@ -1816,7 +1816,7 @@ func (srv *Server) ContainerDestroy(job *engine.Job) engine.Status {
|
|
|
log.Printf("The volume %s is used by the container %s. Impossible to remove it. Skipping.\n", volumeId, c.ID)
|
|
|
continue
|
|
|
}
|
|
|
- if err := srv.runtime.volumes.Delete(volumeId); err != nil {
|
|
|
+ if err := srv.runtime.Volumes().Delete(volumeId); err != nil {
|
|
|
return job.Errorf("Error calling volumes.Delete(%q): %v", volumeId, err)
|
|
|
}
|
|
|
}
|
|
@@ -1835,12 +1835,12 @@ func (srv *Server) DeleteImage(name string, imgs *engine.Table, first, force boo
|
|
|
|
|
|
repoName, tag = utils.ParseRepositoryTag(name)
|
|
|
if tag == "" {
|
|
|
- tag = DEFAULTTAG
|
|
|
+ tag = graph.DEFAULTTAG
|
|
|
}
|
|
|
|
|
|
- img, err := srv.runtime.repositories.LookupImage(name)
|
|
|
+ img, err := srv.runtime.Repositories().LookupImage(name)
|
|
|
if err != nil {
|
|
|
- if r, _ := srv.runtime.repositories.Get(repoName); r != nil {
|
|
|
+ if r, _ := srv.runtime.Repositories().Get(repoName); r != nil {
|
|
|
return fmt.Errorf("No such image: %s:%s", repoName, tag)
|
|
|
}
|
|
|
return fmt.Errorf("No such image: %s", name)
|
|
@@ -1851,14 +1851,14 @@ func (srv *Server) DeleteImage(name string, imgs *engine.Table, first, force boo
|
|
|
tag = ""
|
|
|
}
|
|
|
|
|
|
- byParents, err := srv.runtime.graph.ByParent()
|
|
|
+ byParents, err := srv.runtime.Graph().ByParent()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
//If delete by id, see if the id belong only to one repository
|
|
|
if repoName == "" {
|
|
|
- for _, repoAndTag := range srv.runtime.repositories.ByID()[img.ID] {
|
|
|
+ for _, repoAndTag := range srv.runtime.Repositories().ByID()[img.ID] {
|
|
|
parsedRepo, parsedTag := utils.ParseRepositoryTag(repoAndTag)
|
|
|
if repoName == "" || repoName == parsedRepo {
|
|
|
repoName = parsedRepo
|
|
@@ -1881,7 +1881,7 @@ func (srv *Server) DeleteImage(name string, imgs *engine.Table, first, force boo
|
|
|
|
|
|
//Untag the current image
|
|
|
for _, tag := range tags {
|
|
|
- tagDeleted, err := srv.runtime.repositories.Delete(repoName, tag)
|
|
|
+ tagDeleted, err := srv.runtime.Repositories().Delete(repoName, tag)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -1892,16 +1892,16 @@ func (srv *Server) DeleteImage(name string, imgs *engine.Table, first, force boo
|
|
|
srv.LogEvent("untag", img.ID, "")
|
|
|
}
|
|
|
}
|
|
|
- tags = srv.runtime.repositories.ByID()[img.ID]
|
|
|
+ tags = srv.runtime.Repositories().ByID()[img.ID]
|
|
|
if (len(tags) <= 1 && repoName == "") || len(tags) == 0 {
|
|
|
if len(byParents[img.ID]) == 0 {
|
|
|
if err := srv.canDeleteImage(img.ID); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- if err := srv.runtime.repositories.DeleteAll(img.ID); err != nil {
|
|
|
+ if err := srv.runtime.Repositories().DeleteAll(img.ID); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- if err := srv.runtime.graph.Delete(img.ID); err != nil {
|
|
|
+ if err := srv.runtime.Graph().Delete(img.ID); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
out := &engine.Env{}
|
|
@@ -1940,12 +1940,12 @@ func (srv *Server) ImageDelete(job *engine.Job) engine.Status {
|
|
|
|
|
|
func (srv *Server) canDeleteImage(imgID string) error {
|
|
|
for _, container := range srv.runtime.List() {
|
|
|
- parent, err := srv.runtime.repositories.LookupImage(container.Image)
|
|
|
+ parent, err := srv.runtime.Repositories().LookupImage(container.Image)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- if err := parent.WalkHistory(func(p *Image) error {
|
|
|
+ if err := parent.WalkHistory(func(p *image.Image) error {
|
|
|
if imgID == p.ID {
|
|
|
return fmt.Errorf("Conflict, cannot delete %s because the container %s is using it", utils.TruncateID(imgID), utils.TruncateID(container.ID))
|
|
|
}
|
|
@@ -1957,10 +1957,10 @@ func (srv *Server) canDeleteImage(imgID string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (srv *Server) ImageGetCached(imgID string, config *runconfig.Config) (*Image, error) {
|
|
|
+func (srv *Server) ImageGetCached(imgID string, config *runconfig.Config) (*image.Image, error) {
|
|
|
|
|
|
// Retrieve all images
|
|
|
- images, err := srv.runtime.graph.Map()
|
|
|
+ images, err := srv.runtime.Graph().Map()
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -1975,9 +1975,9 @@ func (srv *Server) ImageGetCached(imgID string, config *runconfig.Config) (*Imag
|
|
|
}
|
|
|
|
|
|
// Loop on the children of the given image and check the config
|
|
|
- var match *Image
|
|
|
+ var match *image.Image
|
|
|
for elem := range imageMap[imgID] {
|
|
|
- img, err := srv.runtime.graph.Get(elem)
|
|
|
+ img, err := srv.runtime.Graph().Get(elem)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -1990,7 +1990,7 @@ func (srv *Server) ImageGetCached(imgID string, config *runconfig.Config) (*Imag
|
|
|
return match, nil
|
|
|
}
|
|
|
|
|
|
-func (srv *Server) RegisterLinks(container *Container, hostConfig *runconfig.HostConfig) error {
|
|
|
+func (srv *Server) RegisterLinks(container *runtime.Container, hostConfig *runconfig.HostConfig) error {
|
|
|
runtime := srv.runtime
|
|
|
|
|
|
if hostConfig != nil && hostConfig.Links != nil {
|
|
@@ -2014,7 +2014,7 @@ func (srv *Server) RegisterLinks(container *Container, hostConfig *runconfig.Hos
|
|
|
// After we load all the links into the runtime
|
|
|
// set them to nil on the hostconfig
|
|
|
hostConfig.Links = nil
|
|
|
- if err := container.writeHostConfig(); err != nil {
|
|
|
+ if err := container.WriteHostConfig(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
@@ -2062,13 +2062,13 @@ func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
|
|
|
if err := srv.RegisterLinks(container, hostConfig); err != nil {
|
|
|
return job.Error(err)
|
|
|
}
|
|
|
- container.hostConfig = hostConfig
|
|
|
+ container.SetHostConfig(hostConfig)
|
|
|
container.ToDisk()
|
|
|
}
|
|
|
if err := container.Start(); err != nil {
|
|
|
return job.Errorf("Cannot start container %s: %s", name, err)
|
|
|
}
|
|
|
- srv.LogEvent("start", container.ID, runtime.repositories.ImageName(container.Image))
|
|
|
+ srv.LogEvent("start", container.ID, runtime.Repositories().ImageName(container.Image))
|
|
|
|
|
|
return engine.StatusOK
|
|
|
}
|
|
@@ -2088,7 +2088,7 @@ func (srv *Server) ContainerStop(job *engine.Job) engine.Status {
|
|
|
if err := container.Stop(int(t)); err != nil {
|
|
|
return job.Errorf("Cannot stop container %s: %s\n", name, err)
|
|
|
}
|
|
|
- srv.LogEvent("stop", container.ID, srv.runtime.repositories.ImageName(container.Image))
|
|
|
+ srv.LogEvent("stop", container.ID, srv.runtime.Repositories().ImageName(container.Image))
|
|
|
} else {
|
|
|
return job.Errorf("No such container: %s\n", name)
|
|
|
}
|
|
@@ -2234,15 +2234,15 @@ func (srv *Server) ContainerAttach(job *engine.Job) engine.Status {
|
|
|
return engine.StatusOK
|
|
|
}
|
|
|
|
|
|
-func (srv *Server) ContainerInspect(name string) (*Container, error) {
|
|
|
+func (srv *Server) ContainerInspect(name string) (*runtime.Container, error) {
|
|
|
if container := srv.runtime.Get(name); container != nil {
|
|
|
return container, nil
|
|
|
}
|
|
|
return nil, fmt.Errorf("No such container: %s", name)
|
|
|
}
|
|
|
|
|
|
-func (srv *Server) ImageInspect(name string) (*Image, error) {
|
|
|
- if image, err := srv.runtime.repositories.LookupImage(name); err == nil && image != nil {
|
|
|
+func (srv *Server) ImageInspect(name string) (*image.Image, error) {
|
|
|
+ if image, err := srv.runtime.Repositories().LookupImage(name); err == nil && image != nil {
|
|
|
return image, nil
|
|
|
}
|
|
|
return nil, fmt.Errorf("No such image: %s", name)
|
|
@@ -2277,9 +2277,9 @@ func (srv *Server) JobInspect(job *engine.Job) engine.Status {
|
|
|
return job.Error(errContainer)
|
|
|
}
|
|
|
object = &struct {
|
|
|
- *Container
|
|
|
+ *runtime.Container
|
|
|
HostConfig *runconfig.HostConfig
|
|
|
- }{container, container.hostConfig}
|
|
|
+ }{container, container.HostConfig()}
|
|
|
default:
|
|
|
return job.Errorf("Unknown kind: %s", kind)
|
|
|
}
|
|
@@ -2318,8 +2318,8 @@ func (srv *Server) ContainerCopy(job *engine.Job) engine.Status {
|
|
|
return job.Errorf("No such container: %s", name)
|
|
|
}
|
|
|
|
|
|
-func NewServer(eng *engine.Engine, config *DaemonConfig) (*Server, error) {
|
|
|
- runtime, err := NewRuntime(config, eng)
|
|
|
+func NewServer(eng *engine.Engine, config *daemonconfig.Config) (*Server, error) {
|
|
|
+ runtime, err := runtime.NewRuntime(config, eng)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -2332,7 +2332,7 @@ func NewServer(eng *engine.Engine, config *DaemonConfig) (*Server, error) {
|
|
|
listeners: make(map[string]chan utils.JSONMessage),
|
|
|
running: true,
|
|
|
}
|
|
|
- runtime.srv = srv
|
|
|
+ runtime.SetServer(srv)
|
|
|
return srv, nil
|
|
|
}
|
|
|
|
|
@@ -2400,7 +2400,7 @@ func (srv *Server) Close() error {
|
|
|
|
|
|
type Server struct {
|
|
|
sync.RWMutex
|
|
|
- runtime *Runtime
|
|
|
+ runtime *runtime.Runtime
|
|
|
pullingPool map[string]chan struct{}
|
|
|
pushingPool map[string]chan struct{}
|
|
|
events []utils.JSONMessage
|