Skip to content

Commit

Permalink
fix: v0 bashrc file (#1307)
Browse files Browse the repository at this point in the history
* fix: v0 bashrc file

Signed-off-by: Keming <[email protected]>

* reorder py llb

Signed-off-by: Keming <[email protected]>

* fix go emb

Signed-off-by: Keming <[email protected]>

Signed-off-by: Keming <[email protected]>
  • Loading branch information
kemingy authored Dec 15, 2022
1 parent 1fec54e commit 31eec50
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion envd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"path/filepath"
)

//go:embed api/*.py api/**/*.py
//go:embed api/**/*.py
var api embed.FS

const autoGeneratedHeader = `### AUTO-GENERATED ###
Expand Down
6 changes: 3 additions & 3 deletions pkg/lang/ir/v0/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ func (g generalGraph) compilePython(baseStage llb.State) (llb.State, error) {
if err != nil {
return llb.State{}, errors.Wrap(err, "failed to compile shell")
}
condaShellStage := g.compileCondaShell(shellStage)

diffCondaEnvStage := llb.Diff(baseStage, condaEnvStage,
llb.WithCustomName("[internal] conda python environment"))
diffSystemStage := llb.Diff(baseStage, systemStage,
llb.WithCustomName("[internal] install system packages"))
diffShellStage := llb.Diff(baseStage, condaShellStage,
diffShellStage := llb.Diff(baseStage, shellStage,
llb.WithCustomNamef("[internal] configure shell %s", g.Shell))
prePythonStage := llb.Merge([]llb.State{
diffSystemStage,
Expand Down Expand Up @@ -112,7 +111,8 @@ func (g generalGraph) compilePython(baseStage llb.State) (llb.State, error) {
}, llb.WithCustomName("[internal] generating the image"))
}
merged = g.compileAlternative(merged)
return merged, nil
condaShell := g.compileCondaShell(merged)
return condaShell, nil
}

// Set the system default python to envd's python.
Expand Down
22 changes: 8 additions & 14 deletions pkg/lang/ir/v0/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,15 @@ func (g *generalGraph) compileShell(root llb.State) (llb.State, error) {
}

func (g *generalGraph) compileCondaShell(root llb.State) llb.State {
var run llb.ExecState
switch g.Shell {
case shellBASH:
run = root.Run(
llb.Shlex(
fmt.Sprintf(`bash -c 'echo "source %s/activate envd" >> %s'`,
condaBinDir, fileutil.EnvdHomeDir(".bashrc"))),
llb.WithCustomName("[internal] add conda environment to bashrc"))
case shellZSH:
run = root.Run(
llb.Shlex(fmt.Sprintf("bash -c \"%s\"", g.condaInitShell(g.Shell))),
llb.WithCustomNamef("[internal] initialize conda %s environment", g.Shell)).Run(
llb.Shlex(fmt.Sprintf(`bash -c 'echo "source %s/activate envd" >> %s'`, condaBinDir, fileutil.EnvdHomeDir(".zshrc"))),
llb.WithCustomName("[internal] add conda environment to zshrc"))
rcPath := fileutil.EnvdHomeDir(".bashrc")
if g.Shell == shellZSH {
rcPath = fileutil.EnvdHomeDir(".zshrc")
}
run := root.
Run(llb.Shlexf("bash -c \"%s\"", g.condaInitShell(g.Shell)),
llb.WithCustomNamef("[internal] init conda %s env", g.Shell)).
Run(llb.Shlexf(`bash -c 'echo "source %s/activate envd" >> %s'`, condaBinDir, rcPath),
llb.WithCustomNamef("[internal] add conda environment to %s", rcPath))
return run.Root()
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/lang/ir/v1/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (g *generalGraph) compileShell(root llb.State) (_ llb.State, err error) {
}

func (g *generalGraph) compileCondaShell(root llb.State) llb.State {
var run llb.ExecState
findDir := fileutil.DefaultHomeDir
if g.Dev {
findDir = fileutil.EnvdHomeDir
Expand All @@ -82,11 +81,11 @@ func (g *generalGraph) compileCondaShell(root llb.State) llb.State {
if g.Shell == shellZSH {
rcPath = findDir(".zshrc")
}
run = root.
run := root.
Run(llb.Shlexf("bash -c \"%s\"", g.condaInitShell(g.Shell)),
llb.WithCustomNamef("[internal] init conda %s env", g.Shell)).
Run(llb.Shlexf(`bash -c 'echo "source %s/activate envd" >> %s'`, condaBinDir, rcPath),
llb.WithCustomName("[internal] add conda environment to zshrc"))
llb.WithCustomNamef("[internal] add conda environment to %s", rcPath))
return run.Root()
}

Expand Down

0 comments on commit 31eec50

Please sign in to comment.