Skip to content

Commit 04a10e5

Browse files
committed
Merge branch 'main' of https://github.com/AI-Infra-Team/telego into main
2 parents f34d195 + 93236cd commit 04a10e5

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

app/job_img_repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (m ModJobImgRepoStruct) startImgRepo() error {
162162
}
163163
generateHarborConfig()
164164

165-
_, err = util.ModRunCmd.NewBuilder("bash", "install.sh").
165+
_, err = util.ModRunCmd.NewBuilder(util.ShellExec(), "install.sh").
166166
WithRoot().
167167
ShowProgress().
168168
SetDir("/teledeploy_secret/harbor/pack/harbor").

test/test4_img_repo/img_repo_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,27 @@ func TestImgRepoSetup(t *testing.T) {
3535
}
3636

3737
// rclone config to main node
38-
cmd := testutil.NewPtyCommand(t, "rclone", "copy", "/tmp/img_repo", "remote:/teledeploy_secret")
38+
cmd := testutil.NewPtyCommand(t, "rclone", "copy", "/tmp/img_repo", "remote:/teledeploy_secret/config")
3939
cmd.Dir = projectRoot
40-
if err = testutil.RunCommand(t, cmd); err != nil {
41-
t.Fatalf("rclone to main node failed: %v", err)
40+
testutil.RunCommand(t, cmd)
41+
if testutil.GetPtyExitCode(t, cmd) != 0 {
42+
t.Fatalf("rclone to main node failed")
4243
}
4344

4445
// telego start img repo
4546
cmd = testutil.NewPtyCommand(t, "telego", "img-repo")
4647
cmd.Dir = projectRoot
47-
if err = testutil.RunCommand(t, cmd); err != nil {
48-
t.Fatalf("telego start img repo failed: %v", err)
48+
testutil.RunCommand(t, cmd)
49+
if testutil.GetPtyExitCode(t, cmd) != 0 {
50+
t.Fatalf("telego start img repo failed")
4951
}
5052

5153
// docker login
5254
cmd = testutil.NewPtyCommand(t, "docker", "login", "127.0.0.1:5000", "-u", "testadmin", "-p", "testpassword")
5355
cmd.Dir = projectRoot
54-
if err = testutil.RunCommand(t, cmd); err != nil {
55-
t.Fatalf("docker login failed: %v", err)
56+
testutil.RunCommand(t, cmd)
57+
if testutil.GetPtyExitCode(t, cmd) != 0 {
58+
t.Fatalf("docker login failed")
5659
}
5760

5861
t.Log("img repo started")

test/testutil/cmd.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package testutil
22

33
import (
4+
"os"
45
"os/exec"
56
"strconv"
67
"strings"
@@ -24,7 +25,7 @@ func NewPtyCommand(t *testing.T, name string, args ...string) *exec.Cmd {
2425

2526
fullCmd := append([]string{name}, args...)
2627
cmdStr := shellEscapeArgs(fullCmd)
27-
return exec.Command("script", "-q", "-c", cmdStr, "/dev/null")
28+
return exec.Command("script", "-q", "-c", "sh -c '"+cmdStr+"'; echo $? > /tmp/test_exit_code", "/dev/null")
2829
}
2930

3031
// shellEscapeArgs 将参数数组安全拼接成 shell 字符串
@@ -36,3 +37,11 @@ func shellEscapeArgs(args []string) string {
3637
}
3738
return strings.Join(escaped, " ")
3839
}
40+
41+
func GetPtyExitCode(t *testing.T, cmd *exec.Cmd) int {
42+
code, err := os.ReadFile("/tmp/test_exit_code")
43+
if err != nil {
44+
t.Fatalf("read exit code failed: %v", err)
45+
}
46+
return int(code[0])
47+
}

util/adminuser.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,28 @@ package util
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
67
"path/filepath"
78

89
"gopkg.in/yaml.v2"
910
)
1011

12+
func ShellExec() string {
13+
maybeNames := []string{"bash", "sh", "fish", "ksh"}
14+
for _, name := range maybeNames {
15+
if _, err := exec.LookPath(name); err == nil {
16+
return name
17+
}
18+
}
19+
return "shell-not-found"
20+
// // get which shell
21+
// shell := os.Getenv("SHELL")
22+
// if shell == "" {
23+
// shell = "/bin/bash"
24+
// }
25+
// return shell
26+
}
27+
1128
// AdminUserConfig 定义管理员用户配置的结构
1229
type AdminUserConfig struct {
1330
Username string `yaml:"username"`

0 commit comments

Comments
 (0)