From ed60e0dabcd105463f9cbd359e42371ee9c5559f Mon Sep 17 00:00:00 2001 From: Charles Julian Knight Date: Mon, 26 Jul 2021 16:57:52 -0400 Subject: [PATCH] add support for bare detached run --- pkg/cli/run.go | 3 +++ pkg/structs/process.go | 1 + provider/aws/processes.go | 30 ++++++++++++++++++++++++------ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/pkg/cli/run.go b/pkg/cli/run.go index 4f94b42339..f2b12e16cd 100644 --- a/pkg/cli/run.go +++ b/pkg/cli/run.go @@ -22,6 +22,7 @@ func init() { flagRack, flagApp, stdcli.BoolFlag("detach", "d", "run process in the background"), + stdcli.BoolFlag("bare", "b", "run the command directly on the instance without running in a shell"), stdcli.IntFlag("timeout", "t", "timeout"), entrypoint, ), @@ -53,6 +54,8 @@ func Run(rack sdk.Interface, c *stdcli.Context) error { timeout = t } + opts.Bare = options.Bool(c.Bool("bare")) + if w, h, err := c.TerminalSize(); err == nil { opts.Height = options.Int(h) opts.Width = options.Int(w) diff --git a/pkg/structs/process.go b/pkg/structs/process.go index 431f5dc470..e97424e351 100644 --- a/pkg/structs/process.go +++ b/pkg/structs/process.go @@ -37,6 +37,7 @@ type ProcessListOptions struct { } type ProcessRunOptions struct { + Bare *bool `header:"Bare" default:"false"` Command *string `header:"Command"` Environment map[string]string `header:"Environment"` Height *int `header:"Height"` diff --git a/provider/aws/processes.go b/provider/aws/processes.go index 5e98fe469d..0935facafe 100644 --- a/provider/aws/processes.go +++ b/provider/aws/processes.go @@ -403,15 +403,33 @@ func (p *Provider) ProcessRun(app, service string, opts structs.ProcessRunOption } if opts.Command != nil { + cmd := []*string{ + aws.String("sh"), + aws.String("-c"), + aws.String(*opts.Command), + } + bare := cb(opts.Bare, false) + var env []*ecs.KeyValuePair + if bare { + args, err := shellquote.Split(*opts.Command) + if err != nil { + return nil, err + } + cmd = make([]*string, len(args)) + for i, a := range args { + cmd[i] = aws.String(a) + } + env = []*ecs.KeyValuePair{ + {Name: aws.String("COMMAND"), Value: aws.String(*opts.Command)}, + } + } + req.Overrides = &ecs.TaskOverride{ ContainerOverrides: []*ecs.ContainerOverride{ { - Name: aws.String(service), - Command: []*string{ - aws.String("sh"), - aws.String("-c"), - aws.String(*opts.Command), - }, + Name: aws.String(service), + Command: cmd, + Environment: env, }, }, }