mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-22 09:14:00 +02:00
Set default home value (#281)
* Set default home value * Apply default home value based on user for run commands * rename default home function
This commit is contained in:
+19
-1
@@ -17,12 +17,14 @@ limitations under the License.
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
||||
"github.com/google/go-containerregistry/pkg/v1"
|
||||
@@ -59,7 +61,7 @@ func (r *RunCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bui
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
replacementEnvs := buildArgs.ReplacementEnvs(config.Env)
|
||||
cmd.Env = replacementEnvs
|
||||
cmd.Env = addDefaultHOME(config.User, replacementEnvs)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
|
||||
// If specified, run the command as a specific user
|
||||
@@ -113,6 +115,22 @@ func (r *RunCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bui
|
||||
return nil
|
||||
}
|
||||
|
||||
// addDefaultHOME adds the default value for HOME if it isn't already set
|
||||
func addDefaultHOME(user string, envs []string) []string {
|
||||
for _, env := range envs {
|
||||
split := strings.SplitN(env, "=", 2)
|
||||
if split[0] == constants.HOME {
|
||||
return envs
|
||||
}
|
||||
}
|
||||
// If user isn't set, set default value of HOME
|
||||
if user == "" {
|
||||
return append(envs, fmt.Sprintf("%s=%s", constants.HOME, constants.DefaultHOMEValue))
|
||||
}
|
||||
// If user is set, set value of HOME to /home/${user}
|
||||
return append(envs, fmt.Sprintf("%s=/home/%s", constants.HOME, user))
|
||||
}
|
||||
|
||||
// FilesToSnapshot returns nil for this command because we don't know which files
|
||||
// have changed, so we snapshot the entire system.
|
||||
func (r *RunCommand) FilesToSnapshot() []string {
|
||||
|
||||
Reference in New Issue
Block a user