// BuildFile builds the specified docker file in the context of the specified // directory. func BuildFile(dockerfile, dir, tag string) string { if !file.Exists(dockerfile) { cli.Fatalf("File does not exist: %s", dockerfile) } dir = path.Resolve(dir) localDockerfile := ".SousDockerfile" if file.Exists(localDockerfile) { file.Remove(localDockerfile) } file.RemoveOnExit(localDockerfile) // If there is a .gitignore, but no .dockerignore, link it as .dockerignore if file.Exists(".gitignore") { if file.Exists(".dockerignore") { cli.Warn("./.dockerignore found, it is recommended to remove this so Sous can use your .gitignore") } else { file.TemporaryLink(".gitignore", ".dockerignore") // We try to clean this file up early, in preperation for the next build step defer file.Remove(".dockerignore") } } file.TemporaryLink(dockerfile, localDockerfile) // We try to clean the local Dockerfile up early, in preperation for the next build step defer file.Remove(localDockerfile) return dockerCmd("build", "-f", localDockerfile, "-t", tag, dir).Out() }
func (t *AppTarget) PreDockerBuild(c *core.Context) { if t.artifactPath == "" { cli.Fatalf("Artifact path not set by compile target.") } if !file.Exists(t.artifactPath) { cli.Fatalf("Artifact not at %s", t.artifactPath) } filename := path.Base(t.artifactPath) localArtifact := filename file.TemporaryLink(t.artifactPath, "./"+localArtifact) t.artifactPath = localArtifact }
func parseYAMLFile(f string, v interface{}) error { if !file.Exists(f) { return fmt.Errorf("%s not found", f) } b, err := ioutil.ReadFile(f) if err != nil { return err } if err := yaml.Unmarshal(b, v); err != nil { return fmt.Errorf("unable to parse %s as %T: %s", f, v, err) } return nil }
func (s *Sous) BuildImage(t Target, c *Context) { c.IncrementBuildNumber() if file.Exists("Dockerfile") { cli.Warn("./Dockerfile ignored by sous; use `sous dockerfile %s` to see the Dockerfile in effect", t.Name()) } if prebuilder, ok := t.(PreDockerBuilder); ok { prebuilder.PreDockerBuild(c) } // NB: Always rebuild the Dockerfile after running pre-build, since pre-build // may update target state to reflect things like copied file locations etc. c.SaveFile(s.Dockerfile(t, c).Render(), "Dockerfile") docker.BuildFile(c.FilePath("Dockerfile"), ".", c.DockerTag()) c.Commit() }