Created
October 2, 2014 08:49
-
-
Save tonistiigi/68946ccc44ac7a24f087 to your computer and use it in GitHub Desktop.
nested-builds-2.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/builder/dispatchers.go b/builder/dispatchers.go | |
index 541a300..b2a2675 100644 | |
--- a/builder/dispatchers.go | |
+++ b/builder/dispatchers.go | |
@@ -357,12 +357,17 @@ func build(b *Builder, args []string, attributes map[string]bool) error { | |
contextPath = filepath.Join(c.RootfsPath(), contextPath) | |
- if _, err := os.Stat(contextPath); os.IsNotExist(err) { | |
- return fmt.Errorf("no such directory: %s", contextPath) | |
+ dirInfo, err := os.Stat(contextPath) | |
+ if err != nil { | |
+ return err | |
+ } | |
+ if !dirInfo.IsDir() { | |
+ return fmt.Errorf("%s is not a directory", contextPath) | |
} | |
if len(dockerfile) > 1 { | |
- f, err := os.Create(filepath.Join(contextPath, "Dockerfile")) | |
+ dockerfilePath := filepath.Join(contextPath, "Dockerfile") | |
+ f, err := os.Create(dockerfilePath) | |
if err != nil { | |
return err | |
} | |
@@ -371,6 +376,17 @@ func build(b *Builder, args []string, attributes map[string]bool) error { | |
if err != nil { | |
return err | |
} | |
+ | |
+ // Reset the modified times so the Dockerfile can't invalidate cache. | |
+ err = os.Chtimes(dockerfilePath, dirInfo.ModTime(), dirInfo.ModTime()) | |
+ if err != nil { | |
+ return err | |
+ } | |
+ err = os.Chtimes(contextPath, dirInfo.ModTime(), dirInfo.ModTime()) | |
+ if err != nil { | |
+ return err | |
+ } | |
+ | |
} | |
archive, err := archive.Tar(contextPath, archive.Uncompressed) | |
@@ -380,15 +396,15 @@ func build(b *Builder, args []string, attributes map[string]bool) error { | |
defer archive.Close() | |
copy := *b | |
- builder := © | |
+ newBuilder := © | |
- _, err = builder.Run(archive) | |
+ _, err = newBuilder.Run(archive) | |
if err != nil { | |
return err | |
} | |
if b.RepoName != "" { | |
- b.RepoName += "-builder" | |
+ b.RepoName = newBuilder.RepoName + "-builder" | |
} | |
return nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment