adding support of env variable replacement

This commit is contained in:
sharifelgamal
2018-03-30 10:13:35 -07:00
parent 7ae8f35eb9
commit da0231a4d1
2 changed files with 25 additions and 3 deletions
+9 -2
View File
@@ -17,6 +17,7 @@ limitations under the License.
package commands
import (
"github.com/GoogleCloudPlatform/k8s-container-builder/pkg/util"
"github.com/containers/image/manifest"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/sirupsen/logrus"
@@ -32,10 +33,16 @@ func (r *UserCommand) ExecuteCommand(config *manifest.Schema2Config) error {
logrus.Info("cmd: USER")
u := r.cmd.User
userAndGroup := strings.Split(u, ":")
userStr := userAndGroup[0]
userStr, err := util.ResolveEnvironmentReplacement(userAndGroup[0], config.Env, false)
if err != nil {
return err
}
var groupStr string
if len(userAndGroup) > 1 {
groupStr = userAndGroup[1]
groupStr, err = util.ResolveEnvironmentReplacement(userAndGroup[1], config.Env, false)
if err != nil {
return err
}
}
// Lookup by username
+16 -1
View File
@@ -67,11 +67,26 @@ var userTests = []struct {
expectedUid: "",
shouldError: true,
},
{
user: "$envuser",
expectedUid: "0",
shouldError: false,
},
{
user: "root:$envgroup",
expectedUid: "0:0",
shouldError: false,
},
}
func TestUpdateUser(t *testing.T) {
for _, test := range userTests {
cfg := &manifest.Schema2Config{}
cfg := &manifest.Schema2Config{
Env: []string{
"envuser=root",
"envgroup=root",
},
}
cmd := UserCommand{
&instructions.UserCommand{
User: test.user,