func (c *MarathonClient) parseApplicationFromFile(filename string, opts *CreateOptions) (*Application, *CreateOptions, error) { log.Info("Creating Application from file: %s", filename) options := initCreateOptions(opts) file, err := os.Open(filename) if err != nil { return nil, nil, fmt.Errorf("Error opening filename %s, %s", filename, err.Error()) } var encoder encoding.Encoder encoder, err = encoding.NewEncoderFromFileExt(filename) if err != nil { return nil, nil, err } parsed, missing := envsubst.SubstFileTokens(file, filename, options.EnvParams) if options.ErrorOnMissingParams && missing { return nil, nil, ErrorAppParamsMissing } app := new(Application) err = encoder.UnMarshalStr(parsed, &app) if err != nil { return nil, nil, err } return app, options, nil }
func (c *MarathonClient) CreateGroupFromFile(filename string, opts *CreateOptions) (*Group, error) { log.Info("Creating Group from file: %s", filename) options := initCreateOptions(opts) file, err := os.Open(filename) if err != nil { return nil, fmt.Errorf("Error opening filename %s, %s", filename, err.Error()) } var encoder encoding.Encoder encoder, err = encoding.NewEncoderFromFileExt(filename) if err != nil { return nil, err } parsed, missing := envsubst.SubstFileTokens(file, filename, options.EnvParams) if options.ErrorOnMissingParams && missing { return nil, ErrorAppParamsMissing } group := new(Group) err = encoder.UnMarshalStr(parsed, &group) if err != nil { return nil, err } return c.CreateGroup(group, options.Wait, options.Force) }
func (c *ComposeWrapper) createDockerContext() (*project.Project, error) { clientFactory, err := docker.NewDefaultClientFactory(docker.ClientOpts{}) if err != nil { log.Fatal(err) } tlsVerify := os.Getenv(DOCKER_TLS_VERIFY) if tlsVerify == "1" { clientFactory, err = docker.NewDefaultClientFactory(docker.ClientOpts{ TLS: true, TLSVerify: true, }) if err != nil { log.Fatal(err) } } 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.ComposeFile, 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(&docker.Context{ Context: project.Context{ ComposeFile: c.context.ComposeFile, ProjectName: c.context.ProjectName, }, ClientFactory: clientFactory, }) }