Merge pull request #412 from mrunalp/image_wd_env
Apply working dir and env from image config
This commit is contained in:
commit
7c6443c592
1 changed files with 34 additions and 18 deletions
|
@ -242,24 +242,6 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
// creates a spec Generator with the default spec.
|
// creates a spec Generator with the default spec.
|
||||||
specgen := generate.New()
|
specgen := generate.New()
|
||||||
|
|
||||||
cwd := containerConfig.WorkingDir
|
|
||||||
if cwd == "" {
|
|
||||||
cwd = "/"
|
|
||||||
}
|
|
||||||
specgen.SetProcessCwd(cwd)
|
|
||||||
|
|
||||||
envs := containerConfig.GetEnvs()
|
|
||||||
if envs != nil {
|
|
||||||
for _, item := range envs {
|
|
||||||
key := item.Key
|
|
||||||
value := item.Value
|
|
||||||
if key == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
specgen.AddProcessEnv(key, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := addOciBindMounts(sb, containerConfig, &specgen); err != nil {
|
if err := addOciBindMounts(sb, containerConfig, &specgen); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -467,6 +449,40 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
}
|
}
|
||||||
specgen.SetProcessArgs(processArgs)
|
specgen.SetProcessArgs(processArgs)
|
||||||
|
|
||||||
|
// Add environment variables from CRI and image config
|
||||||
|
envs := containerConfig.GetEnvs()
|
||||||
|
if envs != nil {
|
||||||
|
for _, item := range envs {
|
||||||
|
key := item.Key
|
||||||
|
value := item.Value
|
||||||
|
if key == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
specgen.AddProcessEnv(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, item := range containerInfo.Config.Config.Env {
|
||||||
|
parts := strings.SplitN(item, "=", 2)
|
||||||
|
if len(parts) != 2 {
|
||||||
|
return nil, fmt.Errorf("invalid env from image: %s", item)
|
||||||
|
}
|
||||||
|
|
||||||
|
if parts[0] == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
specgen.AddProcessEnv(parts[0], parts[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set working directory
|
||||||
|
// Pick it up from image config first and override if specified in CRI
|
||||||
|
imageCwd := containerInfo.Config.Config.WorkingDir
|
||||||
|
specgen.SetProcessCwd(imageCwd)
|
||||||
|
|
||||||
|
cwd := containerConfig.WorkingDir
|
||||||
|
if cwd != "" {
|
||||||
|
specgen.SetProcessCwd(cwd)
|
||||||
|
}
|
||||||
|
|
||||||
// by default, the root path is an empty string. set it now.
|
// by default, the root path is an empty string. set it now.
|
||||||
specgen.SetRootPath(mountPoint)
|
specgen.SetRootPath(mountPoint)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue