From c1b9353943d8649c37eea612802e313ce0fad93f Mon Sep 17 00:00:00 2001 From: Brad Date: Sun, 2 Mar 2014 22:54:09 -0800 Subject: [PATCH] added code to persist directories between builds. see issue #147 --- pkg/build/build.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/build/build.go b/pkg/build/build.go index 81284452..d4f29530 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -326,6 +326,37 @@ func (b *Builder) run() error { host.Links = append(host.Links, service.Name[1:]+":"+image.Name) } + // link cached volumes + conf.Volumes = make(map[string]struct{}) + for _, volume := range b.Build.Cache { + name := filepath.Clean(b.Repo.Name) + branch := filepath.Clean(b.Repo.Branch) + volume := filepath.Clean(volume) + + // with Docker, volumes must be an absolute path. If an absolute + // path is not provided, then assume it is for the repository + // working directory. + if strings.HasPrefix(volume, "/") == false { + volume = filepath.Join(b.Repo.Dir, volume) + } + + // local cache path on the host machine + // this path is going to be really long + hostpath := filepath.Join("/tmp/drone", name, branch, volume) + + // check if the volume is created + if _, err := os.Stat(hostpath); err != nil { + // if does not exist then create + os.MkdirAll(hostpath, 0777) + } + + host.Binds = append(host.Binds, hostpath+":"+volume) + conf.Volumes[volume]=struct{}{} + + // debugging + log.Infof("mounting volume %s:%s", hostpath, volume) + } + // create the container from the image run, err := b.dockerClient.Containers.Create(&conf) if err != nil {