server/buildfile.go -> builder/builder.go; add maintainers file

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
Erik Hollensbe 2014-07-28 22:22:58 -07:00
parent 475131cd4a
commit 3a177ccd3a
5 changed files with 46 additions and 42 deletions

2
builder/MAINTAINERS Normal file
View File

@ -0,0 +1,2 @@
Tibor Vass <teabee89@gmail.com> (@tiborvass)
Erik Hollensbe <github@hollensbe.org> (@erikh)

View File

@ -1,4 +1,4 @@
package server
package builder
import (
"crypto/sha256"
@ -21,6 +21,7 @@ import (
"github.com/docker/docker/archive"
"github.com/docker/docker/daemon"
"github.com/docker/docker/engine"
"github.com/docker/docker/nat"
"github.com/docker/docker/pkg/symlink"
"github.com/docker/docker/pkg/system"
@ -41,7 +42,7 @@ type BuildFile interface {
type buildFile struct {
daemon *daemon.Daemon
srv *Server
eng *engine.Engine
image string
maintainer string
@ -96,7 +97,7 @@ func (b *buildFile) CmdFrom(name string) error {
resolvedAuth := b.configFile.ResolveAuthConfig(endpoint)
pullRegistryAuth = &resolvedAuth
}
job := b.srv.Eng.Job("pull", remote, tag)
job := b.eng.Job("pull", remote, tag)
job.SetenvBool("json", b.sf.Json())
job.SetenvBool("parallel", true)
job.SetenvJson("authConfig", pullRegistryAuth)
@ -167,12 +168,12 @@ func (b *buildFile) CmdMaintainer(name string) error {
// probeCache checks to see if image-caching is enabled (`b.utilizeCache`)
// and if so attempts to look up the current `b.image` and `b.config` pair
// in the current server `b.srv`. If an image is found, probeCache returns
// in the current server `b.daemon`. If an image is found, probeCache returns
// `(true, nil)`. If no image is found, it returns `(false, nil)`. If there
// is any error, it returns `(false, err)`.
func (b *buildFile) probeCache() (bool, error) {
if b.utilizeCache {
if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil {
if cache, err := b.daemon.ImageGetCached(b.image, b.config); err != nil {
return false, err
} else if cache != nil {
fmt.Fprintf(b.outStream, " ---> Using cache\n")
@ -889,10 +890,10 @@ func fixPermissions(destination string, uid, gid int) error {
})
}
func NewBuildFile(srv *Server, outStream, errStream io.Writer, verbose, utilizeCache, rm bool, forceRm bool, outOld io.Writer, sf *utils.StreamFormatter, auth *registry.AuthConfig, authConfigFile *registry.ConfigFile) BuildFile {
func NewBuildFile(d *daemon.Daemon, eng *engine.Engine, outStream, errStream io.Writer, verbose, utilizeCache, rm bool, forceRm bool, outOld io.Writer, sf *utils.StreamFormatter, auth *registry.AuthConfig, authConfigFile *registry.ConfigFile) BuildFile {
return &buildFile{
daemon: srv.daemon,
srv: srv,
daemon: d,
eng: eng,
config: &runconfig.Config{},
outStream: outStream,
errStream: errStream,

View File

@ -513,7 +513,7 @@ func (container *Container) monitor(callback execdriver.StartCallback) error {
if container.daemon != nil && container.daemon.srv != nil && container.daemon.srv.IsRunning() {
// FIXME: here is race condition between two RUN instructions in Dockerfile
// because they share same runconfig and change image. Must be fixed
// in server/buildfile.go
// in builder/builder.go
if err := container.toDisk(); err != nil {
utils.Errorf("Error dumping container %s state to disk: %s\n", container.ID, err)
}

View File

@ -1099,3 +1099,35 @@ func (daemon *Daemon) checkLocaldns() error {
}
return nil
}
func (daemon *Daemon) ImageGetCached(imgID string, config *runconfig.Config) (*image.Image, error) {
// Retrieve all images
images, err := daemon.Graph().Map()
if err != nil {
return nil, err
}
// Store the tree in a map of map (map[parentId][childId])
imageMap := make(map[string]map[string]struct{})
for _, img := range images {
if _, exists := imageMap[img.Parent]; !exists {
imageMap[img.Parent] = make(map[string]struct{})
}
imageMap[img.Parent][img.ID] = struct{}{}
}
// Loop on the children of the given image and check the config
var match *image.Image
for elem := range imageMap[imgID] {
img, err := daemon.Graph().Get(elem)
if err != nil {
return nil, err
}
if runconfig.Compare(&img.ContainerConfig, config) {
if match == nil || match.Created.Before(img.Created) {
match = img
}
}
}
return match, nil
}

View File

@ -46,6 +46,7 @@ import (
"time"
"github.com/docker/docker/archive"
"github.com/docker/docker/builder"
"github.com/docker/docker/daemon"
"github.com/docker/docker/daemonconfig"
"github.com/docker/docker/dockerversion"
@ -534,7 +535,7 @@ func (srv *Server) Build(job *engine.Job) engine.Status {
defer context.Close()
sf := utils.NewStreamFormatter(job.GetenvBool("json"))
b := NewBuildFile(srv,
b := builder.NewBuildFile(srv.daemon, srv.Eng,
&utils.StdoutFormater{
Writer: job.Stdout,
StreamFormatter: sf,
@ -2058,38 +2059,6 @@ func (srv *Server) canDeleteImage(imgID string, force, untagged bool) error {
return nil
}
func (srv *Server) ImageGetCached(imgID string, config *runconfig.Config) (*image.Image, error) {
// Retrieve all images
images, err := srv.daemon.Graph().Map()
if err != nil {
return nil, err
}
// Store the tree in a map of map (map[parentId][childId])
imageMap := make(map[string]map[string]struct{})
for _, img := range images {
if _, exists := imageMap[img.Parent]; !exists {
imageMap[img.Parent] = make(map[string]struct{})
}
imageMap[img.Parent][img.ID] = struct{}{}
}
// Loop on the children of the given image and check the config
var match *image.Image
for elem := range imageMap[imgID] {
img, err := srv.daemon.Graph().Get(elem)
if err != nil {
return nil, err
}
if runconfig.Compare(&img.ContainerConfig, config) {
if match == nil || match.Created.Before(img.Created) {
match = img
}
}
}
return match, nil
}
func (srv *Server) setHostConfig(container *daemon.Container, hostConfig *runconfig.HostConfig) error {
// Validate the HostConfig binds. Make sure that:
// the source exists