Skip to content

Commit

Permalink
Merge pull request #2722 from dtrudg/issue2721
Browse files Browse the repository at this point in the history
fix: oci: set default PATH if image does not
  • Loading branch information
dtrudg authored Mar 7, 2024
2 parents ac6b804 + 41f91e8 commit 6935fa7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ commands:
libtool \
pkg-config \
squashfs-tools \
squashfs-tools-ng \
uidmap \
zlib1g-dev
- run:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# SingularityCE Changelog

## Change Since Last Release

### Bug Fixes

- Set default `PATH` in container run in OCI-Mode when image does not set `PATH`.

## 4.1.2 \[2024-03-05\]

### Bug Fixes
Expand Down
10 changes: 7 additions & 3 deletions internal/pkg/runtime/launcher/oci/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,20 @@ func (l *Launcher) getProcessEnv(imageSpec imgspecv1.Image, hostEnv []string, us
}

func setOCIPath(g *generate.Generator, prependPath, path, appendPath string) {
// If we have no PATH at this point, then the image didn't define one, and
// the user didn't specify a full PATH override. We need to use a default,
// to find bare `CMD`s e.g. issue #2721.
if path == "" {
path = env.DefaultPath
}
// Compute and set optionally APPEND-ed / PREPEND-ed PATH.
if appendPath != "" {
path = strings.TrimSuffix(path, ":") + ":" + appendPath
}
if prependPath != "" {
path = prependPath + ":" + strings.TrimPrefix(path, ":")
}
if path != "" {
g.AddProcessEnv("PATH", path)
}
g.AddProcessEnv("PATH", path)
}

func setNativePath(g *generate.Generator, prependPath, path, appendPath string) {
Expand Down
23 changes: 21 additions & 2 deletions internal/pkg/runtime/launcher/oci/process_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func TestGetProcessArgs(t *testing.T) {
}

func TestGetProcessEnvOCI(t *testing.T) {
defaultPathEnv := "PATH=" + env.DefaultPath

tests := []struct {
name string
noCompat bool
Expand All @@ -155,7 +157,10 @@ func TestGetProcessEnvOCI(t *testing.T) {
imageEnv: []string{},
hostEnv: []string{},
userEnv: map[string]string{},
wantEnv: []string{"LD_LIBRARY_PATH=/.singularity.d/libs"},
wantEnv: []string{
defaultPathEnv,
"LD_LIBRARY_PATH=/.singularity.d/libs",
},
},
{
name: "PassTERM",
Expand All @@ -165,6 +170,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
userEnv: map[string]string{},
wantEnv: []string{
"TERM=xterm-256color",
defaultPathEnv,
"LD_LIBRARY_PATH=/.singularity.d/libs",
},
},
Expand All @@ -176,6 +182,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
userEnv: map[string]string{},
wantEnv: []string{
"HTTP_PROXY=proxy.example.com:3128",
defaultPathEnv,
"LD_LIBRARY_PATH=/.singularity.d/libs",
},
},
Expand All @@ -185,7 +192,10 @@ func TestGetProcessEnvOCI(t *testing.T) {
imageEnv: []string{},
hostEnv: []string{"NOT_FOR_CONTAINER=true"},
userEnv: map[string]string{},
wantEnv: []string{"LD_LIBRARY_PATH=/.singularity.d/libs"},
wantEnv: []string{
defaultPathEnv,
"LD_LIBRARY_PATH=/.singularity.d/libs",
},
},
{
name: "ImagePath",
Expand Down Expand Up @@ -239,6 +249,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
userEnv: map[string]string{},
wantEnv: []string{
"LD_LIBRARY_PATH=/foo:/.singularity.d/libs",
defaultPathEnv,
},
},
{
Expand All @@ -248,6 +259,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
hostEnv: []string{},
userEnv: map[string]string{"LD_LIBRARY_PATH": "/foo"},
wantEnv: []string{
defaultPathEnv,
"LD_LIBRARY_PATH=/foo:/.singularity.d/libs",
},
},
Expand All @@ -259,6 +271,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
userEnv: map[string]string{"LD_LIBRARY_PATH": "/bar"},
wantEnv: []string{
"LD_LIBRARY_PATH=/bar:/.singularity.d/libs",
defaultPathEnv,
},
},
{
Expand All @@ -269,6 +282,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
userEnv: map[string]string{},
wantEnv: []string{
"FOO=bar",
defaultPathEnv,
"LD_LIBRARY_PATH=/.singularity.d/libs",
},
},
Expand All @@ -280,6 +294,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
userEnv: map[string]string{"FOO": "baz"},
wantEnv: []string{
"FOO=baz",
defaultPathEnv,
"LD_LIBRARY_PATH=/.singularity.d/libs",
},
},
Expand All @@ -292,6 +307,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
wantEnv: []string{
"FOO=bar",
"ABC=123",
defaultPathEnv,
"LD_LIBRARY_PATH=/.singularity.d/libs",
},
},
Expand All @@ -303,6 +319,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
userEnv: map[string]string{},
wantEnv: []string{
"FOO=bar",
defaultPathEnv,
"LD_LIBRARY_PATH=/.singularity.d/libs",
},
},
Expand All @@ -314,6 +331,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
userEnv: map[string]string{},
wantEnv: []string{
"FOO=baz",
defaultPathEnv,
"LD_LIBRARY_PATH=/.singularity.d/libs",
},
},
Expand All @@ -325,6 +343,7 @@ func TestGetProcessEnvOCI(t *testing.T) {
userEnv: map[string]string{"FOO": "baz"},
wantEnv: []string{
"FOO=baz",
defaultPathEnv,
"LD_LIBRARY_PATH=/.singularity.d/libs",
},
},
Expand Down

0 comments on commit 6935fa7

Please sign in to comment.