Exemple #1
0
// 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()
}
Exemple #2
0
func Write(data []byte, pathFormat string, a ...interface{}) {
	p := path.Resolve(pathFormat, a...)
	dir.EnsureExists(path.BaseDir(p))
	err := ioutil.WriteFile(p, data, 0777)
	if err != nil {
		cli.Fatalf("unable to write file %s; %s", p, err)
	}
}
Exemple #3
0
func BuildPath(sous *core.Sous, args []string) {
	target := "app"
	if len(args) != 0 {
		target = args[0]
	}
	_, context := sous.AssembleTargetContext(target)
	fmt.Println(path.Resolve(path.BaseDir(context.BaseDir())))
	cli.Success()
}
Exemple #4
0
func Read(pathFormat string, a ...interface{}) ([]byte, bool, string) {
	path := path.Resolve(pathFormat, a...)
	contents, err := ioutil.ReadFile(path)
	if err == nil {
		return contents, true, path
	}
	if os.IsNotExist(err) {
		return nil, false, path
	}
	cli.Fatalf("Unable to read file %s: %s", path, err)
	return nil, false, path
}
Exemple #5
0
func Exists(pathFormat string, a ...interface{}) bool {
	path := path.Resolve(pathFormat, a...)
	s, err := os.Stat(path)
	if err == nil {
		if s.IsDir() {
			return true
		} else {
			return false
		}
	}
	if !os.IsNotExist(err) {
		cli.Fatalf("unable to stat path %s", path)
	}
	return false
}
Exemple #6
0
func EnsureExists(pathFormat string, a ...interface{}) {
	path := path.Resolve(pathFormat, a...)
	s, err := os.Stat(path)
	if err == nil {
		if s.IsDir() {
			return
		} else {
			cli.Fatalf("%s exists and is not a directory", path)
		}
	}
	if os.IsNotExist(err) {
		if err := os.MkdirAll(path, 0777); err != nil {
			cli.Fatalf("unable to make directory %s; %s", path, err)
		}
		return
	}
	cli.Fatalf("unable to stat or create directory %s", path)
}
Exemple #7
0
// FilePath returns a path to a named file within the state directory
// of the current build target. This is used for things like passing
// artifacts from one build step to the next.
func (c *Context) FilePath(name string) string {
	return path.Resolve(c.BaseDir() + "/" + name)
}
Exemple #8
0
func configFilePath() string {
	return path.Resolve("~/.sous/config")
}
Exemple #9
0
func propertiesFilePath() string {
	return path.Resolve("~/.sous/properties")
}
Exemple #10
0
// Build builds the dockerfile in the specified directory and returns the image ID
func Build(dir, tag string) string {
	dir = path.Resolve(dir)
	return dockerCmd("build", "-t", tag, dir).Out()
}