Commit bd7d53c8 authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Added PTY to shell

parent 9c8a7cc0
......@@ -48,6 +48,7 @@ type RunnerConfig struct {
Shell string `toml:"shell" json:"shell"`
DisableVerbose bool `toml:"disable_verbose" json:"disable_verbose"`
DisablePTY *bool `toml:"disable_pty" json:"disable_pty"`
SSH *ssh.Config `toml:"ssh" json:"ssh"`
Docker *DockerConfig `toml:"docker" json:"docker"`
......@@ -72,6 +73,10 @@ func (c *RunnerConfig) UniqueID() string {
return c.URL + c.Token
}
func (c *RunnerConfig) IsPTYEnabled() bool {
return c.DisablePTY == nil || !*c.DisablePTY
}
func (c *Config) LoadConfig(configFile string) error {
info, err := os.Stat(configFile)
if err != nil {
......
......@@ -8,15 +8,19 @@ import (
"os/exec"
"path/filepath"
krpty "github.com/kr/pty"
"github.com/ayufan/gitlab-ci-multi-runner/common"
"github.com/ayufan/gitlab-ci-multi-runner/executors"
"github.com/ayufan/gitlab-ci-multi-runner/helpers"
"io"
)
type ShellExecutor struct {
executors.AbstractExecutor
cmd *exec.Cmd
scriptDir string
pty *os.File
}
func (s *ShellExecutor) Prepare(config *common.RunnerConfig, build *common.Build) error {
......@@ -51,6 +55,21 @@ func (s *ShellExecutor) Start() error {
s.cmd.Stdout = s.BuildLog
s.cmd.Stderr = s.BuildLog
// Open PTY if available
if s.Config.IsPTYEnabled() {
pty, tty, err := krpty.Open()
if err == nil {
go io.Copy(s.BuildLog, pty)
defer tty.Close()
s.cmd.Stdout = tty
s.cmd.Stderr = tty
s.pty = pty
} else if err != krpty.ErrUnsupported {
s.Errorln("Failed to open pty", err)
}
}
// Save shell script as file
if s.ShellScript.PassFile {
scriptDir, err := ioutil.TempDir("", "build_script")
if err != nil {
......@@ -89,6 +108,10 @@ func (s *ShellExecutor) Cleanup() {
os.RemoveAll(s.scriptDir)
}
if s.pty != nil {
s.pty.Close()
}
s.AbstractExecutor.Cleanup()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment