mirror of https://github.com/docker/docs.git
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:
parent
475131cd4a
commit
3a177ccd3a
|
@ -0,0 +1,2 @@
|
||||||
|
Tibor Vass <teabee89@gmail.com> (@tiborvass)
|
||||||
|
Erik Hollensbe <github@hollensbe.org> (@erikh)
|
|
@ -1,4 +1,4 @@
|
||||||
package server
|
package builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
@ -21,6 +21,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/archive"
|
"github.com/docker/docker/archive"
|
||||||
"github.com/docker/docker/daemon"
|
"github.com/docker/docker/daemon"
|
||||||
|
"github.com/docker/docker/engine"
|
||||||
"github.com/docker/docker/nat"
|
"github.com/docker/docker/nat"
|
||||||
"github.com/docker/docker/pkg/symlink"
|
"github.com/docker/docker/pkg/symlink"
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
|
@ -41,7 +42,7 @@ type BuildFile interface {
|
||||||
|
|
||||||
type buildFile struct {
|
type buildFile struct {
|
||||||
daemon *daemon.Daemon
|
daemon *daemon.Daemon
|
||||||
srv *Server
|
eng *engine.Engine
|
||||||
|
|
||||||
image string
|
image string
|
||||||
maintainer string
|
maintainer string
|
||||||
|
@ -96,7 +97,7 @@ func (b *buildFile) CmdFrom(name string) error {
|
||||||
resolvedAuth := b.configFile.ResolveAuthConfig(endpoint)
|
resolvedAuth := b.configFile.ResolveAuthConfig(endpoint)
|
||||||
pullRegistryAuth = &resolvedAuth
|
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("json", b.sf.Json())
|
||||||
job.SetenvBool("parallel", true)
|
job.SetenvBool("parallel", true)
|
||||||
job.SetenvJson("authConfig", pullRegistryAuth)
|
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`)
|
// 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
|
// 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
|
// `(true, nil)`. If no image is found, it returns `(false, nil)`. If there
|
||||||
// is any error, it returns `(false, err)`.
|
// is any error, it returns `(false, err)`.
|
||||||
func (b *buildFile) probeCache() (bool, error) {
|
func (b *buildFile) probeCache() (bool, error) {
|
||||||
if b.utilizeCache {
|
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
|
return false, err
|
||||||
} else if cache != nil {
|
} else if cache != nil {
|
||||||
fmt.Fprintf(b.outStream, " ---> Using cache\n")
|
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{
|
return &buildFile{
|
||||||
daemon: srv.daemon,
|
daemon: d,
|
||||||
srv: srv,
|
eng: eng,
|
||||||
config: &runconfig.Config{},
|
config: &runconfig.Config{},
|
||||||
outStream: outStream,
|
outStream: outStream,
|
||||||
errStream: errStream,
|
errStream: errStream,
|
|
@ -513,7 +513,7 @@ func (container *Container) monitor(callback execdriver.StartCallback) error {
|
||||||
if container.daemon != nil && container.daemon.srv != nil && container.daemon.srv.IsRunning() {
|
if container.daemon != nil && container.daemon.srv != nil && container.daemon.srv.IsRunning() {
|
||||||
// FIXME: here is race condition between two RUN instructions in Dockerfile
|
// FIXME: here is race condition between two RUN instructions in Dockerfile
|
||||||
// because they share same runconfig and change image. Must be fixed
|
// 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 {
|
if err := container.toDisk(); err != nil {
|
||||||
utils.Errorf("Error dumping container %s state to disk: %s\n", container.ID, err)
|
utils.Errorf("Error dumping container %s state to disk: %s\n", container.ID, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1099,3 +1099,35 @@ func (daemon *Daemon) checkLocaldns() error {
|
||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/archive"
|
"github.com/docker/docker/archive"
|
||||||
|
"github.com/docker/docker/builder"
|
||||||
"github.com/docker/docker/daemon"
|
"github.com/docker/docker/daemon"
|
||||||
"github.com/docker/docker/daemonconfig"
|
"github.com/docker/docker/daemonconfig"
|
||||||
"github.com/docker/docker/dockerversion"
|
"github.com/docker/docker/dockerversion"
|
||||||
|
@ -534,7 +535,7 @@ func (srv *Server) Build(job *engine.Job) engine.Status {
|
||||||
defer context.Close()
|
defer context.Close()
|
||||||
|
|
||||||
sf := utils.NewStreamFormatter(job.GetenvBool("json"))
|
sf := utils.NewStreamFormatter(job.GetenvBool("json"))
|
||||||
b := NewBuildFile(srv,
|
b := builder.NewBuildFile(srv.daemon, srv.Eng,
|
||||||
&utils.StdoutFormater{
|
&utils.StdoutFormater{
|
||||||
Writer: job.Stdout,
|
Writer: job.Stdout,
|
||||||
StreamFormatter: sf,
|
StreamFormatter: sf,
|
||||||
|
@ -2058,38 +2059,6 @@ func (srv *Server) canDeleteImage(imgID string, force, untagged bool) error {
|
||||||
return nil
|
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 {
|
func (srv *Server) setHostConfig(container *daemon.Container, hostConfig *runconfig.HostConfig) error {
|
||||||
// Validate the HostConfig binds. Make sure that:
|
// Validate the HostConfig binds. Make sure that:
|
||||||
// the source exists
|
// the source exists
|
||||||
|
|
Loading…
Reference in New Issue