From d4b54cbbcac97db727d8c8fa613b81a8180efbe1 Mon Sep 17 00:00:00 2001 From: peter-evans Date: Thu, 18 Oct 2018 17:46:43 +0900 Subject: [PATCH 1/3] Add test for setting root user explicitly --- pkg/commands/run_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/commands/run_test.go b/pkg/commands/run_test.go index fd3afb591..8609ac67e 100644 --- a/pkg/commands/run_test.go +++ b/pkg/commands/run_test.go @@ -62,6 +62,17 @@ func Test_addDefaultHOME(t *testing.T) { "HOME=/", }, }, + { + name: "HOME isn't set, user is set to root", + user: "root", + initial: []string{ + "PATH=/something/else", + }, + expected: []string{ + "PATH=/something/else", + "HOME=/root", + }, + }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { From 49b2fa5199034ee554c409b3014aa3a33ca9a9a5 Mon Sep 17 00:00:00 2001 From: peter-evans Date: Thu, 18 Oct 2018 17:59:07 +0900 Subject: [PATCH 2/3] Set root user to default home --- pkg/commands/run.go | 2 +- pkg/constants/constants.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index dba619680..d8957786c 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -127,7 +127,7 @@ func addDefaultHOME(u string, envs []string) []string { } // If user isn't set, set default value of HOME - if u == "" { + if u == "" || u == constants.RootUser { return append(envs, fmt.Sprintf("%s=%s", constants.HOME, constants.DefaultHOMEValue)) } diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index d8fcc722e..c3a4ac909 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -58,6 +58,7 @@ const ( HOME = "HOME" // DefaultHOMEValue is the default value Docker sets for $HOME DefaultHOMEValue = "/root" + RootUser = "root" // Docker command names Cmd = "cmd" From 39d6dc1ce736e76c54c185cdc1ec78525023f1ca Mon Sep 17 00:00:00 2001 From: peter-evans Date: Thu, 18 Oct 2018 18:08:34 +0900 Subject: [PATCH 3/3] Modify integration test for setting root user explicitly --- integration/dockerfiles/Dockerfile_test_user_run | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration/dockerfiles/Dockerfile_test_user_run b/integration/dockerfiles/Dockerfile_test_user_run index bdad4f4b9..3732e625b 100644 --- a/integration/dockerfiles/Dockerfile_test_user_run +++ b/integration/dockerfiles/Dockerfile_test_user_run @@ -21,6 +21,8 @@ USER testuser:1001 RUN echo "hey2" >> /tmp/foo USER root +RUN echo "hi" > $HOME/file +COPY context/foo $HOME/foo RUN useradd -ms /bin/bash newuser USER newuser