Set env at command run time instead of in the process. (#91)

This commit is contained in:
dlorenc 2018-04-15 18:05:21 -07:00 committed by GitHub
parent 2ff7a6556a
commit 0438539cbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 9 deletions

View File

@ -17,12 +17,12 @@ limitations under the License.
package commands
import (
"strings"
"github.com/GoogleCloudPlatform/kaniko/pkg/util"
"github.com/containers/image/manifest"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/sirupsen/logrus"
"os"
"strings"
)
type EnvCommand struct {
@ -45,10 +45,6 @@ func (e *EnvCommand) ExecuteCommand(config *manifest.Schema2Config) error {
Key: expandedKey,
Value: expandedValue,
}
logrus.Infof("Setting environment variable %s=%s", pair.Key, expandedValue)
if err := os.Setenv(pair.Key, expandedValue); err != nil {
return err
}
}
return updateConfigEnv(newEnvs, config)
}

View File

@ -17,14 +17,15 @@ limitations under the License.
package commands
import (
"github.com/containers/image/manifest"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/sirupsen/logrus"
"os"
"os/exec"
"strconv"
"strings"
"syscall"
"github.com/containers/image/manifest"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/sirupsen/logrus"
)
type RunCommand struct {
@ -48,6 +49,8 @@ func (r *RunCommand) ExecuteCommand(config *manifest.Schema2Config) error {
cmd := exec.Command(newCommand[0], newCommand[1:]...)
cmd.Dir = config.WorkingDir
cmd.Stdout = os.Stdout
cmd.Env = config.Env
// If specified, run the command as a specific user
if config.User != "" {
userAndGroup := strings.Split(config.User, ":")