Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base-images/python3.8-ubuntu20.04-cuda11.6.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RUN apt-get update && \
bzip2 ca-certificates libglib2.0-0 libsm6 libxext6 libxrender1 mercurial \
procps subversion wget \
# envd dependencies
python3 curl openssh-client git tini sudo python3-pip zsh vim \
curl openssh-client git tini sudo python3-pip zsh vim \
&& rm -rf /var/lib/apt/lists/*

# Keep apt from auto upgrading the cublas and nccl packages. See https://gitlab.com/nvidia/container-images/cuda/-/issues/88
Expand Down
2 changes: 1 addition & 1 deletion base-images/python3.8-ubuntu20.04.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN apt-get update && \
bzip2 ca-certificates libglib2.0-0 libsm6 libxext6 libxrender1 mercurial \
procps subversion wget \
# envd dependencies
python3 curl openssh-client git tini sudo python3-pip zsh vim \
curl openssh-client git tini sudo python3-pip zsh vim \
&& rm -rf /var/lib/apt/lists/*

# Leave these args here to better use the Docker build cache
Expand Down
13 changes: 5 additions & 8 deletions pkg/lang/ir/conda.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
)

const (
condarc = "/home/envd/.condarc"
condarc = "/home/envd/.condarc"
defaultVersion = "3.9"
)

func (g Graph) CondaEnabled() bool {
Expand Down Expand Up @@ -81,17 +82,13 @@ func (g Graph) compileCondaPackages(root llb.State) llb.State {
}

func (g Graph) setCondaENV(root llb.State) llb.State {
if !g.CondaEnabled() {
return root
}

root = llb.User("envd")(root)
// Always init bash since we will use it to create jupyter notebook service.
run := root.Run(llb.Shlex("bash -c \"/opt/conda/bin/conda init bash\""), llb.WithCustomName("[internal] initialize conda bash environment"))

pythonVersion := "3.9"
if g.Language.Version != nil {
pythonVersion = *g.Language.Version
pythonVersion, err := g.GetAppropriatePythonVersion()
if err != nil {
pythonVersion = defaultVersion
}
cmd := fmt.Sprintf(
"bash -c \"/opt/conda/bin/conda create -n envd python=%s\"", pythonVersion)
Expand Down
31 changes: 26 additions & 5 deletions pkg/lang/ir/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ import (
"github.com/sirupsen/logrus"
)

func (g Graph) GetAppropriatePythonVersion() (string, error) {
version := *g.Language.Version
if version == "3" || version == "" {
return defaultVersion, nil
}
if strings.HasPrefix(version, "3.") {
return version, nil
}
return "", errors.Errorf("python version %s is not supported", version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not support Python 2.x, does it work for you? @VoVAllen @kemingy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget to discuss with others. But I do think it is not a good idea to support python2. >_<!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Python 2.x should be deprecated in all ways

}

func (g Graph) compilePython(aptStage llb.State) (llb.State, error) {
condaChanelStage := g.compileCondaChannel(aptStage)
pypiMirrorStage := g.compilePyPIIndex(condaChanelStage)
Expand Down Expand Up @@ -74,9 +85,22 @@ func (g Graph) compilePython(aptStage llb.State) (llb.State, error) {
diffSSHStage, pypiStage,
}, llb.WithCustomName("merging all components into one"))
}
merged = g.compileAlternative(merged)
return merged, nil
}

// Set the system default python to envd's python.
func (g Graph) compileAlternative(root llb.State) llb.State {
root = llb.User("root")(root)
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"))
return run.Root()
}

func (g Graph) compilePyPIPackages(root llb.State) llb.State {
if len(g.PyPIPackages) == 0 {
return root
Expand All @@ -88,11 +112,8 @@ func (g Graph) compilePyPIPackages(root llb.State) llb.State {

// Compose the package install command.
var sb strings.Builder
if g.CondaEnabled() {
sb.WriteString("/opt/conda/bin/conda run -n envd pip install")
} else {
sb.WriteString("pip install --no-warn-script-location")
}
// Always use the conda's pip.
sb.WriteString("/opt/conda/bin/conda run -n envd pip install")
for _, pkg := range g.PyPIPackages {
sb.WriteString(fmt.Sprintf(" %s", pkg))
}
Expand Down