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

[RFR] Do not rebuild binaries each time #70

Merged
merged 1 commit into from
Jun 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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