Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 3a177cc

Browse files
author
Erik Hollensbe
committed
server/buildfile.go -> builder/builder.go; add maintainers file
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
1 parent 475131c commit 3a177cc

File tree

5 files changed

+46
-42
lines changed

5 files changed

+46
-42
lines changed

builder/MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Tibor Vass <teabee89@gmail.com> (@tiborvass)
2+
Erik Hollensbe <github@hollensbe.org> (@erikh)
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package server
1+
package builder
22

33
import (
44
"crypto/sha256"
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/docker/docker/archive"
2323
"github.com/docker/docker/daemon"
24+
"github.com/docker/docker/engine"
2425
"github.com/docker/docker/nat"
2526
"github.com/docker/docker/pkg/symlink"
2627
"github.com/docker/docker/pkg/system"
@@ -41,7 +42,7 @@ type BuildFile interface {
4142

4243
type buildFile struct {
4344
daemon *daemon.Daemon
44-
srv *Server
45+
eng *engine.Engine
4546

4647
image string
4748
maintainer string
@@ -96,7 +97,7 @@ func (b *buildFile) CmdFrom(name string) error {
9697
resolvedAuth := b.configFile.ResolveAuthConfig(endpoint)
9798
pullRegistryAuth = &resolvedAuth
9899
}
99-
job := b.srv.Eng.Job("pull", remote, tag)
100+
job := b.eng.Job("pull", remote, tag)
100101
job.SetenvBool("json", b.sf.Json())
101102
job.SetenvBool("parallel", true)
102103
job.SetenvJson("authConfig", pullRegistryAuth)
@@ -167,12 +168,12 @@ func (b *buildFile) CmdMaintainer(name string) error {
167168

168169
// probeCache checks to see if image-caching is enabled (`b.utilizeCache`)
169170
// and if so attempts to look up the current `b.image` and `b.config` pair
170-
// in the current server `b.srv`. If an image is found, probeCache returns
171+
// in the current server `b.daemon`. If an image is found, probeCache returns
171172
// `(true, nil)`. If no image is found, it returns `(false, nil)`. If there
172173
// is any error, it returns `(false, err)`.
173174
func (b *buildFile) probeCache() (bool, error) {
174175
if b.utilizeCache {
175-
if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil {
176+
if cache, err := b.daemon.ImageGetCached(b.image, b.config); err != nil {
176177
return false, err
177178
} else if cache != nil {
178179
fmt.Fprintf(b.outStream, " ---> Using cache\n")
@@ -889,10 +890,10 @@ func fixPermissions(destination string, uid, gid int) error {
889890
})
890891
}
891892

892-
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 {
893+
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 {
893894
return &buildFile{
894-
daemon: srv.daemon,
895-
srv: srv,
895+
daemon: d,
896+
eng: eng,
896897
config: &runconfig.Config{},
897898
outStream: outStream,
898899
errStream: errStream,

daemon/container.go

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

daemon/daemon.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,3 +1099,35 @@ func (daemon *Daemon) checkLocaldns() error {
10991099
}
11001100
return nil
11011101
}
1102+
1103+
func (daemon *Daemon) ImageGetCached(imgID string, config *runconfig.Config) (*image.Image, error) {
1104+
// Retrieve all images
1105+
images, err := daemon.Graph().Map()
1106+
if err != nil {
1107+
return nil, err
1108+
}
1109+
1110+
// Store the tree in a map of map (map[parentId][childId])
1111+
imageMap := make(map[string]map[string]struct{})
1112+
for _, img := range images {
1113+
if _, exists := imageMap[img.Parent]; !exists {
1114+
imageMap[img.Parent] = make(map[string]struct{})
1115+
}
1116+
imageMap[img.Parent][img.ID] = struct{}{}
1117+
}
1118+
1119+
// Loop on the children of the given image and check the config
1120+
var match *image.Image
1121+
for elem := range imageMap[imgID] {
1122+
img, err := daemon.Graph().Get(elem)
1123+
if err != nil {
1124+
return nil, err
1125+
}
1126+
if runconfig.Compare(&img.ContainerConfig, config) {
1127+
if match == nil || match.Created.Before(img.Created) {
1128+
match = img
1129+
}
1130+
}
1131+
}
1132+
return match, nil
1133+
}

server/server.go

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"time"
4747

4848
"github.com/docker/docker/archive"
49+
"github.com/docker/docker/builder"
4950
"github.com/docker/docker/daemon"
5051
"github.com/docker/docker/daemonconfig"
5152
"github.com/docker/docker/dockerversion"
@@ -534,7 +535,7 @@ func (srv *Server) Build(job *engine.Job) engine.Status {
534535
defer context.Close()
535536

536537
sf := utils.NewStreamFormatter(job.GetenvBool("json"))
537-
b := NewBuildFile(srv,
538+
b := builder.NewBuildFile(srv.daemon, srv.Eng,
538539
&utils.StdoutFormater{
539540
Writer: job.Stdout,
540541
StreamFormatter: sf,
@@ -2058,38 +2059,6 @@ func (srv *Server) canDeleteImage(imgID string, force, untagged bool) error {
20582059
return nil
20592060
}
20602061

2061-
func (srv *Server) ImageGetCached(imgID string, config *runconfig.Config) (*image.Image, error) {
2062-
// Retrieve all images
2063-
images, err := srv.daemon.Graph().Map()
2064-
if err != nil {
2065-
return nil, err
2066-
}
2067-
2068-
// Store the tree in a map of map (map[parentId][childId])
2069-
imageMap := make(map[string]map[string]struct{})
2070-
for _, img := range images {
2071-
if _, exists := imageMap[img.Parent]; !exists {
2072-
imageMap[img.Parent] = make(map[string]struct{})
2073-
}
2074-
imageMap[img.Parent][img.ID] = struct{}{}
2075-
}
2076-
2077-
// Loop on the children of the given image and check the config
2078-
var match *image.Image
2079-
for elem := range imageMap[imgID] {
2080-
img, err := srv.daemon.Graph().Get(elem)
2081-
if err != nil {
2082-
return nil, err
2083-
}
2084-
if runconfig.Compare(&img.ContainerConfig, config) {
2085-
if match == nil || match.Created.Before(img.Created) {
2086-
match = img
2087-
}
2088-
}
2089-
}
2090-
return match, nil
2091-
}
2092-
20932062
func (srv *Server) setHostConfig(container *daemon.Container, hostConfig *runconfig.HostConfig) error {
20942063
// Validate the HostConfig binds. Make sure that:
20952064
// the source exists

0 commit comments

Comments
 (0)