Browse code

pkg/system: deprecate DefaultPathEnv, move to oci

This patch:

- Deprecates pkg/system.DefaultPathEnv
- Moves the implementation inside oci
- Adds TODOs to align the default in the Builder with the one used elsewhere

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2022/10/08 06:57:09
Showing 7 changed files
... ...
@@ -14,7 +14,7 @@ import (
14 14
 	"github.com/docker/docker/api/types/strslice"
15 15
 	"github.com/docker/docker/builder"
16 16
 	"github.com/docker/docker/image"
17
-	"github.com/docker/docker/pkg/system"
17
+	"github.com/docker/docker/oci"
18 18
 	"github.com/docker/go-connections/nat"
19 19
 	"github.com/moby/buildkit/frontend/dockerfile/instructions"
20 20
 	"github.com/moby/buildkit/frontend/dockerfile/parser"
... ...
@@ -128,7 +128,8 @@ func TestFromScratch(t *testing.T) {
128 128
 	assert.NilError(t, err)
129 129
 	assert.Check(t, sb.state.hasFromImage())
130 130
 	assert.Check(t, is.Equal("", sb.state.imageID))
131
-	expected := "PATH=" + system.DefaultPathEnv(runtime.GOOS)
131
+	// TODO(thaJeztah): use github.com/moby/buildkit/util/system.DefaultPathEnv() once https://github.com/moby/buildkit/pull/3158 is resolved.
132
+	expected := "PATH=" + oci.DefaultPathEnv(runtime.GOOS)
132 133
 	assert.Check(t, is.DeepEqual([]string{expected}, sb.state.runConfig.Env))
133 134
 }
134 135
 
... ...
@@ -28,6 +28,7 @@ import (
28 28
 	"github.com/docker/docker/api/types/container"
29 29
 	"github.com/docker/docker/builder"
30 30
 	"github.com/docker/docker/errdefs"
31
+	"github.com/docker/docker/oci"
31 32
 	"github.com/docker/docker/pkg/system"
32 33
 	"github.com/docker/docker/runconfig/opts"
33 34
 	"github.com/moby/buildkit/frontend/dockerfile/instructions"
... ...
@@ -236,7 +237,8 @@ func (s *dispatchState) beginStage(stageName string, image builder.Image) error
236 236
 // Add the default PATH to runConfig.ENV if one exists for the operating system and there
237 237
 // is no PATH set. Note that Windows containers on Windows won't have one as it's set by HCS
238 238
 func (s *dispatchState) setDefaultPath() {
239
-	defaultPath := system.DefaultPathEnv(s.operatingSystem)
239
+	// TODO(thaJeztah): use github.com/moby/buildkit/util/system.DefaultPathEnv() once https://github.com/moby/buildkit/pull/3158 is resolved.
240
+	defaultPath := oci.DefaultPathEnv(s.operatingSystem)
240 241
 	if defaultPath == "" {
241 242
 		return
242 243
 	}
... ...
@@ -28,10 +28,10 @@ import (
28 28
 	"github.com/docker/docker/image"
29 29
 	"github.com/docker/docker/layer"
30 30
 	libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
31
+	"github.com/docker/docker/oci"
31 32
 	"github.com/docker/docker/pkg/containerfs"
32 33
 	"github.com/docker/docker/pkg/idtools"
33 34
 	"github.com/docker/docker/pkg/ioutils"
34
-	"github.com/docker/docker/pkg/system"
35 35
 	"github.com/docker/docker/restartmanager"
36 36
 	"github.com/docker/docker/volume"
37 37
 	volumemounts "github.com/docker/docker/volume/mounts"
... ...
@@ -737,7 +737,7 @@ func (container *Container) CreateDaemonEnvironment(tty bool, linkedEnv []string
737 737
 
738 738
 	env := make([]string, 0, envSize)
739 739
 	if runtime.GOOS != "windows" {
740
-		env = append(env, "PATH="+system.DefaultPathEnv(ctrOS))
740
+		env = append(env, "PATH="+oci.DefaultPathEnv(ctrOS))
741 741
 		env = append(env, "HOSTNAME="+container.Config.Hostname)
742 742
 		if tty {
743 743
 			env = append(env, "TERM=xterm")
... ...
@@ -9,6 +9,24 @@ import (
9 9
 
10 10
 func iPtr(i int64) *int64 { return &i }
11 11
 
12
+const defaultUnixPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
13
+
14
+// DefaultPathEnv is unix style list of directories to search for
15
+// executables. Each directory is separated from the next by a colon
16
+// ':' character .
17
+// For Windows containers, an empty string is returned as the default
18
+// path will be set by the container, and Docker has no context of what the
19
+// default path should be.
20
+//
21
+// TODO(thaJeztah) align Windows default with BuildKit; see https://github.com/moby/buildkit/pull/1747
22
+// TODO(thaJeztah) use defaults from containerd (but align it with BuildKit; see https://github.com/moby/buildkit/pull/1747)
23
+func DefaultPathEnv(os string) string {
24
+	if os == "windows" {
25
+		return ""
26
+	}
27
+	return defaultUnixPathEnv
28
+}
29
+
12 30
 // DefaultSpec returns the default spec used by docker for the current Platform
13 31
 func DefaultSpec() specs.Spec {
14 32
 	if runtime.GOOS == "windows" {
... ...
@@ -1,20 +1,5 @@
1 1
 package system // import "github.com/docker/docker/pkg/system"
2 2
 
3
-const defaultUnixPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
4
-
5
-// DefaultPathEnv is unix style list of directories to search for
6
-// executables. Each directory is separated from the next by a colon
7
-// ':' character .
8
-// For Windows containers, an empty string is returned as the default
9
-// path will be set by the container, and Docker has no context of what the
10
-// default path should be.
11
-func DefaultPathEnv(os string) string {
12
-	if os == "windows" {
13
-		return ""
14
-	}
15
-	return defaultUnixPathEnv
16
-}
17
-
18 3
 // CheckSystemDriveAndRemoveDriveLetter verifies that a path, if it includes a drive letter,
19 4
 // is the system drive.
20 5
 // On Linux: this is a no-op.
21 6
new file mode 100644
... ...
@@ -0,0 +1,18 @@
0
+package system
1
+
2
+const defaultUnixPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
3
+
4
+// DefaultPathEnv is unix style list of directories to search for
5
+// executables. Each directory is separated from the next by a colon
6
+// ':' character .
7
+// For Windows containers, an empty string is returned as the default
8
+// path will be set by the container, and Docker has no context of what the
9
+// default path should be.
10
+//
11
+// Deprecated: use oci.DefaultPathEnv
12
+func DefaultPathEnv(os string) string {
13
+	if os == "windows" {
14
+		return ""
15
+	}
16
+	return defaultUnixPathEnv
17
+}
... ...
@@ -8,7 +8,6 @@ import (
8 8
 
9 9
 	"github.com/docker/docker/api/types"
10 10
 	"github.com/docker/docker/oci"
11
-	"github.com/docker/docker/pkg/system"
12 11
 	specs "github.com/opencontainers/runtime-spec/specs-go"
13 12
 	"github.com/pkg/errors"
14 13
 )
... ...
@@ -114,7 +113,7 @@ func (p *Plugin) InitSpec(execRoot string) (*specs.Spec, error) {
114 114
 	}
115 115
 
116 116
 	envs := make([]string, 1, len(p.PluginObj.Settings.Env)+1)
117
-	envs[0] = "PATH=" + system.DefaultPathEnv(runtime.GOOS)
117
+	envs[0] = "PATH=" + oci.DefaultPathEnv(runtime.GOOS)
118 118
 	envs = append(envs, p.PluginObj.Settings.Env...)
119 119
 
120 120
 	args := append(p.PluginObj.Config.Entrypoint, p.PluginObj.Settings.Args...)