Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: fix failing unit tests #9

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ type DockerCommand interface {
IsArgsEnvsRequiredInCache() bool
}

func GetCommand(cmd instructions.Command, fileContext util.FileContext, useNewRun bool, cacheCopy bool, cacheRun bool, output *RunOutput) (DockerCommand, error) {
func GetCommand(cmd instructions.Command, fileContext util.FileContext, useNewRun bool, cacheCopy bool, cacheRun bool) (DockerCommand, error) {
switch c := cmd.(type) {
case *instructions.RunCommand:
if useNewRun {
return &RunMarkerCommand{cmd: c, shdCache: cacheRun, output: output}, nil
return &RunMarkerCommand{cmd: c, shdCache: cacheRun}, nil
}
return &RunCommand{cmd: c, shdCache: cacheRun, output: output}, nil
return &RunCommand{cmd: c, shdCache: cacheRun}, nil
case *instructions.CopyCommand:
return &CopyCommand{cmd: c, fileContext: fileContext, shdCache: cacheCopy}, nil
case *instructions.ExposeCommand:
Expand Down
24 changes: 4 additions & 20 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package commands

import (
"fmt"
"io"
"os"
"os/exec"
"strings"
Expand All @@ -34,15 +33,9 @@ import (
"github.com/sirupsen/logrus"
)

type RunOutput struct {
Stdout io.Writer
Stderr io.Writer
}

type RunCommand struct {
BaseCommand
cmd *instructions.RunCommand
output *RunOutput
shdCache bool
}

Expand All @@ -56,19 +49,10 @@ func (r *RunCommand) IsArgsEnvsRequiredInCache() bool {
}

func (r *RunCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.BuildArgs) error {
return runCommandInExec(config, buildArgs, r.cmd, r.output)
return runCommandInExec(config, buildArgs, r.cmd)
}

func runCommandInExec(config *v1.Config, buildArgs *dockerfile.BuildArgs, cmdRun *instructions.RunCommand, output *RunOutput) error {
if output == nil {
output = &RunOutput{}
}
if output.Stdout == nil {
output.Stdout = os.Stdout
}
if output.Stderr == nil {
output.Stderr = os.Stderr
}
func runCommandInExec(config *v1.Config, buildArgs *dockerfile.BuildArgs, cmdRun *instructions.RunCommand) error {
var newCommand []string
if cmdRun.PrependShell {
// This is the default shell on Linux
Expand Down Expand Up @@ -105,8 +89,8 @@ func runCommandInExec(config *v1.Config, buildArgs *dockerfile.BuildArgs, cmdRun
cmd := exec.Command(newCommand[0], newCommand[1:]...)

cmd.Dir = setWorkDirIfExists(config.WorkingDir)
cmd.Stdout = output.Stdout
cmd.Stderr = output.Stderr
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
replacementEnvs := buildArgs.ReplacementEnvs(config.Env)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}

Expand Down
3 changes: 1 addition & 2 deletions pkg/commands/run_marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
type RunMarkerCommand struct {
BaseCommand
cmd *instructions.RunCommand
output *RunOutput
Files []string
shdCache bool
}
Expand All @@ -38,7 +37,7 @@ func (r *RunMarkerCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfi
// run command `touch filemarker`
logrus.Debugf("Using new RunMarker command")
prevFilesMap, _ := util.GetFSInfoMap("/", map[string]os.FileInfo{})
if err := runCommandInExec(config, buildArgs, r.cmd, r.output); err != nil {
if err := runCommandInExec(config, buildArgs, r.cmd); err != nil {
return err
}
_, r.Files = util.GetFSInfoMap("/", prevFilesMap)
Expand Down
3 changes: 0 additions & 3 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package config
import (
"errors"
"fmt"
"io"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -88,8 +87,6 @@ type KanikoOptions struct {
IgnoreVarRun bool
SkipUnusedStages bool
RunV2 bool
RunStdout io.Writer
RunStderr io.Writer
CacheCopyLayers bool
CacheRunLayers bool
ForceBuildMetadata bool
Expand Down
5 changes: 1 addition & 4 deletions pkg/executor/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ func newStageBuilder(args *dockerfile.BuildArgs, opts *config.KanikoOptions, sta
}

for _, cmd := range s.stage.Commands {
command, err := commands.GetCommand(cmd, fileContext, opts.RunV2, opts.CacheCopyLayers, opts.CacheRunLayers, &commands.RunOutput{
Stdout: opts.RunStdout,
Stderr: opts.RunStderr,
})
command, err := commands.GetCommand(cmd, fileContext, opts.RunV2, opts.CacheCopyLayers, opts.CacheRunLayers)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/command_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ Loop:

func GetUserGroup(chownStr string, env []string) (int64, int64, error) {
if chownStr == "" {
return 0, 0, nil
return DoNotChangeUID, DoNotChangeGID, nil
}

chown, err := ResolveEnvironmentReplacement(chownStr, env, false)
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/command_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ func TestGetUserGroup(t *testing.T) {
mockIDGetter: func(string, string) (uint32, uint32, error) {
return 0, 0, fmt.Errorf("should not be called")
},
expectedU: 0,
expectedG: 0,
expectedU: -1,
expectedG: -1,
},
}
for _, tc := range tests {
Expand Down