diff --git a/Makefile b/Makefile index 5fa9242..b881514 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = 0.8.9 +VERSION = 0.9.0 GO_FMT = gofmt -s -w -l . GO_XC = goxc -os="linux darwin windows" -tasks-="rmbin" diff --git a/commands/marathon/app_cmds.go b/commands/marathon/app_cmds.go index d7774a8..b896277 100644 --- a/commands/marathon/app_cmds.go +++ b/commands/marathon/app_cmds.go @@ -21,6 +21,7 @@ const ( SCALE_FLAG = "scale" FORMAT_FLAG = "format" TEMPLATE_CTX_FLAG = "tempctx" + DEFAULT_CTX = "template-context.json" STOP_DEPLOYS_FLAG = "stop-deploys" ) @@ -179,7 +180,7 @@ func createApp(cmd *cobra.Command, args []string) { var result *marathon.Application = nil var e error - if len(tempctx) > 0 { + if TemplateExists(tempctx) { b := &bytes.Buffer{} r, err := LoadTemplateContext(tempctx) diff --git a/commands/marathon/deploy_cmds.go b/commands/marathon/deploy_cmds.go index 37fd58b..4f0099d 100644 --- a/commands/marathon/deploy_cmds.go +++ b/commands/marathon/deploy_cmds.go @@ -11,6 +11,7 @@ import ( "io/ioutil" "os" "strings" + "time" ) var deployCmd = &cobra.Command{ @@ -79,7 +80,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().String(TEMPLATE_CTX_FLAG, DEFAULT_CTX, "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") deployCreateCmd.Flags().BoolP(IGNORE_MISSING, "i", false, `Ignore missing ${PARAMS} that are declared in app config that could not be resolved @@ -90,6 +91,7 @@ func init() { eg. -p MYVAR=value would replace ${MYVAR} with "value" in the application file. These take precidence over env vars`) + deployCreateCmd.Flags().DurationP(TIMEOUT_FLAG, "t", time.Duration(0), "Max duration to wait for application health (ex. 90s | 2m). See docs for ordering") deployDeleteCmd.Flags().BoolP(FORCE_FLAG, "f", false, "If set to true, then the deployment is still canceled but no rollback deployment is created.") deployCmd.AddCommand(deployCreateCmd, deployListCmd, deployDeleteCmd, deleteIfDeployingCmd) } @@ -137,6 +139,8 @@ func deployAppOrGroup(cmd *cobra.Command, args []string) { } } + log.Debug("Composed Descriptor: %s", descriptor) + if ag.IsApplication() { result, e := client(cmd).CreateApplicationFromString(filename, descriptor, options) outputDeployment(result, e) @@ -144,6 +148,11 @@ func deployAppOrGroup(cmd *cobra.Command, args []string) { } else { result, e := client(cmd).CreateGroupFromString(filename, descriptor, options) outputDeployment(result, e) + + if e != nil { + cli.Output(nil, e) + } + arr := flattenGroup(result, []*marathon.Group{}) cli.Output(templateFor(T_GROUPS, arr), e) } @@ -163,7 +172,7 @@ func outputDeployment(result interface{}, e error) { } func parseDescriptor(tempctx, filename string) string { - if len(tempctx) > 0 { + if TemplateExists(tempctx) { b := &bytes.Buffer{} r, err := LoadTemplateContext(tempctx) diff --git a/commands/marathon/group_cmds.go b/commands/marathon/group_cmds.go index 48a03f7..0d4f0eb 100644 --- a/commands/marathon/group_cmds.go +++ b/commands/marathon/group_cmds.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "os" "strings" + "time" ) var groupCmd = &cobra.Command{ @@ -55,10 +56,12 @@ func init() { // Destroy Flags groupDestroyCmd.Flags().BoolP(WAIT_FLAG, "w", false, "Wait for destroy to complete") // Create Flags - groupCreateCmd.Flags().String(TEMPLATE_CTX_FLAG, "", "Provides data per environment in JSON form to do a first pass parse of descriptor as template") + groupCreateCmd.Flags().String(TEMPLATE_CTX_FLAG, DEFAULT_CTX, "Provides data per environment in JSON form to do a first pass parse of descriptor as template") groupCreateCmd.Flags().BoolP(WAIT_FLAG, "w", false, "Wait for group to become healthy") groupCreateCmd.Flags().Bool(STOP_DEPLOYS_FLAG, false, "Stop an existing deployment for this group (if exists) and use this revision") groupCreateCmd.Flags().BoolP(FORCE_FLAG, "f", false, "Force deployment (updates group if it already exists)") + groupCreateCmd.Flags().DurationP(TIMEOUT_FLAG, "t", time.Duration(0), "Max duration to wait for application health (ex. 90s | 2m). See docs for ordering") + groupCreateCmd.Flags().BoolP(IGNORE_MISSING, "i", false, `Ignore missing ${PARAMS} that are declared in app config that could not be resolved CAUTION: This can be dangerous if some params define versions or other required information.`) groupCreateCmd.Flags().StringSliceP(PARAMS_FLAG, "p", nil, `Adds a param(s) that can be used for substitution. @@ -124,7 +127,7 @@ func createGroup(cmd *cobra.Command, args []string) { var result *marathon.Group = nil var e error - if len(tempctx) > 0 { + if TemplateExists(tempctx) { b := &bytes.Buffer{} r, err := LoadTemplateContext(tempctx) diff --git a/commands/marathon/templatectx.go b/commands/marathon/templatectx.go index ee1838f..b3fbb10 100644 --- a/commands/marathon/templatectx.go +++ b/commands/marathon/templatectx.go @@ -9,8 +9,8 @@ import ( "github.com/ContainX/depcon/pkg/encoding" "github.com/spf13/viper" - "strings" "path/filepath" + "strings" ) const ( @@ -132,6 +132,16 @@ func recovery() { recover() } +func TemplateExists(filename string) bool { + + if len(filename) > 0 { + if _, err := os.Stat(filename); err == nil { + return true + } + } + return false +} + func LoadTemplateContext(filename string) (*TemplateContext, error) { ctx, err := os.Open(filename) if err != nil { diff --git a/marathon/application.go b/marathon/application.go index 0b91d16..41b7b0d 100644 --- a/marathon/application.go +++ b/marathon/application.go @@ -180,6 +180,9 @@ func (c *MarathonClient) ListApplicationsWithFilters(filter string) (*Applicatio url := c.marathonUrl(API_APPS) if len(filter) > 0 { + if strings.Contains(filter, "=") == false { + filter = fmt.Sprintf("id=%s", filter) + } url = fmt.Sprintf("%s?%s", url, filter) } resp := c.http.HttpGet(url, apps)