Commit f0ce49ee authored by Kamil Trzciński's avatar Kamil Trzciński

Introduce shell type

- use NormalShell only when executing builds in docker container - it allows to preserve all environment variables set in Dockerfile
- use LoginShell in all other cases
parent 84a48e86
......@@ -15,6 +15,13 @@ type ShellScript struct {
Extension string
}
type ShellType int
const (
NormalShell ShellType = iota
LoginShell
)
func (s *ShellScript) GetCommandWithArguments() []string {
parts := []string{s.Command}
for _, arg := range s.Arguments {
......@@ -33,7 +40,7 @@ func (s *ShellScript) GetFullCommand() string {
type Shell interface {
GetName() string
GenerateScript(build *Build) (*ShellScript, error)
GenerateScript(build *Build, shellType ShellType) (*ShellScript, error)
IsDefault() bool
}
......@@ -69,13 +76,13 @@ func GetShells() []string {
return names
}
func GenerateShellScript(name string, build *Build) (*ShellScript, error) {
func GenerateShellScript(name string, build *Build, shellType ShellType) (*ShellScript, error) {
shell := GetShell(name)
if shell == nil {
return nil, fmt.Errorf("shell %s not found", name)
}
return shell.GenerateScript(build)
return shell.GenerateScript(build, shellType)
}
func GetDefaultShell() string {
......
......@@ -70,6 +70,7 @@ func init() {
DefaultBuildsDir: "/builds",
SharedBuildsDir: false,
DefaultShell: "bash",
ShellType: common.NormalShell,
ShowHostname: true,
},
},
......
......@@ -72,6 +72,7 @@ func init() {
DefaultBuildsDir: "builds",
SharedBuildsDir: false,
DefaultShell: "bash",
ShellType: common.LoginShell,
ShowHostname: true,
},
},
......
......@@ -17,6 +17,7 @@ type AbstractExecutor struct {
DefaultBuildsDir string
SharedBuildsDir bool
DefaultShell string
ShellType common.ShellType
ShowHostname bool
Config *common.RunnerConfig
Build *common.Build
......@@ -123,7 +124,7 @@ func (e *AbstractExecutor) Errorln(args ...interface{}) {
func (e *AbstractExecutor) generateShellScript() error {
shell := helpers.StringOrDefault(e.Config.Shell, e.DefaultShell)
shellScript, err := common.GenerateShellScript(shell, e.Build)
shellScript, err := common.GenerateShellScript(shell, e.Build, e.ShellType)
if err != nil {
return err
}
......
......@@ -316,6 +316,7 @@ func init() {
DefaultBuildsDir: "tmp/builds",
SharedBuildsDir: false,
DefaultShell: "bash",
ShellType: common.LoginShell,
ShowHostname: true,
},
}
......
......@@ -95,6 +95,7 @@ func init() {
DefaultBuildsDir: "tmp/builds",
SharedBuildsDir: true,
DefaultShell: common.GetDefaultShell(),
ShellType: common.LoginShell,
ShowHostname: false,
},
}
......
......@@ -70,6 +70,7 @@ func init() {
DefaultBuildsDir: "builds",
SharedBuildsDir: true,
DefaultShell: "bash",
ShellType: common.LoginShell,
ShowHostname: true,
},
}
......
......@@ -44,7 +44,7 @@ func (b *BashShell) writeCheckoutCmd(w io.Writer, build *common.Build) {
io.WriteString(w, fmt.Sprintf("git checkout -qf %s\n", build.Sha))
}
func (b *BashShell) GenerateScript(build *common.Build) (*common.ShellScript, error) {
func (b *BashShell) GenerateScript(build *common.Build, shellType common.ShellType) (*common.ShellScript, error) {
var buffer bytes.Buffer
w := bufio.NewWriter(&buffer)
......@@ -98,8 +98,12 @@ func (b *BashShell) GenerateScript(build *common.Build) (*common.ShellScript, er
Environment: env,
Script: buffer.Bytes(),
Command: "bash",
Arguments: []string{"--login"},
}
if shellType == common.LoginShell {
script.Arguments = []string{"--login"}
}
return &script, nil
}
......
......@@ -55,7 +55,7 @@ func (b *CmdShell) writeCheckoutCmd(w io.Writer, build *common.Build) {
b.writeCommandChecked(w, "git checkout -qf \"%s\"", build.RefName, build.Sha)
}
func (b *CmdShell) GenerateScript(build *common.Build) (*common.ShellScript, error) {
func (b *CmdShell) GenerateScript(build *common.Build, shellType common.ShellType) (*common.ShellScript, error) {
var buffer bytes.Buffer
w := bufio.NewWriter(&buffer)
......
......@@ -53,7 +53,7 @@ func (b *PowerShell) writeCheckoutCmd(w io.Writer, build *common.Build) {
b.writeCommandChecked(w, "git checkout -qf \"%s\"", build.Sha)
}
func (b *PowerShell) GenerateScript(build *common.Build) (*common.ShellScript, error) {
func (b *PowerShell) GenerateScript(build *common.Build, shellType common.ShellType) (*common.ShellScript, error) {
var buffer bytes.Buffer
w := bufio.NewWriter(&buffer)
......
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