Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #70 from marmelab/do_not_rebuild_binaries
Browse files Browse the repository at this point in the history
[RFR] Do not rebuild binaries each time
  • Loading branch information
manuquentin committed Jun 6, 2014
2 parents c82469f + e443c74 commit 13de1e3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
10 changes: 6 additions & 4 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *Container) Init() {
if c.Add == nil {
c.Add = make(map[string]string)
}

if c.Custom == nil {
c.Custom = make(map[string]interface{})
}
Expand Down Expand Up @@ -213,9 +213,11 @@ func (c *Container) Start(rebuild bool) {
}

func (c *Container) BuildAndRun(currentPath string, arguments []string) {
buildChans := make(chan bool, 1)
go c.BuildOrPull(buildChans)
<-buildChans
if docker.ShouldRebuild(c.Image) {
buildChans := make(chan bool, 1)
go c.BuildOrPull(buildChans)
<-buildChans
}

c.Run(currentPath, arguments)
}
Expand Down
36 changes: 36 additions & 0 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,42 @@ func SnapshotProcesses() (map[string]string, error) {
return images, nil
}

func ShouldRebuild(imageName string) bool {
images, err := GetImages()

if err != nil {
return false
}

_, ok := images[imageName]
return !ok
}

func GetImages() (map[string]string, error) {
images := make(map[string]string)

imagesCommand := exec.Command(getDockerBinaryPath(), "images")
out, err := imagesCommand.CombinedOutput()
if err != nil {
return nil, errors.New(string(out))
}

// Retrieve lines & remove first and last one
lines := strings.Split(string(out), "\n")
lines = lines[1 : len(lines)-1]

for _, line := range lines {
fields := strings.Fields(line)
if fields[0] == "<none>" {
continue
}

images[fields[0]] = fields[2]
}

return images, nil
}

func getDockerBinaryPath() string {
if len(docker) != 0 {
return docker
Expand Down
1 change: 1 addition & 0 deletions gaudi/gaudi_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func (s *GaudiTestSuite) TestStartBinariesShouldCleanAndBuildThem(c *C) {

docker.EXPECT().ImageExists(gomock.Any()).Return(true).Times(1)
docker.EXPECT().HasDocker().Return(true).Times(1)
docker.EXPECT().ShouldRebuild(gomock.Any()).Return(true).Times(1)

util.EXPECT().PrintGreen("Building", "gaudi/npm", "...")
docker.EXPECT().Build(gomock.Any(), gomock.Any()).Times(1)
Expand Down

0 comments on commit 13de1e3

Please sign in to comment.