Skip to content

Commit 71e6866

Browse files
authored
fix(agents): convert agent entrypoints to unix path before templating (#666)
* fix(agents): convert agent entrypoints to unix path before templating * chore(lk): bump version * chore(lk): normalize paths when building tarball Signed-off-by: rektdeckard <[email protected]> --------- Signed-off-by: rektdeckard <[email protected]>
1 parent 3902374 commit 71e6866

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

pkg/agentfs/docker.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,9 @@ func GenerateDockerArtifacts(dir string, projectType ProjectType, settingsMap ma
8383
return nil, nil, err
8484
}
8585

86-
// TODO: (@rektdeckard) support Node entrypoint validation
87-
if projectType.IsPython() {
88-
dockerfileContent, err = validateEntrypoint(dir, dockerfileContent, dockerIgnoreContent, projectType)
89-
if err != nil {
90-
return nil, nil, err
91-
}
86+
dockerfileContent, err = validateEntrypoint(dir, dockerfileContent, dockerIgnoreContent, projectType)
87+
if err != nil {
88+
return nil, nil, err
9289
}
9390

9491
return dockerfileContent, dockerIgnoreContent, nil
@@ -134,11 +131,11 @@ func validateEntrypoint(dir string, dockerfileContent []byte, dockerignoreConten
134131
priority := func(p string) int {
135132
name := filepath.Base(p)
136133
switch name {
137-
case "__main__.py":
134+
case "__main__.py", "index.js":
138135
return 0
139-
case "main.py":
136+
case "main.py", "main.js":
140137
return 1
141-
case "agent.py":
138+
case "agent.py", "agent.js":
142139
return 2
143140
default:
144141
return 3
@@ -156,7 +153,7 @@ func validateEntrypoint(dir string, dockerfileContent []byte, dockerignoreConten
156153

157154
var newEntrypoint string
158155
if len(fileList) == 0 {
159-
newEntrypoint = "main.py"
156+
newEntrypoint = projectType.DefaultEntrypoint()
160157
} else if len(fileList) == 1 {
161158
newEntrypoint = fileList[0]
162159
} else {
@@ -173,7 +170,7 @@ func validateEntrypoint(dir string, dockerfileContent []byte, dockerignoreConten
173170
if err := form.Run(); err != nil {
174171
return nil, err
175172
}
176-
newEntrypoint = selected
173+
newEntrypoint = util.ToUnixPath(selected)
177174
}
178175

179176
fmt.Printf("Using entrypoint file [%s]\n", util.Accented(newEntrypoint))

pkg/agentfs/tar.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/schollz/progressbar/v3"
2929

30+
"github.com/livekit/livekit-cli/v2/pkg/util"
3031
"github.com/livekit/protocol/logger"
3132
)
3233

@@ -218,7 +219,7 @@ func UploadTarball(directory string, presignedUrl string, excludeFiles []string)
218219
if err != nil {
219220
return fmt.Errorf("failed to create tar header for file %s: %w", path, err)
220221
}
221-
header.Name = relPath
222+
header.Name = util.ToUnixPath(relPath)
222223
if err := tarWriter.WriteHeader(header); err != nil {
223224
return fmt.Errorf("failed to write tar header for file %s: %w", path, err)
224225
}

pkg/agentfs/utils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ func (p ProjectType) FileExt() string {
6565
}
6666
}
6767

68+
func (p ProjectType) DefaultEntrypoint() string {
69+
switch {
70+
case p.IsPython():
71+
return "agent.py"
72+
case p.IsNode():
73+
return "agent.js"
74+
default:
75+
return ""
76+
}
77+
}
78+
6879
func LocateLockfile(dir string, p ProjectType) (bool, string) {
6980
pythonFiles := []string{
7081
"requirements.txt",

pkg/util/fs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"os"
2121
"path"
2222
"path/filepath"
23+
"strings"
2324

2425
"github.com/livekit/protocol/utils/guid"
2526
)
@@ -120,3 +121,9 @@ func UseTempPath(permanentPath string) (string, func() error, func() error) {
120121
}
121122
return tempPath, relocate, cleanup
122123
}
124+
125+
// Converts a path (possibly Windows-style) to a Unix-style path.
126+
func ToUnixPath(p string) string {
127+
clean := filepath.Clean(p)
128+
return strings.ReplaceAll(clean, `\`, `/`)
129+
}

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
package livekitcli
1616

1717
const (
18-
Version = "2.5.1"
18+
Version = "2.5.2"
1919
)

0 commit comments

Comments
 (0)