Skip to content

Commit

Permalink
fix: pip install requirements.txt (#1434)
Browse files Browse the repository at this point in the history
* fix: v1 pip install requirements.txt

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

* change v0

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

Signed-off-by: Keming <kemingyang@tensorchord.ai>
  • Loading branch information
kemingy committed Jan 22, 2023
1 parent f47f7a3 commit 83c63c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
21 changes: 4 additions & 17 deletions pkg/lang/ir/v0/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,12 @@ func (g generalGraph) compilePyPIPackages(root llb.State) llb.State {
}

if g.RequirementsFile != nil {
// Compose the package install command.
var sb strings.Builder
sb.WriteString("bash -c '")
sb.WriteString("set -euo pipefail\n")
sb.WriteString(fmt.Sprintf("chown -R envd:envd %s\n", g.getWorkingDir())) // Change mount dir permission
envdCmd := strings.Builder{}
envdCmd.WriteString(fmt.Sprintf("cd %s\n", g.getWorkingDir()))
envdCmd.WriteString(fmt.Sprintf("/opt/conda/envs/envd/bin/python -m pip install -r %s\n", *g.RequirementsFile))

// Execute the command to write yaml file and conda env using envd user
sb.WriteString(fmt.Sprintf("sudo -i -u envd bash << EOF\n%s\nEOF\n", envdCmd.String()))
sb.WriteString("'")
cmd := sb.String()

logrus.WithField("command", cmd).
logrus.WithField("file", *g.RequirementsFile).
Debug("Configure pip install requirements statements")
root = root.User("root").Dir(g.getWorkingDir())
root = root.Dir(g.getWorkingDir())
run := root.
Run(llb.Shlex(cmd), llb.WithCustomNamef("pip install %s", *g.RequirementsFile))
Run(llb.Shlexf("/opt/conda/envs/envd/bin/python -m pip install -r %s", *g.RequirementsFile),
llb.WithCustomNamef("pip install -r %s", *g.RequirementsFile))
run.AddMount(cacheDir, cache,
llb.AsPersistentCacheDir(g.CacheID(cacheDir), llb.CacheMountShared), llb.SourcePath("/cache/pip"))
run.AddMount(g.getWorkingDir(),
Expand Down
21 changes: 4 additions & 17 deletions pkg/lang/ir/v1/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,12 @@ func (g generalGraph) compilePyPIPackages(root llb.State) llb.State {
}

if g.RequirementsFile != nil {
// Compose the package install command.
var sb strings.Builder
sb.WriteString("bash -c '")
sb.WriteString("set -euo pipefail\n")
sb.WriteString(fmt.Sprintf("chown -R envd:envd %s\n", g.getWorkingDir())) // Change mount dir permission
envdCmd := strings.Builder{}
envdCmd.WriteString(fmt.Sprintf("cd %s\n", g.getWorkingDir()))
envdCmd.WriteString(fmt.Sprintf("python -m pip install -r %s\n", *g.RequirementsFile))

// Execute the command to write yaml file and conda env using envd user
sb.WriteString(fmt.Sprintf("sudo -i -u envd bash << EOF\n%s\nEOF\n", envdCmd.String()))
sb.WriteString("'")
cmd := sb.String()

logrus.WithField("command", cmd).
logrus.WithField("file", *g.RequirementsFile).
Debug("Configure pip install requirements statements")
root = root.User("root").Dir(g.getWorkingDir())
root = root.Dir(g.getWorkingDir())
run := root.
Run(llb.Shlex(cmd), llb.WithCustomNamef("pip install %s", *g.RequirementsFile))
Run(llb.Shlexf("python -m pip install -r %s", *g.RequirementsFile),
llb.WithCustomNamef("pip install -r %s", *g.RequirementsFile))
run.AddMount(cacheDir, cache,
llb.AsPersistentCacheDir(g.CacheID(cacheDir), llb.CacheMountShared), llb.SourcePath("/cache/pip"))
run.AddMount(g.getWorkingDir(),
Expand Down

0 comments on commit 83c63c7

Please sign in to comment.