Skip to content

Commit cbff42f

Browse files
authored
honor gitignore when creating tar file upload (#536)
* include gitignore when creating tar file upload * better naming * add nanpa
1 parent 1983f04 commit cbff42f

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
minor type="changed" "updated agent hosting upload management"

pkg/agentfs/tar.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,34 @@ import (
1616
"github.com/livekit/protocol/logger"
1717
)
1818

19-
var standardTarballExcludeFiles = []string{
20-
"Dockerfile",
21-
".dockerignore",
22-
".gitignore",
23-
".git",
24-
"node_modules",
25-
"*.env",
26-
}
19+
var (
20+
defaultExcludePatterns = []string{
21+
"Dockerfile",
22+
".dockerignore",
23+
".gitignore",
24+
".git",
25+
"node_modules",
26+
"*.env",
27+
}
28+
29+
ignoreFilePatterns = []string{
30+
".gitignore",
31+
".dockerignore",
32+
}
33+
)
2734

2835
func UploadTarball(directory string, presignedUrl string, excludeFiles []string) error {
29-
excludeFiles = append(standardTarballExcludeFiles, excludeFiles...)
36+
excludeFiles = append(defaultExcludePatterns, excludeFiles...)
3037

31-
dockerIgnore := filepath.Join(directory, ".dockerignore")
32-
if _, err := os.Stat(dockerIgnore); err == nil {
33-
content, err := os.ReadFile(dockerIgnore)
34-
if err != nil {
35-
return fmt.Errorf("failed to read .dockerignore: %w", err)
38+
for _, exclude := range ignoreFilePatterns {
39+
ignore := filepath.Join(directory, exclude)
40+
if _, err := os.Stat(ignore); err == nil {
41+
content, err := os.ReadFile(ignore)
42+
if err != nil {
43+
return fmt.Errorf("failed to read %s: %w", ignore, err)
44+
}
45+
excludeFiles = append(excludeFiles, strings.Split(string(content), "\n")...)
3646
}
37-
excludeFiles = append(excludeFiles, strings.Split(string(content), "\n")...)
3847
}
3948

4049
for i, exclude := range excludeFiles {

0 commit comments

Comments
 (0)