fix(executor/sandbox): stream all files
Some checks failed
submodules sync / sync (push) Successful in 28s
build / build (push) Failing after 1m11s
build / trigger-build-image (push) Has been skipped

This commit is contained in:
张泊明518370910136 2026-07-22 22:07:17 -07:00
parent 90602b358f
commit e897d2a78c
GPG Key ID: D47306D7062CDA9D
3 changed files with 67 additions and 41 deletions

View File

@ -12,23 +12,12 @@ jobs:
run: go version run: go version
- name: Prepare - name: Prepare
run: | run: |
echo ">>> set GO111MODULE"
go env -w GO111MODULE=on go env -w GO111MODULE=on
echo ">>> set GOPROXY"
go env -w GOPROXY=https://goproxy.cn,direct go env -w GOPROXY=https://goproxy.cn,direct
echo ">>> mkdir ~/.ssh"
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo ">>> write private key"
echo "${{ secrets.DEPLOY_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 echo "${{ secrets.DEPLOY_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
echo ">>> write public key"
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519.pub echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519.pub
echo ">>> chmod private key" chmod 600 ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/id_ed25519
echo ">>> chmod public key"
chmod 600 ~/.ssh/id_ed25519.pub
echo ">>> ssh-keyscan"
timeout 10 ssh-keyscan -p 2222 focs.gc.sjtu.edu.cn >> ~/.ssh/known_hosts || echo "ssh-keyscan failed, using StrictHostKeyChecking=accept-new"
echo ">>> ssh test"
ssh -o StrictHostKeyChecking=accept-new -T git@focs.gc.sjtu.edu.cn -p 2222 ssh -o StrictHostKeyChecking=accept-new -T git@focs.gc.sjtu.edu.cn -p 2222
# - name: Lint # - name: Lint
# run: make lint # run: make lint
@ -47,19 +36,10 @@ jobs:
steps: steps:
- name: Set up SSH - name: Set up SSH
run: | run: |
echo ">>> mkdir ~/.ssh"
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo ">>> write private key"
echo "${{ secrets.DEPLOY_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 echo "${{ secrets.DEPLOY_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
echo ">>> write public key"
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519.pub echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519.pub
echo ">>> chmod private key" chmod 600 ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/id_ed25519
echo ">>> chmod public key"
chmod 600 ~/.ssh/id_ed25519.pub
echo ">>> ssh-keyscan"
timeout 10 ssh-keyscan -p 2222 focs.gc.sjtu.edu.cn >> ~/.ssh/known_hosts || echo "ssh-keyscan failed, using StrictHostKeyChecking=accept-new"
echo ">>> ssh test"
ssh -o StrictHostKeyChecking=accept-new -T git@focs.gc.sjtu.edu.cn -p 2222 ssh -o StrictHostKeyChecking=accept-new -T git@focs.gc.sjtu.edu.cn -p 2222
- name: Set up Git - name: Set up Git
run: | run: |

View File

@ -13,19 +13,10 @@ jobs:
fetch-depth: 0 fetch-depth: 0
- name: Set up SSH - name: Set up SSH
run: | run: |
echo ">>> mkdir ~/.ssh"
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo ">>> write private key"
echo "${{ secrets.DEPLOY_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 echo "${{ secrets.DEPLOY_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
echo ">>> write public key"
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519.pub echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519.pub
echo ">>> chmod private key" chmod 600 ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/id_ed25519
echo ">>> chmod public key"
chmod 600 ~/.ssh/id_ed25519.pub
echo ">>> ssh-keyscan"
timeout 10 ssh-keyscan -p 2222 focs.gc.sjtu.edu.cn >> ~/.ssh/known_hosts || echo "ssh-keyscan failed, using StrictHostKeyChecking=accept-new"
echo ">>> ssh test"
ssh -o StrictHostKeyChecking=accept-new -T git@focs.gc.sjtu.edu.cn -p 2222 ssh -o StrictHostKeyChecking=accept-new -T git@focs.gc.sjtu.edu.cn -p 2222
- name: Set up Git - name: Set up Git
run: | run: |

View File

@ -55,13 +55,12 @@ func prepareTarStream(cmds []stage.Cmd) (bool, []byte) {
for i := range cmds { for i := range cmds {
if cmds[i].CopyInDir != "" && if cmds[i].CopyInDir != "" &&
estimateCopyInSize(&cmds[i]) >= tarStreamThreshold { estimateCopyInSize(&cmds[i]) >= tarStreamThreshold {
tarData, err := createCopyInTar(&cmds[i]) tarData, keysInTar := createCopyInTar(&cmds[i])
if err != nil {
slog.Error("create copyIn tar", "error", err)
return false, nil
}
for j := range cmds { for j := range cmds {
cmds[j].CopyInDir = "" cmds[j].CopyInDir = ""
for _, k := range keysInTar {
delete(cmds[j].CopyIn, k)
}
} }
return true, tarData return true, tarData
} }
@ -222,9 +221,10 @@ func estimateCopyInSize(cmd *stage.Cmd) int {
return total return total
} }
func createCopyInTar(cmd *stage.Cmd) ([]byte, error) { func createCopyInTar(cmd *stage.Cmd) ([]byte, []string) {
var buf bytes.Buffer var buf bytes.Buffer
tw := tar.NewWriter(&buf) tw := tar.NewWriter(&buf)
tarKeys := make([]string, 0, len(cmd.CopyIn))
if cmd.CopyInDir != "" { if cmd.CopyInDir != "" {
err := filepath.Walk(cmd.CopyInDir, err := filepath.Walk(cmd.CopyInDir,
@ -280,14 +280,69 @@ func createCopyInTar(cmd *stage.Cmd) ([]byte, error) {
return err return err
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf("walk copyInDir: %w", err) slog.Error("create copyIn tar walk", "error", err)
return nil, nil
}
}
for k, f := range cmd.CopyIn {
if f.FileID != nil || f.Symlink != nil || f.StreamIn || f.StreamOut || f.Pipe {
continue
}
if f.Content != nil {
hdr := &tar.Header{
Name: k,
Mode: 0o644,
Size: int64(len(*f.Content)),
}
if err := tw.WriteHeader(hdr); err != nil {
slog.Error("create copyIn tar write header", "key", k, "error", err)
continue
}
if _, err := tw.Write([]byte(*f.Content)); err != nil {
slog.Error("create copyIn tar write content", "key", k, "error", err)
continue
}
tarKeys = append(tarKeys, k)
} else if f.Src != nil {
fi, err := os.Stat(*f.Src)
if err != nil {
slog.Error("create copyIn tar stat", "key", k, "src", *f.Src, "error", err)
continue
}
if fi.IsDir() {
continue
}
hdr, err := tar.FileInfoHeader(fi, "")
if err != nil {
slog.Error("create copyIn tar file info header", "key", k, "error", err)
continue
}
hdr.Name = k
if err := tw.WriteHeader(hdr); err != nil {
slog.Error("create copyIn tar write header", "key", k, "error", err)
continue
}
srcFile, err := os.Open(*f.Src)
if err != nil {
slog.Error("create copyIn tar open src", "key", k, "src", *f.Src, "error", err)
continue
}
_, err = io.Copy(tw, srcFile)
srcFile.Close()
if err != nil {
slog.Error("create copyIn tar copy", "key", k, "error", err)
continue
}
tarKeys = append(tarKeys, k)
} }
} }
if err := tw.Close(); err != nil { if err := tw.Close(); err != nil {
return nil, fmt.Errorf("close tar: %w", err) slog.Error("create copyIn tar close", "error", err)
return nil, nil
} }
return buf.Bytes(), nil return buf.Bytes(), tarKeys
} }
func (e *Sandbox) Cleanup() error { func (e *Sandbox) Cleanup() error {