From 74f5a41a052a21abf68ff8d14ff174b2356afb20 Mon Sep 17 00:00:00 2001 From: Eric Richardson Date: Wed, 5 Mar 2014 16:53:10 -0500 Subject: [PATCH] Add ability to specify temp directory via DRONE_TMP environment variable * If not set, defaults to the previously-used `/tmp/drone` * This is the directory used for storing cached volumes, so in some deployment scenarios the admin may wish to place it somewhere more resilient than /tmp. --- pkg/build/build.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/build/build.go b/pkg/build/build.go index 54c5b41ca..3fd08fb86 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -326,6 +326,18 @@ func (b *Builder) run() error { host.Links = append(host.Links, service.Name[1:]+":"+image.Name) } + // where are temp files going to go? + tmp_path := "/tmp/drone" + if len(os.Getenv("DRONE_TMP")) > 0 { + tmp_path = os.Getenv("DRONE_TMP") + } + + log.Infof("temp directory is %s", tmp_path) + + if err := os.MkdirAll(tmp_path, 0777); err != nil { + return fmt.Errorf("Failed to create temp directory at %s: %s", tmp_path, err) + } + // link cached volumes conf.Volumes = make(map[string]struct{}) for _, volume := range b.Build.Cache { @@ -342,7 +354,7 @@ func (b *Builder) run() error { // local cache path on the host machine // this path is going to be really long - hostpath := filepath.Join("/tmp/drone", name, branch, volume) + hostpath := filepath.Join(tmp_path, name, branch, volume) // check if the volume is created if _, err := os.Stat(hostpath); err != nil { @@ -351,7 +363,7 @@ func (b *Builder) run() error { } host.Binds = append(host.Binds, hostpath+":"+volume) - conf.Volumes[volume]=struct{}{} + conf.Volumes[volume] = struct{}{} // debugging log.Infof("mounting volume %s:%s", hostpath, volume)