fix(executor/sandbox): shell join
Some checks failed
build / build (pull_request) Failing after 1m13s
build / trigger-build-image (pull_request) Has been skipped
build / build (push) Failing after 1m32s
build / trigger-build-image (push) Has been skipped

This commit is contained in:
张泊明518370910136 2026-07-23 00:59:24 -07:00
parent 98889ffbba
commit 93c7e7e16d
GPG Key ID: D47306D7062CDA9D

View File

@ -101,54 +101,21 @@ func (e *Sandbox) runWithTar(cmds []stage.Cmd, tarData []byte) ([]stage.Executor
slog.Debug("sandbox tar uploaded", "fileID", fid, "tarSize", len(tarData))
tarFileName := "/w/__joj3_copyin.tar"
tarCmd := stage.Cmd{
Args: []string{"/bin/tar", "xf", tarFileName, "-C", "/w", "--no-same-owner"},
Env: cmds[0].Env,
Stdin: &stage.CmdFile{Content: strPtr("")},
Stdout: &stage.CmdFile{Name: strPtr("__tar_stdout"), Max: int64Ptr(256)},
Stderr: &stage.CmdFile{Name: strPtr("__tar_stderr"), Max: int64Ptr(256)},
CPULimit: cmds[0].CPULimit,
ClockLimit: cmds[0].ClockLimit,
MemoryLimit: cmds[0].MemoryLimit,
StackLimit: cmds[0].StackLimit,
ProcLimit: cmds[0].ProcLimit,
CPURateLimit: cmds[0].CPURateLimit,
CPUSetLimit: cmds[0].CPUSetLimit,
CopyIn: map[string]stage.CmdFile{
tarFileName: {FileID: &fid},
},
}
script := fmt.Sprintf(
"/bin/tar xf %s -C / --no-same-owner && exec \"$@\"",
tarFileName,
)
allCmds := append([]stage.Cmd{tarCmd}, cmds...)
pbCmds := convertPBCmd(allCmds)
cmds[0].CopyIn[tarFileName] = stage.CmdFile{FileID: &fid}
cmds[0].Args = append([]string{
"/bin/sh", "-c", script, "--",
}, cmds[0].Args...)
pbReq := &pb.Request{}
pbReq.SetCmd(pbCmds)
slog.Debug("sandbox tar exec", "pbReq size", proto.Size(pbReq), "tarSize", len(tarData))
slog.Debug("sandbox tar exec", "cmd", cmds[0].Args[:3])
pbRet, err := e.execClient.Exec(context.TODO(), pbReq)
results, err := e.runUnary(cmds)
if err != nil {
return nil, fmt.Errorf("tar exec: %w", err)
}
if pbRet.GetError() != "" {
return nil, fmt.Errorf("sandbox execute error: %s", pbRet.GetError())
}
results := convertPBResult(pbRet.GetResults())
if len(results) == 0 {
return nil, fmt.Errorf("tar exec: empty results")
}
tarResult := results[0]
if tarResult.Status != stage.StatusAccepted || tarResult.ExitStatus != 0 {
return nil, fmt.Errorf(
"tar extraction failed: status=%v, exit=%d, error=%s",
tarResult.Status, tarResult.ExitStatus, tarResult.Error,
)
}
results = results[1:]
for _, result := range results {
maps.Copy(e.cachedMap, result.FileIDs)
return nil, err
}
deleteReq := &pb.FileID{}
@ -227,6 +194,9 @@ func createCopyInTar(cmd *stage.Cmd) ([]byte, []string) {
return err
}
hdr.Name = relPath
if !filepath.IsAbs(hdr.Name) {
hdr.Name = "w/" + hdr.Name
}
return tw.WriteHeader(hdr)
}
hdr, err := tar.FileInfoHeader(info, "")
@ -234,6 +204,9 @@ func createCopyInTar(cmd *stage.Cmd) ([]byte, []string) {
return err
}
hdr.Name = relPath
if !filepath.IsAbs(hdr.Name) {
hdr.Name = "w/" + hdr.Name
}
if info.IsDir() {
hdr.Name += "/"
}
@ -262,8 +235,12 @@ func createCopyInTar(cmd *stage.Cmd) ([]byte, []string) {
continue
}
if f.Content != nil {
name := k
if !filepath.IsAbs(name) {
name = "w/" + name
}
hdr := &tar.Header{
Name: k,
Name: name,
Mode: 0o644,
Size: int64(len(*f.Content)),
}
@ -291,6 +268,9 @@ func createCopyInTar(cmd *stage.Cmd) ([]byte, []string) {
continue
}
hdr.Name = k
if !filepath.IsAbs(hdr.Name) {
hdr.Name = "w/" + hdr.Name
}
if err := tw.WriteHeader(hdr); err != nil {
slog.Error("create copyIn tar write header", "key", k, "error", err)
continue
@ -329,7 +309,3 @@ func (e *Sandbox) Cleanup() error {
}
return nil
}
func strPtr(s string) *string { return &s }
func int64Ptr(i int64) *int64 { return &i }