示例#1
0
文件: builder.go 项目: opentable/sous
// NewBuilder creates a new build using source code in the working
// directory of sourceShell, and using the working dir of scratchShell as
// temporary storage.
func NewBuilder(nc sous.Inserter, drh string, sourceShell, scratchShell shell.Shell) (*Builder, error) {
	b := &Builder{
		ImageMapper:        nc,
		DockerRegistryHost: drh,
		SourceShell:        sourceShell,
		ScratchShell:       scratchShell,
	}

	files, err := scratchShell.List()
	if err != nil {
		return nil, err
	}

	if len(files) != 0 {
		return nil, fmt.Errorf("scratch dir %s was not empty", scratchShell.Dir())
	}

	return b, nil
}
示例#2
0
文件: otpl.go 项目: opentable/sous
// GetDeploySpecs searches the working directory of wd to find otpl-deploy
// config files in their standard locations (config/{cluster-name}), and
// converts them to sous.DeploySpecs.
func (dsp *DeploySpecParser) GetDeploySpecs(wd shell.Shell) sous.DeploySpecs {
	wd = wd.Clone()
	if err := wd.CD("config"); err != nil {
		return nil
	}
	l, err := wd.List()
	if err != nil {
		dsp.debug(err)
		return nil
	}
	c := make(chan namedDeploySpec)
	wg := sync.WaitGroup{}
	wg.Add(len(l))
	go func() { wg.Wait(); close(c) }()
	for _, f := range l {
		f := f
		go func() {
			defer wg.Done()
			if !f.IsDir() {
				return
			}
			wd := wd.Clone()
			if err := wd.CD(f.Name()); err != nil {
				dsp.debug(err)
				return
			}
			if otplConfig := dsp.GetSingleDeploySpec(wd); otplConfig != nil {
				name := path.Base(wd.Dir())
				c <- namedDeploySpec{name, otplConfig}
			}
		}()
	}
	deployConfigs := sous.DeploySpecs{}
	for s := range c {
		deployConfigs[s.Name] = *s.Spec
	}
	return deployConfigs
}
示例#3
0
文件: otpl.go 项目: opentable/sous
// GetSingleDeploySpec returns a single sous.DeploySpec from the working
// directory of wd. It assumes that this directory contains at least a file
// called singularity.json, and optionally an additional file called
// singularity-requst.json.
func (dsp *DeploySpecParser) GetSingleDeploySpec(wd shell.Shell) *sous.DeploySpec {
	v := SingularityJSON{}
	if !wd.Exists("singularity.json") {
		dsp.debugf("no singularity.json in %s", wd.Dir())
		return nil
	}
	if err := wd.JSON(&v, "cat", "singularity.json"); err != nil {
		dsp.debugf("error reading %s: %s", path.Join(wd.Dir(),
			"singularity.json"), err)
		return nil
	}
	deploySpec := sous.DeploySpec{
		DeployConfig: sous.DeployConfig{
			Resources: v.Resources.SousResources(),
			Env:       v.Env,
		},
	}
	request := SingularityRequestJSON{}
	if !wd.Exists("singularity-request.json") {
		dsp.debugf("no singularity-request.json in %s", wd.Dir())
		return &deploySpec
	}
	dsp.debugf("%s/singularity-request.json exists, parsing it", wd.Dir())
	if err := wd.JSON(&request, "cat", "singularity-request.json"); err != nil {
		dsp.debugf("error reading singularity-request.json: %s", err)
		return &deploySpec
	}
	deploySpec.NumInstances = request.Instances
	return &deploySpec
}