Set env at command run time instead of in the process. (#91)
This commit is contained in:
parent
2ff7a6556a
commit
0438539cbc
|
|
@ -17,12 +17,12 @@ limitations under the License.
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kaniko/pkg/util"
|
"github.com/GoogleCloudPlatform/kaniko/pkg/util"
|
||||||
"github.com/containers/image/manifest"
|
"github.com/containers/image/manifest"
|
||||||
"github.com/docker/docker/builder/dockerfile/instructions"
|
"github.com/docker/docker/builder/dockerfile/instructions"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type EnvCommand struct {
|
type EnvCommand struct {
|
||||||
|
|
@ -45,10 +45,6 @@ func (e *EnvCommand) ExecuteCommand(config *manifest.Schema2Config) error {
|
||||||
Key: expandedKey,
|
Key: expandedKey,
|
||||||
Value: expandedValue,
|
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)
|
return updateConfigEnv(newEnvs, config)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,15 @@ limitations under the License.
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containers/image/manifest"
|
|
||||||
"github.com/docker/docker/builder/dockerfile/instructions"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/containers/image/manifest"
|
||||||
|
"github.com/docker/docker/builder/dockerfile/instructions"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RunCommand struct {
|
type RunCommand struct {
|
||||||
|
|
@ -48,6 +49,8 @@ func (r *RunCommand) ExecuteCommand(config *manifest.Schema2Config) error {
|
||||||
cmd := exec.Command(newCommand[0], newCommand[1:]...)
|
cmd := exec.Command(newCommand[0], newCommand[1:]...)
|
||||||
cmd.Dir = config.WorkingDir
|
cmd.Dir = config.WorkingDir
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Env = config.Env
|
||||||
|
|
||||||
// If specified, run the command as a specific user
|
// If specified, run the command as a specific user
|
||||||
if config.User != "" {
|
if config.User != "" {
|
||||||
userAndGroup := strings.Split(config.User, ":")
|
userAndGroup := strings.Split(config.User, ":")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue