Example #1
0
func (c *MarathonClient) ParseGroupFromString(r io.Reader, et encoding.EncoderType, opts *CreateOptions) (*Group, error) {

	options := initCreateOptions(opts)

	var encoder encoding.Encoder
	var err error

	encoder, err = encoding.NewEncoder(et)
	if err != nil {
		return nil, err
	}

	parsed, missing := envsubst.SubstFileTokens(r, options.EnvParams)

	if opts.ErrorOnMissingParams && missing {
		return nil, ErrorAppParamsMissing
	}

	if opts.DryRun {
		fmt.Printf("Create Group :: DryRun :: Template Output\n\n%s", parsed)
		os.Exit(0)
	}

	group := new(Group)
	err = encoder.UnMarshalStr(parsed, &group)
	if err != nil {
		return nil, err
	}
	return group, nil
}
Example #2
0
func (c *ComposeWrapper) createDockerContext() (project.APIProject, error) {

	if c.context.EnvParams != nil && len(c.context.EnvParams) > 0 {
		file, err := os.Open(c.context.ComposeFile)
		if err != nil {
			return nil, fmt.Errorf("Error opening filename %s, %s", c.context.ComposeFile, err.Error())
		}
		parsed, missing := envsubst.SubstFileTokens(file, c.context.EnvParams)
		log.Debug("Map: %v\nParsed: %s\n", c.context.EnvParams, parsed)

		if c.context.ErrorOnMissingParams && missing {
			return nil, ErrorParamsMissing
		}
		file, err = ioutil.TempFile("", "depcon")
		if err != nil {
			return nil, err
		}
		err = ioutil.WriteFile(file.Name(), []byte(parsed), os.ModeTemporary)
		if err != nil {
			return nil, err
		}
		c.context.ComposeFile = file.Name()
	}
	return docker.NewProject(&ctx.Context{
		Context: project.Context{
			ComposeFiles: strings.Split(c.context.ComposeFile, ","),
			ProjectName:  c.context.ProjectName,
		},
	}, nil)
}