Skip to content

Commit

Permalink
Merge pull request #149 from camandel/add_tty_option
Browse files Browse the repository at this point in the history
run config: add tty option for run steps
  • Loading branch information
sgotti authored Oct 29, 2019
2 parents 0558e78 + 7a51404 commit ec67b26
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
9 changes: 8 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
63 changes: 63 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -388,13 +405,15 @@ func TestParseOutput(t *testing.T) {
Name: "command01",
},
Command: "command01",
Tty: util.BoolP(true),
},
&RunStep{
BaseStep: BaseStep{
Type: "run",
Name: "name different than command",
},
Command: "command02",
Tty: util.BoolP(true),
},
&RunStep{
BaseStep: BaseStep{
Expand All @@ -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"},
Expand All @@ -419,13 +439,15 @@ func TestParseOutput(t *testing.T) {
Name: "command01",
},
Command: "command01",
Tty: util.BoolP(true),
},
&RunStep{
BaseStep: BaseStep{
Type: "run",
Name: "name different than command",
},
Command: "command02",
Tty: util.BoolP(true),
},
&RunStep{
BaseStep: BaseStep{
Expand All @@ -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"},
Expand Down Expand Up @@ -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,
},
},
},
},
Expand Down
1 change: 1 addition & 0 deletions internal/runconfig/runconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion internal/services/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions services/runservice/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ec67b26

Please sign in to comment.