Skip to content

Commit

Permalink
refact: unify the path env (#855)
Browse files Browse the repository at this point in the history
* refact: unify the path env

Signed-off-by: Keming <kemingyang@tensorchord.ai>

* fix priority

Signed-off-by: Keming <kemingyang@tensorchord.ai>

Signed-off-by: Keming <kemingyang@tensorchord.ai>
  • Loading branch information
kemingy committed Sep 7, 2022
1 parent 8056fda commit ecb9e26
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
16 changes: 4 additions & 12 deletions pkg/builder/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
gatewayclient "github.com/moby/buildkit/frontend/gateway/client"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"

"github.com/tensorchord/envd/pkg/types"
)

const (
Expand Down Expand Up @@ -60,21 +62,11 @@ func ImageConfigStr(labels map[string]string, ports map[string]struct{},
return string(data), nil
}

// DefaultPathEnvUnix is unix style list of directories to search for
// executables. Each directory is separated from the next by a colon
// ':' character .
const DefaultPathEnvUnix = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/conda/bin:/opt/conda/envs/envd/bin/:/usr/local/julia/bin"

// DefaultPathEnvWindows is windows style list of directories to search for
// executables. Each directory is separated from the next by a colon
// ';' character .
const DefaultPathEnvWindows = "c:\\Windows\\System32;c:\\Windows"

func DefaultPathEnv(os string) string {
if os == "windows" {
return DefaultPathEnvWindows
return types.DefaultPathEnvWindows
}
return DefaultPathEnvUnix
return types.DefaultPathEnvUnix
}

func parseImportCacheCSV(s string) (gatewayclient.CacheOptionsEntry, error) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/lang/ir/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func (g Graph) compileAlternative(root llb.State) llb.State {
envdPrefix := "/opt/conda/envs/envd/bin"
run := root.
Run(llb.Shlexf("update-alternatives --install /usr/bin/python python %s/python 1", envdPrefix), llb.WithCustomName("update alternative python to envd")).
Run(llb.Shlexf("update-alternatives --install /usr/bin/python3 python3 %s/python3 1", envdPrefix), llb.WithCustomName("update alternative python to envd")).
Run(llb.Shlexf("update-alternatives --install /usr/bin/pip pip %s/pip 1", envdPrefix), llb.WithCustomName("update alternative python to envd")).
Run(llb.Shlexf("update-alternatives --install /usr/bin/pip3 pip3 %s/pip3 1", envdPrefix), llb.WithCustomName("update alternative python to envd"))
Run(llb.Shlexf("update-alternatives --install /usr/bin/python3 python3 %s/python3 1", envdPrefix), llb.WithCustomName("update alternative python3 to envd")).
Run(llb.Shlexf("update-alternatives --install /usr/bin/pip pip %s/pip 1", envdPrefix), llb.WithCustomName("update alternative pip to envd")).
Run(llb.Shlexf("update-alternatives --install /usr/bin/pip3 pip3 %s/pip3 1", envdPrefix), llb.WithCustomName("update alternative pip3 to envd"))
return run.Root()
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/lang/ir/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/tensorchord/envd/pkg/config"
"github.com/tensorchord/envd/pkg/flag"
"github.com/tensorchord/envd/pkg/types"
"github.com/tensorchord/envd/pkg/version"
)

Expand All @@ -49,7 +50,7 @@ func (g Graph) compileRun(root llb.State) llb.State {
if len(g.Exec) == 0 {
return root
}
root = root.AddEnv("PATH", "$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/conda/bin:/usr/local/julia/bin:/opt/conda/envs/envd/bin")
root = root.AddEnv("PATH", types.DefaultPathEnvUnix)
logrus.Debugf("compile run: %s", strings.Join(g.Exec, " "))
if len(g.Exec) == 1 {
return root.Run(llb.Shlex(fmt.Sprintf("bash -c \"%s\"", g.Exec[0]))).Root()
Expand Down
11 changes: 11 additions & 0 deletions pkg/types/envd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,19 @@ import (
"encoding/json"

"github.com/docker/docker/api/types"
"github.com/moby/buildkit/util/system"
)

// DefaultPathEnvUnix is unix style list of directories to search for
// executables. Each directory is separated from the next by a colon
// ':' character .
const DefaultPathEnvUnix = "/opt/conda/envs/envd/bin:/opt/conda/bin:/usr/local/julia/bin:" + system.DefaultPathEnvUnix

// DefaultPathEnvWindows is windows style list of directories to search for
// executables. Each directory is separated from the next by a colon
// ';' character .
const DefaultPathEnvWindows = system.DefaultPathEnvWindows

type EnvdImage struct {
types.ImageSummary

Expand Down

0 comments on commit ecb9e26

Please sign in to comment.