From 89ce61694af29252977036a995103dd68139fb7a Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 15 May 2024 21:57:52 +0100 Subject: [PATCH 1/3] Revert "Set default UserId and GroupId to 0:0" This reverts commit 6431577896f1b557401c9a1fb1926398bad238b7. --- pkg/util/command_util.go | 2 +- pkg/util/command_util_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/util/command_util.go b/pkg/util/command_util.go index 9b896c8adf..8c4af2272c 100644 --- a/pkg/util/command_util.go +++ b/pkg/util/command_util.go @@ -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) diff --git a/pkg/util/command_util_test.go b/pkg/util/command_util_test.go index a6d9ea7a7c..180bff4c43 100644 --- a/pkg/util/command_util_test.go +++ b/pkg/util/command_util_test.go @@ -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 { From dd71412df984fc209e7d96bf3d254aef2eaec27a Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 15 May 2024 22:18:04 +0100 Subject: [PATCH 2/3] Revert "feat: add options for capturing run output" This reverts commit 30ddbe50d716d5c86ad7a558ecc4fbee2c0d76f7. --- pkg/commands/commands.go | 6 +++--- pkg/commands/run.go | 24 ++++-------------------- pkg/config/options.go | 3 --- pkg/executor/build.go | 5 +---- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/pkg/commands/commands.go b/pkg/commands/commands.go index 6215f58696..ae1510510f 100644 --- a/pkg/commands/commands.go +++ b/pkg/commands/commands.go @@ -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: diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 3f3e82a906..f9acc4029b 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -18,7 +18,6 @@ package commands import ( "fmt" - "io" "os" "os/exec" "strings" @@ -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 } @@ -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 @@ -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} diff --git a/pkg/config/options.go b/pkg/config/options.go index 6f3b67a197..a1d7686405 100644 --- a/pkg/config/options.go +++ b/pkg/config/options.go @@ -19,7 +19,6 @@ package config import ( "errors" "fmt" - "io" "strconv" "strings" "time" @@ -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 diff --git a/pkg/executor/build.go b/pkg/executor/build.go index d163af6831..3d1b1ad2d9 100644 --- a/pkg/executor/build.go +++ b/pkg/executor/build.go @@ -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 } From c077f27d272be683f4387bfa53316f530251bb88 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 15 May 2024 22:19:54 +0100 Subject: [PATCH 3/3] Revert "Fix compilation error in RunMarker" This reverts commit f9ad3d51d41746429e63a0fd6c5985724ce822f5. --- pkg/commands/run_marker.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/commands/run_marker.go b/pkg/commands/run_marker.go index 352ed94544..1e37a58aea 100644 --- a/pkg/commands/run_marker.go +++ b/pkg/commands/run_marker.go @@ -29,7 +29,6 @@ import ( type RunMarkerCommand struct { BaseCommand cmd *instructions.RunCommand - output *RunOutput Files []string shdCache bool } @@ -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)