From 7a51404b710e800de6b26e3e97c62ce318dc4ab1 Mon Sep 17 00:00:00 2001 From: Carlo Mandelli Date: Wed, 23 Oct 2019 08:23:41 +0200 Subject: [PATCH] run config: add tty option for run steps --- internal/config/config.go | 9 +++- internal/config/config_test.go | 63 ++++++++++++++++++++++++++ internal/runconfig/runconfig.go | 1 + internal/services/executor/executor.go | 2 +- services/runservice/types/types.go | 4 ++ 5 files changed, 77 insertions(+), 2 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 2360d5c..0efc11c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -165,6 +165,7 @@ type RunStep struct { Environment map[string]Value `json:"environment,omitempty"` WorkingDir string `json:"working_dir"` Shell string `json:"shell"` + Tty *bool `json:"tty"` } type SaveToWorkspaceStep struct { @@ -234,6 +235,9 @@ func (s *Steps) UnmarshalJSON(b []byte) error { if err := json.Unmarshal(stepRaw, &s); err != nil { return err } + if s.Tty == nil { + s.Tty = util.BoolP(true) + } s.Type = stepType step = &s @@ -890,7 +894,10 @@ func checkConfig(config *Config) error { } step.Name = step.Command[:len] } - + // if tty is omitted its default is true + if step.Tty == nil { + step.Tty = util.BoolP(true) + } case *SaveCacheStep: for _, content := range step.Contents { if len(content.Paths) == 0 { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index c688ce5..2879e49 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -337,6 +337,23 @@ func TestParseOutput(t *testing.T) { volumes: - path: /mnt/tmpfs tmpfs: {} + - name: task05 + runtime: + type: pod + containers: + - image: image01 + steps: + - type: run + name: command with default tty + command: command01 + - type: run + name: command with tty as true + command: command02 + tty: true + - type: run + name: command with tty as false + command: command03 + tty: false `, out: &Config{ Runs: []*Run{ @@ -388,6 +405,7 @@ func TestParseOutput(t *testing.T) { Name: "command01", }, Command: "command01", + Tty: util.BoolP(true), }, &RunStep{ BaseStep: BaseStep{ @@ -395,6 +413,7 @@ func TestParseOutput(t *testing.T) { Name: "name different than command", }, Command: "command02", + Tty: util.BoolP(true), }, &RunStep{ BaseStep: BaseStep{ @@ -406,6 +425,7 @@ func TestParseOutput(t *testing.T) { "ENV01": Value{Type: ValueTypeString, Value: "ENV01"}, "ENVFROMVARIABLE01": Value{Type: ValueTypeFromVariable, Value: "variable01"}, }, + Tty: util.BoolP(true), }, &SaveCacheStep{ BaseStep: BaseStep{Type: "save_cache"}, @@ -419,6 +439,7 @@ func TestParseOutput(t *testing.T) { Name: "command01", }, Command: "command01", + Tty: util.BoolP(true), }, &RunStep{ BaseStep: BaseStep{ @@ -426,6 +447,7 @@ func TestParseOutput(t *testing.T) { Name: "name different than command", }, Command: "command02", + Tty: util.BoolP(true), }, &RunStep{ BaseStep: BaseStep{ @@ -437,6 +459,7 @@ func TestParseOutput(t *testing.T) { "ENV01": Value{Type: ValueTypeString, Value: "ENV01"}, "ENVFROMVARIABLE01": Value{Type: ValueTypeFromVariable, Value: "variable01"}, }, + Tty: util.BoolP(true), }, &SaveCacheStep{ BaseStep: BaseStep{Type: "save_cache"}, @@ -521,6 +544,46 @@ func TestParseOutput(t *testing.T) { Steps: nil, Depends: nil, }, + &Task{ + Name: "task05", + Runtime: &Runtime{ + Type: "pod", + Arch: "", + Containers: []*Container{ + &Container{ + Image: "image01", + }, + }, + }, + WorkingDir: defaultWorkingDir, + Steps: Steps{ + &RunStep{ + BaseStep: BaseStep{ + Type: "run", + Name: "command with default tty", + }, + Command: "command01", + Tty: util.BoolP(true), + }, + &RunStep{ + BaseStep: BaseStep{ + Type: "run", + Name: "command with tty as true", + }, + Command: "command02", + Tty: util.BoolP(true), + }, + &RunStep{ + BaseStep: BaseStep{ + Type: "run", + Name: "command with tty as false", + }, + Command: "command03", + Tty: util.BoolP(false), + }, + }, + Depends: nil, + }, }, }, }, diff --git a/internal/runconfig/runconfig.go b/internal/runconfig/runconfig.go index f77101a..cb0f103 100644 --- a/internal/runconfig/runconfig.go +++ b/internal/runconfig/runconfig.go @@ -135,6 +135,7 @@ fi rs.Environment = env rs.WorkingDir = cs.WorkingDir rs.Shell = cs.Shell + rs.Tty = cs.Tty return rs case *config.SaveToWorkspaceStep: diff --git a/internal/services/executor/executor.go b/internal/services/executor/executor.go index 1b29d3e..b4517c6 100644 --- a/internal/services/executor/executor.go +++ b/internal/services/executor/executor.go @@ -171,7 +171,7 @@ func (e *Executor) doRunStep(ctx context.Context, s *types.RunStep, t *types.Exe AttachStdin: true, Stdout: outf, Stderr: outf, - Tty: true, + Tty: *s.Tty, } ce, err := pod.Exec(ctx, execConfig) diff --git a/services/runservice/types/types.go b/services/runservice/types/types.go index a3dcf7a..eb0b843 100644 --- a/services/runservice/types/types.go +++ b/services/runservice/types/types.go @@ -415,6 +415,7 @@ type RunStep struct { Environment map[string]string `json:"environment,omitempty"` WorkingDir string `json:"working_dir,omitempty"` Shell string `json:"shell,omitempty"` + Tty *bool `json:"tty,omitempty"` } type SaveContent struct { @@ -582,6 +583,9 @@ func (et *Steps) UnmarshalJSON(b []byte) error { if err := json.Unmarshal(step, &s); err != nil { return err } + if s.Tty == nil { + s.Tty = util.BoolP(true) + } steps[i] = &s case "save_to_workspace": var s SaveToWorkspaceStep