Example #1
0
// parseTemplateConfigs converts the tasks templates into consul-templates
func parseTemplateConfigs(tmpls []*structs.Template, taskDir string, taskEnv *env.TaskEnvironment) map[ctconf.ConfigTemplate]*structs.Template {
	// Build the task environment
	// TODO Should be able to inject the Nomad env vars into Consul-template for
	// rendering
	taskEnv.Build()

	ctmpls := make(map[ctconf.ConfigTemplate]*structs.Template, len(tmpls))
	for _, tmpl := range tmpls {
		var src, dest string
		if tmpl.SourcePath != "" {
			src = filepath.Join(taskDir, taskEnv.ReplaceEnv(tmpl.SourcePath))
		}
		if tmpl.DestPath != "" {
			dest = filepath.Join(taskDir, taskEnv.ReplaceEnv(tmpl.DestPath))
		}

		ct := ctconf.ConfigTemplate{
			Source:           src,
			Destination:      dest,
			EmbeddedTemplate: tmpl.EmbeddedTmpl,
			Perms:            ctconf.DefaultFilePerms,
			Wait:             &watch.Wait{},
		}

		ctmpls[ct] = tmpl
	}

	return ctmpls
}
Example #2
0
// getGetterUrl returns the go-getter URL to download the artifact.
func getGetterUrl(taskEnv *env.TaskEnvironment, artifact *structs.TaskArtifact) (string, error) {
	taskEnv.Build()
	u, err := url.Parse(taskEnv.ReplaceEnv(artifact.GetterSource))
	if err != nil {
		return "", fmt.Errorf("failed to parse source URL %q: %v", artifact.GetterSource, err)
	}

	// Build the url
	q := u.Query()
	for k, v := range artifact.GetterOptions {
		q.Add(k, taskEnv.ReplaceEnv(v))
	}
	u.RawQuery = q.Encode()
	return u.String(), nil
}
Example #3
0
// parseTemplateConfigs converts the tasks templates into consul-templates
func parseTemplateConfigs(tmpls []*structs.Template, taskDir string,
	taskEnv *env.TaskEnvironment, allowAbs bool) (map[ctconf.ConfigTemplate]*structs.Template, error) {
	// Build the task environment
	// TODO Should be able to inject the Nomad env vars into Consul-template for
	// rendering
	taskEnv.Build()

	ctmpls := make(map[ctconf.ConfigTemplate]*structs.Template, len(tmpls))
	for _, tmpl := range tmpls {
		var src, dest string
		if tmpl.SourcePath != "" {
			if filepath.IsAbs(tmpl.SourcePath) {
				if !allowAbs {
					return nil, fmt.Errorf("Specifying absolute template paths disallowed by client config: %q", tmpl.SourcePath)
				}

				src = tmpl.SourcePath
			} else {
				src = filepath.Join(taskDir, taskEnv.ReplaceEnv(tmpl.SourcePath))
			}
		}
		if tmpl.DestPath != "" {
			dest = filepath.Join(taskDir, taskEnv.ReplaceEnv(tmpl.DestPath))
		}

		ct := ctconf.ConfigTemplate{
			Source:           src,
			Destination:      dest,
			EmbeddedTemplate: tmpl.EmbeddedTmpl,
			Perms:            ctconf.DefaultFilePerms,
			Wait:             &watch.Wait{},
		}

		ctmpls[ct] = tmpl
	}

	return ctmpls, nil
}