diff --git a/commands/marathon/deploy_cmds.go b/commands/marathon/deploy_cmds.go index ecb699f..37fd58b 100644 --- a/commands/marathon/deploy_cmds.go +++ b/commands/marathon/deploy_cmds.go @@ -78,6 +78,7 @@ the other for delegation to the origin (app or group) func init() { + deployCreateCmd.Flags().BoolP(WAIT_FLAG, "w", false, "Wait for group to become healthy") deployCreateCmd.Flags().String(TEMPLATE_CTX_FLAG, "", "Provides data per environment in JSON form to do a first pass parse of descriptor as template") deployCreateCmd.Flags().BoolP(FORCE_FLAG, "f", false, "Force deployment (updates application if it already exists)") deployCreateCmd.Flags().Bool(STOP_DEPLOYS_FLAG, false, "Stop an existing deployment for this app (if exists) and use this revision") @@ -110,7 +111,6 @@ func deployAppOrGroup(cmd *cobra.Command, args []string) { options := &marathon.CreateOptions{Wait: wait, Force: force, ErrorOnMissingParams: !ignore, StopDeploy: stop_deploy} descriptor := parseDescriptor(tempctx, filename) - et, err := encoding.NewEncoderFromFileExt(filename) if err != nil { exitWithError(err) diff --git a/commands/marathon/templatectx.go b/commands/marathon/templatectx.go index 33cf601..ee1838f 100644 --- a/commands/marathon/templatectx.go +++ b/commands/marathon/templatectx.go @@ -9,6 +9,8 @@ import ( "github.com/ContainX/depcon/pkg/encoding" "github.com/spf13/viper" + "strings" + "path/filepath" ) const ( @@ -43,6 +45,13 @@ var Funcs = template.FuncMap{ return value }, + "isEnv": func(value string) bool { + if len(value) > 0 { + current := strings.ToLower(viper.GetString(ENV_NAME)) + return current == strings.ToLower(value) + } + return false + }, } type TemplateContext struct { @@ -60,13 +69,21 @@ func (ctx *TemplateContext) Transform(writer io.Writer, descriptor string) error return err } else { var e error - t = template.New("output").Funcs(Funcs) + t = template.New(descriptor).Funcs(Funcs) t, e = t.Parse(string(b)) if e != nil { return e } + if matches, err := filepath.Glob("./**/*.tmpl"); err == nil && len(matches) > 0 { + if t, e = t.ParseFiles(matches...); err != nil { + return err + } + } } - if err := t.Execute(writer, ctx.mergeAppWithDefault(string(viper.GetString(ENV_NAME)))); err != nil { + environment := viper.GetString(ENV_NAME) + m := ctx.mergeAppWithDefault(environment) + + if err := t.Execute(writer, m); err != nil { return err } return nil